blob: f7a98656b200237b4d58496106b4489030bfe953 [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;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000020import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080021import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Hall Liud892bec2018-11-30 14:51:45 -080022
Shuo Qianccbaf742021-02-22 18:32:21 -080023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
24import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070025import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000027import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070028
Brad Ebinger34c09a52021-02-17 23:23:21 +000029import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080030import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080031import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070032import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000033import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080034import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080036import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070037import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000038import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080039import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000040import android.compat.annotation.ChangeId;
41import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070042import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070043import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.content.Context;
45import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070046import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070047import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070048import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.net.Uri;
50import android.os.AsyncResult;
51import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080052import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.Bundle;
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080054import android.os.DropBoxManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070056import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080057import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080058import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import android.os.Looper;
60import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070061import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080062import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070063import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070064import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080065import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080066import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070067import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070068import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080069import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070071import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070072import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070073import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070074import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080075import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070076import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000077import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090078import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080079import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080080import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070081import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080082import android.telephony.AccessNetworkConstants;
83import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070084import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070085import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080086import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070087import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080088import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070089import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080090import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -060091import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -070092import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080093import android.telephony.CellIdentityCdma;
94import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070096import android.telephony.CellInfoGsm;
97import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070098import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080099import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700100import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700101import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700102import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800103import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700104import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800105import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700106import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800107import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800108import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700109import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800110import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800112import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800113import android.telephony.SignalStrengthUpdateRequest;
114import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800115import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800117import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700118import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700119import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800120import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800121import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800122import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800123import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000124import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000125import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000126import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700127import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700128import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800129import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800130import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700131import android.telephony.gba.GbaAuthRequest;
132import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700133import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800134import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000135import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000136import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700137import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000138import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700139import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800140import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700141import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800142import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700143import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000144import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700145import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800146import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800147import android.telephony.ims.stub.ImsRegistrationImplBase;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800148import android.telephony.satellite.ISatelliteDatagramCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800149import android.telephony.satellite.ISatelliteProvisionStateCallback;
150import android.telephony.satellite.ISatelliteStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800151import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800152import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000153import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800154import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800155import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800156import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800158import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700159import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700160import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800161import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800162
Andrew Lee312e8172014-10-23 17:01:36 -0700163import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800164import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800165import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800166import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800167import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700168import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700169import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700170import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800171import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800172import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700173import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700174import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800175import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700176import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800177import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800178import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800179import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700180import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000181import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700182import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800183import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700184import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800185import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800186import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800187import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700188import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700189import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700190import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700192import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800193import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700194import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700195import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700196import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700197import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800198import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800199import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700200import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000201import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700202import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700203import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800204import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800205import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800206import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700207import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000208import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800209import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700210import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800211import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700212import com.android.internal.telephony.imsphone.ImsPhone;
213import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000214import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800215import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000216import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800217import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
218import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700219import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700220import com.android.internal.telephony.uicc.IccIoResult;
221import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800222import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700223import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800224import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700225import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000226import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800227import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000228import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800229import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000230import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700231import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700232import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800233import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800234import com.android.phone.callcomposer.CallComposerPictureManager;
235import com.android.phone.callcomposer.CallComposerPictureTransfer;
236import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700237import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700238import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000239import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700240import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800241import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700242import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700243import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800244import com.android.services.telephony.TelecomAccountRegistry;
245import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800246import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800247
Hall Liu82694d52020-12-11 18:22:04 -0800248import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700249import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800250import java.io.IOException;
251import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700252import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700253import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800254import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000255import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800256import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800257import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800258import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800259import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100260import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800261import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700262import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800263import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800264import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700265import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800266import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800267import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800268import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269
270/**
271 * Implementation of the ITelephony interface.
272 */
Santos Cordon117fee72014-05-16 17:56:12 -0700273public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700274 private static final String LOG_TAG = "PhoneInterfaceManager";
275 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
276 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800277 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700278
279 // Message codes used with mMainThreadHandler
280 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700281 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
282 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700283 private static final int CMD_OPEN_CHANNEL = 9;
284 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
285 private static final int CMD_CLOSE_CHANNEL = 11;
286 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800287 private static final int CMD_NV_READ_ITEM = 13;
288 private static final int EVENT_NV_READ_ITEM_DONE = 14;
289 private static final int CMD_NV_WRITE_ITEM = 15;
290 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
291 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
292 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700293 private static final int CMD_RESET_MODEM_CONFIG = 19;
294 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800295 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
296 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800297 private static final int CMD_SEND_ENVELOPE = 25;
298 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000299 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
300 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700301 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
302 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
303 private static final int CMD_EXCHANGE_SIM_IO = 31;
304 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800305 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
306 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700307 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
308 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700309 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
310 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700311 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
312 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
313 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
314 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700315 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
316 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
317 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
318 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700319 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800320 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
321 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000322 private static final int CMD_SWITCH_SLOTS = 50;
323 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700324 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
325 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
326 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
327 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
328 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
329 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
330 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
331 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700332 private static final int CMD_GET_ALL_CELL_INFO = 60;
333 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
334 private static final int CMD_GET_CELL_LOCATION = 62;
335 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700336 private static final int CMD_MODEM_REBOOT = 64;
337 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700338 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
339 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800340 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
341 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700342 private static final int CMD_GET_MODEM_STATUS = 70;
343 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700344 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
345 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700346 private static final int CMD_ERASE_MODEM_CONFIG = 74;
347 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800348 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
349 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
350 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
351 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800352 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
353 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800354 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800355 private static final int CMD_GET_CALL_FORWARDING = 83;
356 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
357 private static final int CMD_SET_CALL_FORWARDING = 85;
358 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
359 private static final int CMD_GET_CALL_WAITING = 87;
360 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
361 private static final int CMD_SET_CALL_WAITING = 89;
362 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700363 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
364 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
365 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
366 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700367 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
368 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800369 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
370 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800371 private static final int CMD_SET_DATA_THROTTLING = 99;
372 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800373 private static final int CMD_SET_SIM_POWER = 101;
374 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800375 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
376 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
377 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
378 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800379 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
380 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000381 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800382 private static final int CMD_GET_SLICING_CONFIG = 110;
383 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800384 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700385 private static final int CMD_ENABLE_VONR = 113;
386 private static final int EVENT_ENABLE_VONR_DONE = 114;
387 private static final int CMD_IS_VONR_ENABLED = 115;
388 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700389 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
390 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000391
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800392 // Parameters of select command.
393 private static final int SELECT_COMMAND = 0xA4;
394 private static final int SELECT_P1 = 0x04;
395 private static final int SELECT_P2 = 0;
396 private static final int SELECT_P3 = 0x10;
397
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000398 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
399 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
400
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401 /** The singleton instance. */
402 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800403 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700404
Sarah Chin4beb2b72023-02-14 14:47:54 -0800405 private final PhoneGlobals mApp;
406 private final CallManager mCM;
407 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000408
409 private final SatelliteController mSatelliteController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800410 private final UserManager mUserManager;
411 private final AppOpsManager mAppOps;
412 private final MainThreadHandler mMainThreadHandler;
Jack Yue37dd262022-12-16 11:53:37 -0800413 private final SubscriptionController mSubscriptionController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800414 private final SharedPreferences mTelephonySharedPreferences;
415 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800416 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417
Peter Wangdafb9ac2020-01-15 14:13:38 -0800418 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800419 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800420 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
421
Sarah Chin4beb2b72023-02-14 14:47:54 -0800422 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800423
Derek Tan97ebb422014-09-05 16:55:38 -0700424 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
425 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800426 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800427 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700428
Michelecea4cf22018-12-21 15:00:11 -0800429 // String to store multi SIM allowed
430 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
431
Derek Tan740e1672017-06-27 14:56:27 -0700432 // The AID of ISD-R.
433 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
434
yinxub1bed742017-04-17 11:45:04 -0700435 private NetworkScanRequestTracker mNetworkScanRequestTracker;
436
David Kelly5e06a7f2018-03-12 14:10:59 +0000437 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
438 private static final int MANUFACTURER_CODE_LENGTH = 8;
439
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800440 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800441 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800442
Sarah Chin2ec39f62022-08-31 17:03:26 -0700443 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
444 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
445
Derek Tan89e89d42014-07-08 17:00:10 -0700446 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700447 * Experiment flag to enable erase modem config on reset network, default value is false
448 */
449 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
450 "reset_network_erase_modem_config_enabled";
451
Rambo Wang0f050d82021-02-12 11:43:36 -0800452 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800453
Gary Jian76280a42022-12-07 16:18:33 +0800454 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
455
sandeepjsb6c87872021-09-27 15:34:44 +0000456 /**
457 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
458 * one ICCID active at the same time.
459 * Apps should use below API signatures if targeting SDK is T and beyond.
460 *
461 * @hide
462 */
463 @ChangeId
464 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
465 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800466
Naina Nallurid63128d2019-09-17 14:10:30 -0700467 /**
Chen Xu540470b2021-12-14 17:15:47 -0800468 * Apps targeting on Android T and beyond will get exception whenever icc close channel
469 * operation fails.
470 */
471 @ChangeId
472 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
473 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
474
475 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700476 * A request object to use for transmitting data to an ICC.
477 */
478 private static final class IccAPDUArgument {
479 public int channel, cla, command, p1, p2, p3;
480 public String data;
481
482 public IccAPDUArgument(int channel, int cla, int command,
483 int p1, int p2, int p3, String data) {
484 this.channel = channel;
485 this.cla = cla;
486 this.command = command;
487 this.p1 = p1;
488 this.p2 = p2;
489 this.p3 = p3;
490 this.data = data;
491 }
492 }
493
494 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700495 * A request object to use for transmitting data to an ICC.
496 */
497 private static final class ManualNetworkSelectionArgument {
498 public OperatorInfo operatorInfo;
499 public boolean persistSelection;
500
501 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
502 this.operatorInfo = operatorInfo;
503 this.persistSelection = persistSelection;
504 }
505 }
506
Sarah Chin71b3a852022-09-28 15:54:19 -0700507 private static final class PurchasePremiumCapabilityArgument {
508 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700509 public @NonNull IIntegerConsumer callback;
510
511 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800512 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700513 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700514 this.callback = callback;
515 }
516 }
517
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700518 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700519 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
520 * request after sending. The main thread will notify the request when it is complete.
521 */
522 private static final class MainThreadRequest {
523 /** The argument to use for the request */
524 public Object argument;
525 /** The result of the request that is run on the main thread */
526 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800527 // The subscriber id that this request applies to. Defaults to
528 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
529 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700530
Nathan Harold92bed182018-10-12 18:16:49 -0700531 // In cases where subId is unavailable, the caller needs to specify the phone.
532 public Phone phone;
533
vagdeviaf9a5b92018-08-15 16:01:53 -0700534 public WorkSource workSource;
535
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700536 public MainThreadRequest(Object argument) {
537 this.argument = argument;
538 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800539
Nathan Harold92bed182018-10-12 18:16:49 -0700540 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
541 this.argument = argument;
542 if (phone != null) {
543 this.phone = phone;
544 }
545 this.workSource = workSource;
546 }
547
vagdeviaf9a5b92018-08-15 16:01:53 -0700548 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800549 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800550 if (subId != null) {
551 this.subId = subId;
552 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700553 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800554 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700555 }
556
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800557 private static final class IncomingThirdPartyCallArgs {
558 public final ComponentName component;
559 public final String callId;
560 public final String callerDisplayName;
561
562 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
563 String callerDisplayName) {
564 this.component = component;
565 this.callId = callId;
566 this.callerDisplayName = callerDisplayName;
567 }
568 }
569
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700570 /**
571 * A handler that processes messages on the main thread in the phone process. Since many
572 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
573 * inbound binder threads to the main thread in the phone process. The Binder thread
574 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
575 * on, which will be notified when the operation completes and will contain the result of the
576 * request.
577 *
578 * <p>If a MainThreadRequest object is provided in the msg.obj field,
579 * note that request.result must be set to something non-null for the calling thread to
580 * unblock.
581 */
582 private final class MainThreadHandler extends Handler {
583 @Override
584 public void handleMessage(Message msg) {
585 MainThreadRequest request;
586 Message onCompleted;
587 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000588 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700589 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800590 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700591
592 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700593 case CMD_HANDLE_USSD_REQUEST: {
594 request = (MainThreadRequest) msg.obj;
595 final Phone phone = getPhoneFromRequest(request);
596 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800597 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700598 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700599
Pengquan Menga1bb6272018-09-06 09:59:22 -0700600 if (!isUssdApiAllowed(request.subId)) {
601 // Carrier does not support use of this API, return failure.
602 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
603 UssdResponse response = new UssdResponse(ussdRequest, null);
604 Bundle returnData = new Bundle();
605 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
606 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700607
Pengquan Menga1bb6272018-09-06 09:59:22 -0700608 request.result = true;
609 notifyRequester(request);
610 return;
611 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700612
Pengquan Menga1bb6272018-09-06 09:59:22 -0700613 try {
614 request.result = phone != null
615 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
616 } catch (CallStateException cse) {
617 request.result = false;
618 }
619 // Wake up the requesting thread
620 notifyRequester(request);
621 break;
pkanwar32d516d2016-10-14 19:37:38 -0700622 }
623
Yorke Lee716f67e2015-06-17 15:39:16 -0700624 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700625 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700626 final Phone phone = getPhoneFromRequest(request);
627 request.result = phone != null ?
628 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
629 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700630 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700631 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700632 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700633 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700634
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700635 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700637 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000638 uiccPort = getUiccPortFromRequest(request);
639 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700640 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800641 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700642 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700643 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700644 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800645 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000646 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800647 iccArgument.channel, iccArgument.cla, iccArgument.command,
648 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
649 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700650 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 break;
652
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700653 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 ar = (AsyncResult) msg.obj;
655 request = (MainThreadRequest) ar.userObj;
656 if (ar.exception == null && ar.result != null) {
657 request.result = ar.result;
658 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800659 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 if (ar.result == null) {
661 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800662 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800664 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700665 } else {
666 loge("iccTransmitApduLogicalChannel: Unknown exception");
667 }
668 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700669 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700670 break;
671
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700672 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
673 request = (MainThreadRequest) msg.obj;
674 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000675 uiccPort = getUiccPortFromRequest(request);
676 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700677 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800678 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700679 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700680 } else {
681 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800682 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000683 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800684 iccArgument.cla, iccArgument.command, iccArgument.p1,
685 iccArgument.p2,
686 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700687 }
688 break;
689
690 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
691 ar = (AsyncResult) msg.obj;
692 request = (MainThreadRequest) ar.userObj;
693 if (ar.exception == null && ar.result != null) {
694 request.result = ar.result;
695 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800696 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700697 if (ar.result == null) {
698 loge("iccTransmitApduBasicChannel: Empty response");
699 } else if (ar.exception instanceof CommandException) {
700 loge("iccTransmitApduBasicChannel: CommandException: " +
701 ar.exception);
702 } else {
703 loge("iccTransmitApduBasicChannel: Unknown exception");
704 }
705 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700706 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700707 break;
708
709 case CMD_EXCHANGE_SIM_IO:
710 request = (MainThreadRequest) msg.obj;
711 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000712 uiccPort = getUiccPortFromRequest(request);
713 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700714 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800715 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700716 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700717 } else {
718 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
719 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000720 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700721 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
722 iccArgument.data, onCompleted);
723 }
724 break;
725
726 case EVENT_EXCHANGE_SIM_IO_DONE:
727 ar = (AsyncResult) msg.obj;
728 request = (MainThreadRequest) ar.userObj;
729 if (ar.exception == null && ar.result != null) {
730 request.result = ar.result;
731 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800732 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700733 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700734 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700735 break;
736
Derek Tan4d5e5c12014-02-04 11:54:58 -0800737 case CMD_SEND_ENVELOPE:
738 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000739 uiccPort = getUiccPortFromRequest(request);
740 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700741 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800742 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700743 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700744 } else {
745 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800746 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700747 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800748 break;
749
750 case EVENT_SEND_ENVELOPE_DONE:
751 ar = (AsyncResult) msg.obj;
752 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700753 if (ar.exception == null && ar.result != null) {
754 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800755 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800756 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700757 if (ar.result == null) {
758 loge("sendEnvelopeWithStatus: Empty response");
759 } else if (ar.exception instanceof CommandException) {
760 loge("sendEnvelopeWithStatus: CommandException: " +
761 ar.exception);
762 } else {
763 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
764 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800765 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700766 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800767 break;
768
Shishir Agrawal566b7612013-10-28 14:41:00 -0700769 case CMD_OPEN_CHANNEL:
770 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000771 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800772 IccLogicalChannelRequest openChannelRequest =
773 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000774 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700775 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800776 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800777 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700778 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700779 } else {
780 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800781 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
782 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700783 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700784 break;
785
786 case EVENT_OPEN_CHANNEL_DONE:
787 ar = (AsyncResult) msg.obj;
788 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700789 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700790 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700791 int[] result = (int[]) ar.result;
792 int channelId = result[0];
793 byte[] selectResponse = null;
794 if (result.length > 1) {
795 selectResponse = new byte[result.length - 1];
796 for (int i = 1; i < result.length; ++i) {
797 selectResponse[i - 1] = (byte) result[i];
798 }
799 }
800 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800801 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800802
803 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700804 if (uiccPort == null) {
805 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
806 } else {
807 IccLogicalChannelRequest channelRequest =
808 (IccLogicalChannelRequest) request.argument;
809 channelRequest.channel = channelId;
810 uiccPort.onLogicalChannelOpened(channelRequest);
811 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700812 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700813 if (ar.result == null) {
814 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700815 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700816 if (ar.exception != null) {
817 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
818 }
819
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700820 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700821 if (ar.exception instanceof CommandException) {
822 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800823 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700824 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700825 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700826 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700827 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700828 }
829 }
830 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800831 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700832 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700833 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700834 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700835 break;
836
837 case CMD_CLOSE_CHANNEL:
838 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000839 uiccPort = getUiccPortFromRequest(request);
840 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700841 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800842 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800843 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800844 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700845 } else {
846 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000847 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700848 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700849 break;
850
851 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800852 ar = (AsyncResult) msg.obj;
853 request = (MainThreadRequest) ar.userObj;
854 if (ar.exception == null) {
855 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800856 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700857 if (uiccPort == null) {
858 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
859 } else {
860 final int channelId = (Integer) request.argument;
861 uiccPort.onLogicalChannelClosed(channelId);
862 }
Chen Xu540470b2021-12-14 17:15:47 -0800863 } else {
864 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800865 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800866 if (ar.exception instanceof CommandException) {
867 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
868 CommandException.Error error =
869 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800870 if (error == CommandException.Error.INVALID_ARGUMENTS) {
871 // should only throw exceptions from the binder threads.
872 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800873 "iccCloseLogicalChannel: invalid argument ");
874 }
875 } else {
876 loge("iccCloseLogicalChannel: Unknown exception");
877 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800878 request.result = (exception != null) ? exception :
879 new IllegalStateException(
880 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800881 }
882 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800883 break;
884
885 case CMD_NV_READ_ITEM:
886 request = (MainThreadRequest) msg.obj;
887 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800888 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
889 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800890 break;
891
892 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700893 ar = (AsyncResult) msg.obj;
894 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800895 if (ar.exception == null && ar.result != null) {
896 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700897 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800898 request.result = "";
899 if (ar.result == null) {
900 loge("nvReadItem: Empty response");
901 } else if (ar.exception instanceof CommandException) {
902 loge("nvReadItem: CommandException: " +
903 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700904 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800905 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700906 }
907 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700908 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700909 break;
910
Jake Hambye994d462014-02-03 13:10:13 -0800911 case CMD_NV_WRITE_ITEM:
912 request = (MainThreadRequest) msg.obj;
913 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
914 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800915 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700916 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800917 break;
918
919 case EVENT_NV_WRITE_ITEM_DONE:
920 handleNullReturnEvent(msg, "nvWriteItem");
921 break;
922
923 case CMD_NV_WRITE_CDMA_PRL:
924 request = (MainThreadRequest) msg.obj;
925 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800926 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800927 break;
928
929 case EVENT_NV_WRITE_CDMA_PRL_DONE:
930 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
931 break;
932
chen xu6dac5ab2018-10-26 17:39:23 -0700933 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800934 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700935 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800936 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800937 break;
938
chen xu6dac5ab2018-10-26 17:39:23 -0700939 case EVENT_RESET_MODEM_CONFIG_DONE:
940 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800941 break;
942
Sooraj Sasindran37444802020-08-11 10:40:43 -0700943 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
944 request = (MainThreadRequest) msg.obj;
945 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
946 request);
947 Phone phone = getPhoneFromRequest(request);
948 if (phone != null) {
949 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
950 } else {
951 loge("isNRDualConnectivityEnabled: No phone object");
952 request.result = false;
953 notifyRequester(request);
954 }
955 break;
956 }
957
958 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
959 ar = (AsyncResult) msg.obj;
960 request = (MainThreadRequest) ar.userObj;
961 if (ar.exception == null && ar.result != null) {
962 request.result = ar.result;
963 } else {
964 // request.result must be set to something non-null
965 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700966 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700967 request.result = ar.result;
968 } else {
969 request.result = false;
970 }
971 if (ar.result == null) {
972 loge("isNRDualConnectivityEnabled: Empty response");
973 } else if (ar.exception instanceof CommandException) {
974 loge("isNRDualConnectivityEnabled: CommandException: "
975 + ar.exception);
976 } else {
977 loge("isNRDualConnectivityEnabled: Unknown exception");
978 }
979 }
980 notifyRequester(request);
981 break;
982
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700983 case CMD_IS_VONR_ENABLED: {
984 request = (MainThreadRequest) msg.obj;
985 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
986 request);
987 Phone phone = getPhoneFromRequest(request);
988 if (phone != null) {
989 phone.isVoNrEnabled(onCompleted, request.workSource);
990 } else {
991 loge("isVoNrEnabled: No phone object");
992 request.result = false;
993 notifyRequester(request);
994 }
995 break;
996 }
997
998 case EVENT_IS_VONR_ENABLED_DONE:
999 ar = (AsyncResult) msg.obj;
1000 request = (MainThreadRequest) ar.userObj;
1001 if (ar.exception == null && ar.result != null) {
1002 request.result = ar.result;
1003 } else {
1004 // request.result must be set to something non-null
1005 // for the calling thread to unblock
1006 if (ar.result != null) {
1007 request.result = ar.result;
1008 } else {
1009 request.result = false;
1010 }
1011 if (ar.result == null) {
1012 loge("isVoNrEnabled: Empty response");
1013 } else if (ar.exception instanceof CommandException) {
1014 loge("isVoNrEnabled: CommandException: "
1015 + ar.exception);
1016 } else {
1017 loge("isVoNrEnabled: Unknown exception");
1018 }
1019 }
1020 notifyRequester(request);
1021 break;
1022
Sooraj Sasindran37444802020-08-11 10:40:43 -07001023 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1024 request = (MainThreadRequest) msg.obj;
1025 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1026 Phone phone = getPhoneFromRequest(request);
1027 if (phone != null) {
1028 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1029 request.workSource);
1030 } else {
1031 loge("enableNrDualConnectivity: No phone object");
1032 request.result =
1033 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1034 notifyRequester(request);
1035 }
1036 break;
1037 }
1038
1039 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1040 ar = (AsyncResult) msg.obj;
1041 request = (MainThreadRequest) ar.userObj;
1042 if (ar.exception == null) {
1043 request.result =
1044 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1045 } else {
1046 request.result =
1047 TelephonyManager
1048 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1049 if (ar.exception instanceof CommandException) {
1050 CommandException.Error error =
1051 ((CommandException) (ar.exception)).getCommandError();
1052 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1053 request.result =
1054 TelephonyManager
1055 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001056 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1057 request.result =
1058 TelephonyManager
1059 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001060 }
1061 loge("enableNrDualConnectivity" + ": CommandException: "
1062 + ar.exception);
1063 } else {
1064 loge("enableNrDualConnectivity" + ": Unknown exception");
1065 }
1066 }
1067 notifyRequester(request);
1068 break;
1069 }
1070
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001071 case CMD_ENABLE_VONR: {
1072 request = (MainThreadRequest) msg.obj;
1073 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1074 Phone phone = getPhoneFromRequest(request);
1075 if (phone != null) {
1076 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1077 request.workSource);
1078 } else {
1079 loge("setVoNrEnabled: No phone object");
1080 request.result =
1081 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1082 notifyRequester(request);
1083 }
1084 break;
1085 }
1086
1087 case EVENT_ENABLE_VONR_DONE: {
1088 ar = (AsyncResult) msg.obj;
1089 request = (MainThreadRequest) ar.userObj;
1090 if (ar.exception == null) {
1091 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1092 } else {
1093 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1094 if (ar.exception instanceof CommandException) {
1095 CommandException.Error error =
1096 ((CommandException) (ar.exception)).getCommandError();
1097 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1098 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1099 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1100 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1101 } else {
1102 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1103 }
1104 loge("setVoNrEnabled" + ": CommandException: "
1105 + ar.exception);
1106 } else {
1107 loge("setVoNrEnabled" + ": Unknown exception");
1108 }
1109 }
1110 notifyRequester(request);
1111 break;
1112 }
1113
SongFerngWang3ef3e072020-12-21 16:41:52 +08001114 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001115 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001116 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1117 request);
1118 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001119 break;
1120
SongFerngWang3ef3e072020-12-21 16:41:52 +08001121 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001122 ar = (AsyncResult) msg.obj;
1123 request = (MainThreadRequest) ar.userObj;
1124 if (ar.exception == null && ar.result != null) {
1125 request.result = ar.result; // Integer
1126 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301127 // request.result must be set to something non-null
1128 // for the calling thread to unblock
1129 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001130 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001131 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001132 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001133 loge("getAllowedNetworkTypesBitmask: CommandException: "
1134 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001135 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001136 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001137 }
1138 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001139 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001140 break;
1141
SongFerngWang3ef3e072020-12-21 16:41:52 +08001142 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001143 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001144 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1145 request);
1146 Pair<Integer, Long> reasonWithNetworkTypes =
1147 (Pair<Integer, Long>) request.argument;
1148 getPhoneFromRequest(request).setAllowedNetworkTypes(
1149 reasonWithNetworkTypes.first,
1150 reasonWithNetworkTypes.second,
1151 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001152 break;
1153
SongFerngWang3ef3e072020-12-21 16:41:52 +08001154 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1155 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001156 break;
1157
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001158 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1159 request = (MainThreadRequest)msg.obj;
1160 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001161 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001162 break;
1163
1164 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1165 ar = (AsyncResult)msg.obj;
1166 request = (MainThreadRequest)ar.userObj;
1167 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001168 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001169 break;
1170
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001171 case CMD_SET_VOICEMAIL_NUMBER:
1172 request = (MainThreadRequest) msg.obj;
1173 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1174 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001175 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1176 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001177 break;
1178
1179 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1180 handleNullReturnEvent(msg, "setVoicemailNumber");
1181 break;
1182
Stuart Scott54788802015-03-30 13:18:01 -07001183 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1184 request = (MainThreadRequest) msg.obj;
1185 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1186 request);
1187 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1188 break;
1189
1190 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1191 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1192 break;
1193
Shishir Agrawal302c8692015-06-19 13:49:39 -07001194 case CMD_PERFORM_NETWORK_SCAN:
1195 request = (MainThreadRequest) msg.obj;
1196 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1197 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1198 break;
1199
Hall Liu27d24262020-09-18 19:04:59 -07001200 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001201 request = (MainThreadRequest) msg.obj;
1202 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001203 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1204 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1205 request.argument;
1206 int callForwardingReason = args.first;
1207 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001208 break;
Hall Liu27d24262020-09-18 19:04:59 -07001209 }
1210 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001211 ar = (AsyncResult) msg.obj;
1212 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001213 TelephonyManager.CallForwardingInfoCallback callback =
1214 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1215 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001216 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001217 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001218 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1219 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1220 // Service Class is a bit mask per 3gpp 27.007. Search for
1221 // any service for voice call.
1222 if ((callForwardInfo.serviceClass
1223 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001224 callForwardingInfo = new CallForwardingInfo(
1225 callForwardInfo.status
1226 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001227 callForwardInfo.reason,
1228 callForwardInfo.number,
1229 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001230 break;
1231 }
1232 }
1233 // Didn't find a call forward info for voice call.
1234 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001235 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1236 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001237 }
Hall Liu27d24262020-09-18 19:04:59 -07001238 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001239 } else {
1240 if (ar.result == null) {
1241 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1242 }
1243 if (ar.exception != null) {
1244 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1245 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001246 int errorCode = TelephonyManager
1247 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001248 if (ar.exception instanceof CommandException) {
1249 CommandException.Error error =
1250 ((CommandException) (ar.exception)).getCommandError();
1251 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001252 errorCode = TelephonyManager
1253 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001254 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001255 errorCode = TelephonyManager
1256 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001257 }
1258 }
Hall Liu27d24262020-09-18 19:04:59 -07001259 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001260 }
Shuo Qian4a594052020-01-23 11:59:30 -08001261 break;
Hall Liu27d24262020-09-18 19:04:59 -07001262 }
Shuo Qian4a594052020-01-23 11:59:30 -08001263
Hall Liu27d24262020-09-18 19:04:59 -07001264 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001265 request = (MainThreadRequest) msg.obj;
1266 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001267 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001268 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001269 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1270 request.argument).first;
1271 request.phone.setCallForwardingOption(
1272 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001273 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001274 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001275 callForwardingInfoToSet.getReason(),
1276 callForwardingInfoToSet.getNumber(),
1277 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1278 break;
Hall Liu27d24262020-09-18 19:04:59 -07001279 }
Shuo Qian4a594052020-01-23 11:59:30 -08001280
Hall Liu27d24262020-09-18 19:04:59 -07001281 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001282 ar = (AsyncResult) msg.obj;
1283 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001284 Consumer<Integer> callback =
1285 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1286 request.argument).second;
1287 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001288 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001289 int errorCode = TelephonyManager.CallForwardingInfoCallback
1290 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001291 if (ar.exception instanceof CommandException) {
1292 CommandException.Error error =
1293 ((CommandException) (ar.exception)).getCommandError();
1294 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001295 errorCode = TelephonyManager.CallForwardingInfoCallback
1296 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001297 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001298 errorCode = TelephonyManager.CallForwardingInfoCallback
1299 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001300 }
1301 }
1302 callback.accept(errorCode);
1303 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001304 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001305 }
Shuo Qian4a594052020-01-23 11:59:30 -08001306 break;
Hall Liu27d24262020-09-18 19:04:59 -07001307 }
Shuo Qian4a594052020-01-23 11:59:30 -08001308
Hall Liu27d24262020-09-18 19:04:59 -07001309 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001310 request = (MainThreadRequest) msg.obj;
1311 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1312 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1313 break;
Hall Liu27d24262020-09-18 19:04:59 -07001314 }
Shuo Qian4a594052020-01-23 11:59:30 -08001315
Hall Liu27d24262020-09-18 19:04:59 -07001316 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001317 ar = (AsyncResult) msg.obj;
1318 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001319 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001320 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001321 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001322 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001323 // Service Class is a bit mask per 3gpp 27.007.
1324 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001325 if (callForwardResults.length > 1
1326 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001327 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001328 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001329 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1330 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001331 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001332 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001333 }
1334 } else {
1335 if (ar.result == null) {
1336 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1337 }
1338 if (ar.exception != null) {
1339 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1340 }
1341 if (ar.exception instanceof CommandException) {
1342 CommandException.Error error =
1343 ((CommandException) (ar.exception)).getCommandError();
1344 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001345 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001346 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001347 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1348 callWaitingStatus =
1349 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001350 }
1351 }
1352 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001353 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001354 break;
Hall Liu27d24262020-09-18 19:04:59 -07001355 }
Shuo Qian4a594052020-01-23 11:59:30 -08001356
Hall Liu27d24262020-09-18 19:04:59 -07001357 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001358 request = (MainThreadRequest) msg.obj;
1359 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001360 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1361 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001362 break;
Hall Liu27d24262020-09-18 19:04:59 -07001363 }
Shuo Qian4a594052020-01-23 11:59:30 -08001364
Hall Liu27d24262020-09-18 19:04:59 -07001365 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001366 ar = (AsyncResult) msg.obj;
1367 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001368 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1369 Consumer<Integer> callback =
1370 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1371 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001372 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001373 if (ar.exception instanceof CommandException) {
1374 CommandException.Error error =
1375 ((CommandException) (ar.exception)).getCommandError();
1376 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1377 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001378 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1379 callback.accept(
1380 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001381 } else {
1382 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1383 }
1384 } else {
1385 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1386 }
1387 } else {
1388 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1389 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001390 }
Shuo Qian4a594052020-01-23 11:59:30 -08001391 break;
Hall Liu27d24262020-09-18 19:04:59 -07001392 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001393 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1394 ar = (AsyncResult) msg.obj;
1395 request = (MainThreadRequest) ar.userObj;
1396 CellNetworkScanResult cellScanResult;
1397 if (ar.exception == null && ar.result != null) {
1398 cellScanResult = new CellNetworkScanResult(
1399 CellNetworkScanResult.STATUS_SUCCESS,
1400 (List<OperatorInfo>) ar.result);
1401 } else {
1402 if (ar.result == null) {
1403 loge("getCellNetworkScanResults: Empty response");
1404 }
1405 if (ar.exception != null) {
1406 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1407 }
1408 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1409 if (ar.exception instanceof CommandException) {
1410 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001411 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001412 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1413 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1414 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1415 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1416 }
1417 }
1418 cellScanResult = new CellNetworkScanResult(errorCode, null);
1419 }
1420 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001421 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001422 break;
1423
1424 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1425 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001426 ManualNetworkSelectionArgument selArg =
1427 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001428 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1429 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001430 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1431 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001432 break;
1433
1434 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001435 ar = (AsyncResult) msg.obj;
1436 request = (MainThreadRequest) ar.userObj;
1437 if (ar.exception == null) {
1438 request.result = true;
1439 } else {
1440 request.result = false;
1441 loge("setNetworkSelectionModeManual " + ar.exception);
1442 }
1443 notifyRequester(request);
1444 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001445 break;
1446
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001447 case CMD_GET_MODEM_ACTIVITY_INFO:
1448 request = (MainThreadRequest) msg.obj;
1449 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001450 if (defaultPhone != null) {
1451 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001452 } else {
1453 ResultReceiver result = (ResultReceiver) request.argument;
1454 Bundle bundle = new Bundle();
1455 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001456 new ModemActivityInfo(0, 0, 0,
1457 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001458 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001459 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001460 break;
1461
Hall Liud0f208c2020-10-14 16:54:44 -07001462 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001463 ar = (AsyncResult) msg.obj;
1464 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001465 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001466 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001467 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001468 if (mLastModemActivityInfo == null) {
1469 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1470 mLastModemActivitySpecificInfo[0] =
1471 new ActivityStatsTechSpecificInfo(
1472 0,
1473 0,
1474 new int[ModemActivityInfo.getNumTxPowerLevels()],
1475 0);
1476 mLastModemActivityInfo =
1477 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1478 }
1479
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001480 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001481 // Update the last modem activity info and the result of the request.
1482 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1483 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001484 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001485 } else {
1486 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001487 }
Kai Shi917fdc62022-11-28 14:01:02 -08001488 // This is needed to decouple ret from mLastModemActivityInfo
1489 // We don't want to return mLastModemActivityInfo which is updated
1490 // inside mergeModemActivityInfo()
1491 ret = new ModemActivityInfo(
1492 mLastModemActivityInfo.getTimestampMillis(),
1493 mLastModemActivityInfo.getSleepTimeMillis(),
1494 mLastModemActivityInfo.getIdleTimeMillis(),
1495 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001496
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001497 } else {
1498 if (ar.result == null) {
1499 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001500 error = TelephonyManager.ModemActivityInfoException
1501 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001502 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001503 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001504 error = TelephonyManager.ModemActivityInfoException
1505 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001506 } else {
1507 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001508 error = TelephonyManager.ModemActivityInfoException
1509 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001510 }
1511 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001512 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001513 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001514 bundle.putParcelable(
1515 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001516 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001517 } else {
1518 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1519 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001520 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001521 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001522 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001523 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001524
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001525 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001526 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001527 CarrierRestrictionRules argument =
1528 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001529 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001530 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001531 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001532 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001533
1534 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1535 ar = (AsyncResult) msg.obj;
1536 request = (MainThreadRequest) ar.userObj;
1537 if (ar.exception == null && ar.result != null) {
1538 request.result = ar.result;
1539 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001540 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1541 if (ar.exception instanceof CommandException) {
1542 loge("setAllowedCarriers: CommandException: " + ar.exception);
1543 CommandException.Error error =
1544 ((CommandException) (ar.exception)).getCommandError();
1545 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1546 request.result =
1547 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1548 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001549 } else {
1550 loge("setAllowedCarriers: Unknown exception");
1551 }
1552 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001553 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001554 break;
1555
1556 case CMD_GET_ALLOWED_CARRIERS:
1557 request = (MainThreadRequest) msg.obj;
1558 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001559 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001560 break;
1561
1562 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1563 ar = (AsyncResult) msg.obj;
1564 request = (MainThreadRequest) ar.userObj;
1565 if (ar.exception == null && ar.result != null) {
1566 request.result = ar.result;
1567 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001568 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001569 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001570 if (ar.result == null) {
1571 loge("getAllowedCarriers: Empty response");
1572 } else if (ar.exception instanceof CommandException) {
1573 loge("getAllowedCarriers: CommandException: " +
1574 ar.exception);
1575 } else {
1576 loge("getAllowedCarriers: Unknown exception");
1577 }
1578 }
arunvoddud7401012022-12-15 16:08:12 +00001579 if (request.argument != null) {
1580 // This is for the implementation of carrierRestrictionStatus.
1581 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1582 Consumer<Integer> callback = callbackInfo.getConsumer();
1583 int callerCarrierId = callbackInfo.getCarrierId();
1584 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1585 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1586 CarrierRestrictionRules carrierRestrictionRules =
1587 (CarrierRestrictionRules) ar.result;
1588 int carrierId = -1;
1589 try {
1590 CarrierIdentifier carrierIdentifier =
1591 carrierRestrictionRules.getAllowedCarriers().get(0);
1592 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1593 carrierIdentifier);
1594 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1595 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1596 }
1597 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1598 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1599 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001600 lockStatus = TelephonyManager
1601 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001602 }
1603 } else {
1604 Rlog.e(LOG_TAG,
1605 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1606 }
1607 callback.accept(lockStatus);
1608 } else {
1609 // This is for the implementation of getAllowedCarriers.
1610 notifyRequester(request);
1611 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001612 break;
1613
Nathan Haroldb3014052017-01-25 15:57:32 -08001614 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1615 ar = (AsyncResult) msg.obj;
1616 request = (MainThreadRequest) ar.userObj;
1617 if (ar.exception == null && ar.result != null) {
1618 request.result = ar.result;
1619 } else {
1620 request.result = new IllegalArgumentException(
1621 "Failed to retrieve Forbidden Plmns");
1622 if (ar.result == null) {
1623 loge("getForbiddenPlmns: Empty response");
1624 } else {
1625 loge("getForbiddenPlmns: Unknown exception");
1626 }
1627 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001628 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001629 break;
1630
1631 case CMD_GET_FORBIDDEN_PLMNS:
1632 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001633 uiccPort = getUiccPortFromRequest(request);
1634 if (uiccPort == null) {
1635 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001636 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001637 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001638 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001639 break;
1640 }
1641 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001642 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001643 if (uiccApp == null) {
1644 loge("getForbiddenPlmns() no app with specified type -- "
1645 + appType);
1646 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001647 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001648 break;
1649 } else {
1650 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1651 + " specified type -- " + appType);
1652 }
1653 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1654 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001655 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001656 break;
1657
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001658 case CMD_SWITCH_SLOTS:
1659 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001660 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001661 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001662 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001663 break;
1664
1665 case EVENT_SWITCH_SLOTS_DONE:
1666 ar = (AsyncResult) msg.obj;
1667 request = (MainThreadRequest) ar.userObj;
1668 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001669 notifyRequester(request);
1670 break;
1671 case CMD_GET_NETWORK_SELECTION_MODE:
1672 request = (MainThreadRequest) msg.obj;
1673 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1674 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1675 break;
1676
1677 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1678 ar = (AsyncResult) msg.obj;
1679 request = (MainThreadRequest) ar.userObj;
1680 if (ar.exception != null) {
1681 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1682 } else {
1683 int mode = ((int[]) ar.result)[0];
1684 if (mode == 0) {
1685 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1686 } else {
1687 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1688 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001689 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001690 notifyRequester(request);
1691 break;
1692 case CMD_GET_CDMA_ROAMING_MODE:
1693 request = (MainThreadRequest) msg.obj;
1694 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1695 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1696 break;
1697 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1698 ar = (AsyncResult) msg.obj;
1699 request = (MainThreadRequest) ar.userObj;
1700 if (ar.exception != null) {
1701 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1702 } else {
1703 request.result = ((int[]) ar.result)[0];
1704 }
1705 notifyRequester(request);
1706 break;
1707 case CMD_SET_CDMA_ROAMING_MODE:
1708 request = (MainThreadRequest) msg.obj;
1709 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1710 int mode = (int) request.argument;
1711 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1712 break;
1713 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1714 ar = (AsyncResult) msg.obj;
1715 request = (MainThreadRequest) ar.userObj;
1716 request.result = ar.exception == null;
1717 notifyRequester(request);
1718 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001719 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1720 request = (MainThreadRequest) msg.obj;
1721 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1722 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1723 break;
1724 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1725 ar = (AsyncResult) msg.obj;
1726 request = (MainThreadRequest) ar.userObj;
1727 if (ar.exception != null) {
1728 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1729 } else {
1730 request.result = ((int[]) ar.result)[0];
1731 }
1732 notifyRequester(request);
1733 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001734 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1735 request = (MainThreadRequest) msg.obj;
1736 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1737 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001738 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1739 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001740 break;
1741 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1742 ar = (AsyncResult) msg.obj;
1743 request = (MainThreadRequest) ar.userObj;
1744 request.result = ar.exception == null;
1745 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001746 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001747 case CMD_GET_ALL_CELL_INFO:
1748 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001749 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001750 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001751 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001752 case EVENT_GET_ALL_CELL_INFO_DONE:
1753 ar = (AsyncResult) msg.obj;
1754 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001755 // If a timeout occurs, the response will be null
1756 request.result = (ar.exception == null && ar.result != null)
1757 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001758 synchronized (request) {
1759 request.notifyAll();
1760 }
1761 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001762 case CMD_REQUEST_CELL_INFO_UPDATE:
1763 request = (MainThreadRequest) msg.obj;
1764 request.phone.requestCellInfoUpdate(request.workSource,
1765 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1766 break;
1767 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1768 ar = (AsyncResult) msg.obj;
1769 request = (MainThreadRequest) ar.userObj;
1770 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1771 try {
1772 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001773 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001774 cb.onError(
1775 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1776 ar.exception.getClass().getName(),
1777 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001778 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001779 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001780 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001781 } else {
1782 // use the result as returned
1783 cb.onCellInfo((List<CellInfo>) ar.result);
1784 }
1785 } catch (RemoteException re) {
1786 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1787 }
1788 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001789 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001790 request = (MainThreadRequest) msg.obj;
1791 WorkSource ws = (WorkSource) request.argument;
1792 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001793 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001794 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001795 }
1796 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001797 ar = (AsyncResult) msg.obj;
1798 request = (MainThreadRequest) ar.userObj;
1799 if (ar.exception == null) {
1800 request.result = ar.result;
1801 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001802 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001803 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001804 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001805 }
1806
1807 synchronized (request) {
1808 request.notifyAll();
1809 }
1810 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001811 }
chen xu6dac5ab2018-10-26 17:39:23 -07001812 case CMD_MODEM_REBOOT:
1813 request = (MainThreadRequest) msg.obj;
1814 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001815 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001816 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001817 case EVENT_CMD_MODEM_REBOOT_DONE:
1818 handleNullReturnEvent(msg, "rebootModem");
1819 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001820 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001821 request = (MainThreadRequest) msg.obj;
1822 boolean enable = (boolean) request.argument;
1823 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001824 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001825 PhoneConfigurationManager.getInstance()
1826 .enablePhone(request.phone, enable, onCompleted);
1827 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001828 }
Michele Berionne5e411512020-11-13 02:36:59 +00001829 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001830 ar = (AsyncResult) msg.obj;
1831 request = (MainThreadRequest) ar.userObj;
1832 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001833 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001834 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001835 if ((boolean) request.result) {
1836 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1837 updateModemStateMetrics();
1838 } else {
1839 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1840 + ar.exception);
1841 }
1842 notifyRequester(request);
1843 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001844 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001845 case CMD_GET_MODEM_STATUS:
1846 request = (MainThreadRequest) msg.obj;
1847 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1848 PhoneConfigurationManager.getInstance()
1849 .getPhoneStatusFromModem(request.phone, onCompleted);
1850 break;
1851 case EVENT_GET_MODEM_STATUS_DONE:
1852 ar = (AsyncResult) msg.obj;
1853 request = (MainThreadRequest) ar.userObj;
1854 int id = request.phone.getPhoneId();
1855 if (ar.exception == null && ar.result != null) {
1856 request.result = ar.result;
1857 //update the cache as modem status has changed
1858 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1859 (boolean) request.result);
1860 } else {
1861 // Return true if modem status cannot be retrieved. For most cases,
1862 // modem status is on. And for older version modems, GET_MODEM_STATUS
1863 // and disable modem are not supported. Modem is always on.
1864 // TODO: this should be fixed in R to support a third
1865 // status UNKNOWN b/131631629
1866 request.result = true;
1867 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1868 + ar.exception);
1869 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001870 notifyRequester(request);
1871 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001872 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1873 request = (MainThreadRequest) msg.obj;
1874 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1875 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1876 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1877 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1878 break;
1879 }
1880 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1881 ar = (AsyncResult) msg.obj;
1882 request = (MainThreadRequest) ar.userObj;
1883 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1884 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1885 args.second.accept(ar.exception == null);
1886 notifyRequester(request);
1887 break;
1888 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001889 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1890 request = (MainThreadRequest) msg.obj;
1891 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1892 Phone phone = getPhoneFromRequest(request);
1893 if (phone != null) {
1894 phone.getSystemSelectionChannels(onCompleted);
1895 } else {
1896 loge("getSystemSelectionChannels: No phone object");
1897 request.result = new ArrayList<RadioAccessSpecifier>();
1898 notifyRequester(request);
1899 }
1900 break;
1901 }
1902 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1903 ar = (AsyncResult) msg.obj;
1904 request = (MainThreadRequest) ar.userObj;
1905 if (ar.exception == null && ar.result != null) {
1906 request.result = ar.result;
1907 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001908 request.result = new IllegalStateException(
1909 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001910 if (ar.result == null) {
1911 loge("getSystemSelectionChannels: Empty response");
1912 } else {
1913 loge("getSystemSelectionChannels: Unknown exception");
1914 }
1915 }
1916 notifyRequester(request);
1917 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001918 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1919 ar = (AsyncResult) msg.obj;
1920 request = (MainThreadRequest) ar.userObj;
1921 if (ar.exception == null && ar.result != null) {
1922 request.result = ar.result;
1923 } else {
1924 request.result = -1;
1925 loge("Failed to set Forbidden Plmns");
1926 if (ar.result == null) {
1927 loge("setForbidenPlmns: Empty response");
1928 } else if (ar.exception != null) {
1929 loge("setForbiddenPlmns: Exception: " + ar.exception);
1930 request.result = -1;
1931 } else {
1932 loge("setForbiddenPlmns: Unknown exception");
1933 }
1934 }
1935 notifyRequester(request);
1936 break;
1937 case CMD_SET_FORBIDDEN_PLMNS:
1938 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001939 uiccPort = getUiccPortFromRequest(request);
1940 if (uiccPort == null) {
1941 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001942 request.result = -1;
1943 notifyRequester(request);
1944 break;
1945 }
1946 Pair<Integer, List<String>> setFplmnsArgs =
1947 (Pair<Integer, List<String>>) request.argument;
1948 appType = setFplmnsArgs.first;
1949 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001950 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001951 if (uiccApp == null) {
1952 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1953 request.result = -1;
1954 loge("Failed to get UICC App");
1955 notifyRequester(request);
1956 } else {
1957 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1958 ((SIMRecords) uiccApp.getIccRecords())
1959 .setForbiddenPlmns(onCompleted, fplmns);
1960 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001961 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001962 case CMD_ERASE_MODEM_CONFIG:
1963 request = (MainThreadRequest) msg.obj;
1964 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1965 defaultPhone.eraseModemConfig(onCompleted);
1966 break;
1967 case EVENT_ERASE_MODEM_CONFIG_DONE:
1968 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001969 break;
zoey chene02881a2019-12-30 16:11:23 +08001970
Kai Shif70f46f2021-03-03 13:59:46 -08001971 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1972 request = (MainThreadRequest) msg.obj;
1973 request.result = defaultPhone.eraseDataInSharedPreferences();
1974 notifyRequester(request);
1975 break;
1976
zoey chene02881a2019-12-30 16:11:23 +08001977 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1978 request = (MainThreadRequest) msg.obj;
1979 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1980 Pair<String, String> changed = (Pair<String, String>) request.argument;
1981 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1982 changed.first, changed.second, onCompleted);
1983 break;
1984 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1985 ar = (AsyncResult) msg.obj;
1986 request = (MainThreadRequest) ar.userObj;
1987 if (ar.exception == null) {
1988 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001989 // If the operation is successful, update the PIN storage
1990 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1991 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001992 UiccController.getInstance().getPinStorage()
1993 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001994 } else {
1995 request.result = msg.arg1;
1996 }
1997 notifyRequester(request);
1998 break;
1999
Michele Berionne5e411512020-11-13 02:36:59 +00002000 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002001 request = (MainThreadRequest) msg.obj;
2002 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2003 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2004 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2005 enabled.first, enabled.second, onCompleted);
2006 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002007 }
zoey chene02881a2019-12-30 16:11:23 +08002008 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2009 ar = (AsyncResult) msg.obj;
2010 request = (MainThreadRequest) ar.userObj;
2011 if (ar.exception == null) {
2012 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002013 // If the operation is successful, update the PIN storage
2014 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2015 int phoneId = getPhoneFromRequest(request).getPhoneId();
2016 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002017 UiccController.getInstance().getPinStorage()
2018 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002019 } else {
2020 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2021 }
zoey chene02881a2019-12-30 16:11:23 +08002022 } else {
2023 request.result = msg.arg1;
2024 }
Michele Berionne5e411512020-11-13 02:36:59 +00002025
2026
zoey chene02881a2019-12-30 16:11:23 +08002027 notifyRequester(request);
2028 break;
2029
Peter Wangdafb9ac2020-01-15 14:13:38 -08002030 case MSG_NOTIFY_USER_ACTIVITY:
2031 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002032 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002033 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2034 getDefaultPhone().getContext().sendBroadcastAsUser(
2035 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2036 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002037
2038 case CMD_SET_DATA_THROTTLING: {
2039 request = (MainThreadRequest) msg.obj;
2040 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2041 DataThrottlingRequest dataThrottlingRequest =
2042 (DataThrottlingRequest) request.argument;
2043 Phone phone = getPhoneFromRequest(request);
2044 if (phone != null) {
2045 phone.setDataThrottling(onCompleted,
2046 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2047 dataThrottlingRequest.getCompletionDurationMillis());
2048 } else {
2049 loge("setDataThrottling: No phone object");
2050 request.result =
2051 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2052 notifyRequester(request);
2053 }
2054
2055 break;
2056 }
2057 case EVENT_SET_DATA_THROTTLING_DONE:
2058 ar = (AsyncResult) msg.obj;
2059 request = (MainThreadRequest) ar.userObj;
2060
2061 if (ar.exception == null) {
2062 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2063 } else if (ar.exception instanceof CommandException) {
2064 loge("setDataThrottling: CommandException: " + ar.exception);
2065 CommandException.Error error =
2066 ((CommandException) (ar.exception)).getCommandError();
2067
2068 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2069 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002070 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002071 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2072 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002073 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2074 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002075 } else {
2076 request.result =
2077 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2078 }
2079 } else {
2080 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2081 }
2082 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2083 notifyRequester(request);
2084 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002085
2086 case CMD_SET_SIM_POWER: {
2087 request = (MainThreadRequest) msg.obj;
2088 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2089 request = (MainThreadRequest) msg.obj;
2090 int stateToSet =
2091 ((Pair<Integer, IIntegerConsumer>)
2092 request.argument).first;
2093 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2094 break;
2095 }
2096 case EVENT_SET_SIM_POWER_DONE: {
2097 ar = (AsyncResult) msg.obj;
2098 request = (MainThreadRequest) ar.userObj;
2099 IIntegerConsumer callback =
2100 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2101 if (ar.exception != null) {
2102 loge("setSimPower exception: " + ar.exception);
2103 int errorCode = TelephonyManager.CallForwardingInfoCallback
2104 .RESULT_ERROR_UNKNOWN;
2105 if (ar.exception instanceof CommandException) {
2106 CommandException.Error error =
2107 ((CommandException) (ar.exception)).getCommandError();
2108 if (error == CommandException.Error.SIM_ERR) {
2109 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2110 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2111 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2112 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2113 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2114 } else {
2115 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2116 }
2117 }
2118 try {
2119 callback.accept(errorCode);
2120 } catch (RemoteException e) {
2121 // Ignore if the remote process is no longer available to call back.
2122 Log.w(LOG_TAG, "setSimPower: callback not available.");
2123 }
2124 } else {
2125 try {
2126 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2127 } catch (RemoteException e) {
2128 // Ignore if the remote process is no longer available to call back.
2129 Log.w(LOG_TAG, "setSimPower: callback not available.");
2130 }
2131 }
2132 break;
2133 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002134 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2135 request = (MainThreadRequest) msg.obj;
2136
2137 final Phone phone = getPhoneFromRequest(request);
2138 if (phone == null || phone.getServiceStateTracker() == null) {
2139 request.result = new IllegalStateException("Phone or SST is null");
2140 notifyRequester(request);
2141 break;
2142 }
2143
2144 Pair<Integer, SignalStrengthUpdateRequest> pair =
2145 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2146 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2147 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002148 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002149 request.subId, pair.first /*callingUid*/,
2150 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002151 break;
2152 }
2153 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2154 ar = (AsyncResult) msg.obj;
2155 request = (MainThreadRequest) ar.userObj;
2156 // request.result will be the exception of ar if present, true otherwise.
2157 // Be cautious not to leave result null which will wait() forever
2158 request.result = ar.exception != null ? ar.exception : true;
2159 notifyRequester(request);
2160 break;
2161 }
2162 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2163 request = (MainThreadRequest) msg.obj;
2164
2165 Phone phone = getPhoneFromRequest(request);
2166 if (phone == null || phone.getServiceStateTracker() == null) {
2167 request.result = new IllegalStateException("Phone or SST is null");
2168 notifyRequester(request);
2169 break;
2170 }
2171
2172 Pair<Integer, SignalStrengthUpdateRequest> pair =
2173 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2174 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2175 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002176 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002177 request.subId, pair.first /*callingUid*/,
2178 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002179 break;
2180 }
2181 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2182 ar = (AsyncResult) msg.obj;
2183 request = (MainThreadRequest) ar.userObj;
2184 request.result = ar.exception != null ? ar.exception : true;
2185 notifyRequester(request);
2186 break;
2187 }
Jordan Liu109698e2020-11-24 14:50:34 -08002188
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002189 case CMD_GET_SLICING_CONFIG: {
2190 request = (MainThreadRequest) msg.obj;
2191 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2192 request.phone.getSlicingConfig(onCompleted);
2193 break;
2194 }
2195 case EVENT_GET_SLICING_CONFIG_DONE: {
2196 ar = (AsyncResult) msg.obj;
2197 request = (MainThreadRequest) ar.userObj;
2198 ResultReceiver result = (ResultReceiver) request.argument;
2199
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002200 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002201 Bundle bundle = new Bundle();
2202 int resultCode = 0;
2203 if (ar.exception != null) {
2204 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2205 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002206 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002207 } else if (ar.result == null) {
2208 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002209 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002210 } else {
2211 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002212 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2213 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002214 }
2215
2216 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002217 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002218 }
2219 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2220 result.send(resultCode, bundle);
2221 notifyRequester(request);
2222 break;
2223 }
2224
Sarah Chin71b3a852022-09-28 15:54:19 -07002225 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002226 request = (MainThreadRequest) msg.obj;
2227 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002228 PurchasePremiumCapabilityArgument arg =
2229 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002230 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chinb8218c22023-01-04 13:35:29 -08002231 arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002232 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002233 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002234
Sarah Chin71b3a852022-09-28 15:54:19 -07002235 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002236 ar = (AsyncResult) msg.obj;
2237 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002238 PurchasePremiumCapabilityArgument arg =
2239 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002240 try {
2241 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002242 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002243 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002244 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002245 + ", result= "
2246 + TelephonyManager.convertPurchaseResultToString(result));
2247 } catch (RemoteException e) {
2248 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002249 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002250 + " failed: " + e;
2251 if (DBG) log(logStr);
2252 AnomalyReporter.reportAnomaly(
2253 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2254 }
2255 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002256 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002257
Michele Berionne5e411512020-11-13 02:36:59 +00002258 case CMD_PREPARE_UNATTENDED_REBOOT:
2259 request = (MainThreadRequest) msg.obj;
2260 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002261 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002262 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002263 notifyRequester(request);
2264 break;
2265
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 default:
2267 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2268 break;
2269 }
2270 }
Jake Hambye994d462014-02-03 13:10:13 -08002271
Pengquan Menga1bb6272018-09-06 09:59:22 -07002272 private void notifyRequester(MainThreadRequest request) {
2273 synchronized (request) {
2274 request.notifyAll();
2275 }
2276 }
2277
Jake Hambye994d462014-02-03 13:10:13 -08002278 private void handleNullReturnEvent(Message msg, String command) {
2279 AsyncResult ar = (AsyncResult) msg.obj;
2280 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2281 if (ar.exception == null) {
2282 request.result = true;
2283 } else {
2284 request.result = false;
2285 if (ar.exception instanceof CommandException) {
2286 loge(command + ": CommandException: " + ar.exception);
2287 } else {
2288 loge(command + ": Unknown exception");
2289 }
2290 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002291 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002292 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002293 }
2294
2295 /**
2296 * Posts the specified command to be executed on the main thread,
2297 * waits for the request to complete, and returns the result.
2298 * @see #sendRequestAsync
2299 */
2300 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002301 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2302 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002303 }
2304
2305 /**
2306 * Posts the specified command to be executed on the main thread,
2307 * waits for the request to complete, and returns the result.
2308 * @see #sendRequestAsync
2309 */
2310 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2311 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002312 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002313 }
2314
2315 /**
2316 * Posts the specified command to be executed on the main thread,
2317 * waits for the request to complete, and returns the result.
2318 * @see #sendRequestAsync
2319 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002320 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002321 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2322 }
2323
2324 /**
2325 * Posts the specified command to be executed on the main thread,
2326 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2327 * if not timeout or null otherwise.
2328 * @see #sendRequestAsync
2329 */
2330 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2331 long timeoutInMs) {
2332 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002333 }
2334
2335 /**
2336 * Posts the specified command to be executed on the main thread,
2337 * waits for the request to complete, and returns the result.
2338 * @see #sendRequestAsync
2339 */
Nathan Harold92bed182018-10-12 18:16:49 -07002340 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002341 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002342 }
2343
2344 /**
2345 * Posts the specified command to be executed on the main thread,
2346 * waits for the request to complete, and returns the result.
2347 * @see #sendRequestAsync
2348 */
2349 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002350 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2351 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002352 }
2353
2354 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002355 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2356 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2357 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002358 * @see #sendRequestAsync
2359 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002360 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2361 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002362 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2363 throw new RuntimeException("This method will deadlock if called from the main thread.");
2364 }
2365
Nathan Harold92bed182018-10-12 18:16:49 -07002366 MainThreadRequest request = null;
2367 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2368 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2369 } else if (phone != null) {
2370 request = new MainThreadRequest(argument, phone, workSource);
2371 } else {
2372 request = new MainThreadRequest(argument, subId, workSource);
2373 }
2374
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 Message msg = mMainThreadHandler.obtainMessage(command, request);
2376 msg.sendToTarget();
2377
Rambo Wang0f050d82021-02-12 11:43:36 -08002378
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002380 if (timeoutInMs >= 0) {
2381 // Wait for at least timeoutInMs before returning null request result
2382 long now = SystemClock.elapsedRealtime();
2383 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002384 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002385 try {
2386 request.wait(deadline - now);
2387 } catch (InterruptedException e) {
2388 // Do nothing, go back and check if request is completed or timeout
2389 } finally {
2390 now = SystemClock.elapsedRealtime();
2391 }
2392 }
2393 } else {
2394 // Wait for the request to complete
2395 while (request.result == null) {
2396 try {
2397 request.wait();
2398 } catch (InterruptedException e) {
2399 // Do nothing, go back and wait until the request is complete
2400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002401 }
2402 }
2403 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002404 if (request.result == null) {
2405 Log.wtf(LOG_TAG,
2406 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2407 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 return request.result;
2409 }
2410
2411 /**
2412 * Asynchronous ("fire and forget") version of sendRequest():
2413 * Posts the specified command to be executed on the main thread, and
2414 * returns immediately.
2415 * @see #sendRequest
2416 */
2417 private void sendRequestAsync(int command) {
2418 mMainThreadHandler.sendEmptyMessage(command);
2419 }
2420
2421 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002422 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002423 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002424 */
2425 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002426 sendRequestAsync(command, argument, null, null);
2427 }
2428
2429 /**
2430 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2431 * @see {@link #sendRequest(int,Object)}
2432 */
2433 private void sendRequestAsync(
2434 int command, Object argument, Phone phone, WorkSource workSource) {
2435 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002436 Message msg = mMainThreadHandler.obtainMessage(command, request);
2437 msg.sendToTarget();
2438 }
2439
2440 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441 * Initialize the singleton PhoneInterfaceManager instance.
2442 * This is only done once, at startup, from PhoneApp.onCreate().
2443 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002444 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 synchronized (PhoneInterfaceManager.class) {
2446 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002447 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 } else {
2449 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2450 }
2451 return sInstance;
2452 }
2453 }
2454
2455 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002456 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002458 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002459 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002460 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002461 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2463 mMainThreadHandler = new MainThreadHandler();
Jack Yue37dd262022-12-16 11:53:37 -08002464 if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) {
2465 mSubscriptionController = SubscriptionController.getInstance();
2466 } else {
2467 mSubscriptionController = null;
2468 }
Sarah Chin4beb2b72023-02-14 14:47:54 -08002469 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002470 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002471 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002472 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002473 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002474 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 publish();
arunvoddud7401012022-12-15 16:08:12 +00002476 CarrierAllowListInfo.loadInstance(mApp);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 }
2478
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002479 @VisibleForTesting
2480 public SharedPreferences getSharedPreferences() {
2481 return mTelephonySharedPreferences;
2482 }
2483
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002484 /**
2485 * Get the default phone for this device.
2486 */
2487 @VisibleForTesting
2488 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002489 Phone thePhone = getPhone(getDefaultSubscription());
2490 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2491 }
2492
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493 private void publish() {
2494 if (DBG) log("publish: " + this);
2495
Peter Wangc035ce42020-01-08 21:00:22 -08002496 TelephonyFrameworkInitializer
2497 .getTelephonyServiceManager()
2498 .getTelephonyServiceRegisterer()
2499 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 }
2501
Stuart Scott584921c2015-01-15 17:10:34 -08002502 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002503 if (request.phone != null) {
2504 return request.phone;
2505 } else {
2506 return getPhoneFromSubId(request.subId);
2507 }
2508 }
2509
2510 private Phone getPhoneFromSubId(int subId) {
2511 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2512 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002513 }
2514
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002515 /**
2516 * Get phone object associated with a subscription.
2517 * Return default phone if phone object associated with subscription is null
2518 * @param subId - subscriptionId
2519 * @return phone object associated with a subscription or default phone if null.
2520 */
Ling Mac28f0212023-03-24 16:07:15 -07002521 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002522 Phone phone = getPhoneFromSubId(subId);
2523 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002524 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002525 phone = getDefaultPhone();
2526 }
2527 return phone;
2528 }
2529
Rambo Wange53e07d2022-05-10 13:01:13 -07002530 @Nullable
2531 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002532 Phone phone = getPhoneFromRequest(request);
2533 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002534 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002535 }
2536
Ling Mac28f0212023-03-24 16:07:15 -07002537 /**
2538 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2539 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2540 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2541 * @return The Phone associated the sub Id
2542 */
2543 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002544 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002545 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002546
Kai Shif70f46f2021-03-03 13:59:46 -08002547 private void sendEraseModemConfig(@NonNull Phone phone) {
2548 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2549 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2550 }
2551
2552 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2553 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2554 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002555 }
2556
Peter Wang44b186e2020-01-13 23:33:09 -08002557 private boolean isImsAvailableOnDevice() {
2558 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2559 if (pm == null) {
2560 // For some reason package manger is not available.. This will fail internally anyway,
2561 // so do not throw error and allow.
2562 return true;
2563 }
2564 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2565 }
2566
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002567 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002568 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002569 }
2570
Wink Savilleb564aae2014-10-23 10:18:09 -07002571 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002572 if (DBG) log("dial: " + number);
2573 // No permission check needed here: This is just a wrapper around the
2574 // ACTION_DIAL intent, which is available to any app since it puts up
2575 // the UI before it does anything.
2576
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002577 final long identity = Binder.clearCallingIdentity();
2578 try {
2579 String url = createTelUrl(number);
2580 if (url == null) {
2581 return;
2582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002583
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002584 // PENDING: should we just silently fail if phone is offhook or ringing?
2585 PhoneConstants.State state = mCM.getState(subId);
2586 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2587 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2588 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2589 mApp.startActivity(intent);
2590 }
2591 } finally {
2592 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002593 }
2594 }
2595
2596 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002597 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002598 }
2599
Wink Savilleb564aae2014-10-23 10:18:09 -07002600 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002601 if (DBG) log("call: " + number);
2602
2603 // This is just a wrapper around the ACTION_CALL intent, but we still
2604 // need to do a permission check since we're calling startActivity()
2605 // from the context of the phone app.
2606 enforceCallPermission();
2607
Jordan Liu1617b712019-07-10 15:06:26 -07002608 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002609 != AppOpsManager.MODE_ALLOWED) {
2610 return;
2611 }
2612
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613 final long identity = Binder.clearCallingIdentity();
2614 try {
2615 String url = createTelUrl(number);
2616 if (url == null) {
2617 return;
2618 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002619
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002620 boolean isValid = false;
2621 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2622 if (slist != null) {
2623 for (SubscriptionInfo subInfoRecord : slist) {
2624 if (subInfoRecord.getSubscriptionId() == subId) {
2625 isValid = true;
2626 break;
2627 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002628 }
Wink Saville08874612014-08-31 19:19:58 -07002629 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002630 if (!isValid) {
2631 return;
2632 }
Wink Saville08874612014-08-31 19:19:58 -07002633
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002634 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2635 intent.putExtra(SUBSCRIPTION_KEY, subId);
2636 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2637 mApp.startActivity(intent);
2638 } finally {
2639 Binder.restoreCallingIdentity(identity);
2640 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002641 }
2642
Wink Savilleb564aae2014-10-23 10:18:09 -07002643 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002644 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002645 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2646 }
2647
Wink Savilleb564aae2014-10-23 10:18:09 -07002648 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002649 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002650 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2651 }
2652
Wink Savilleb564aae2014-10-23 10:18:09 -07002653 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002654 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655
2656 final long identity = Binder.clearCallingIdentity();
2657 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002658 Phone phone = getPhone(subId);
2659 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002660 checkSimPin.start();
2661 return checkSimPin.unlockSim(null, pin);
2662 } finally {
2663 Binder.restoreCallingIdentity(identity);
2664 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002665 }
2666
Wink Savilleb564aae2014-10-23 10:18:09 -07002667 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002668 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002669
2670 final long identity = Binder.clearCallingIdentity();
2671 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002672 Phone phone = getPhone(subId);
2673 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002674 checkSimPuk.start();
2675 return checkSimPuk.unlockSim(puk, pin);
2676 } finally {
2677 Binder.restoreCallingIdentity(identity);
2678 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002679 }
2680
2681 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002682 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002683 * a synchronous one.
2684 */
2685 private static class UnlockSim extends Thread {
2686
2687 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002688 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002689
2690 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002691 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2692 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002693
2694 // For replies from SimCard interface
2695 private Handler mHandler;
2696
2697 // For async handler to identify request type
2698 private static final int SUPPLY_PIN_COMPLETE = 100;
2699
Michele Berionne5e411512020-11-13 02:36:59 +00002700 UnlockSim(int phoneId, IccCard simCard) {
2701 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002702 mSimCard = simCard;
2703 }
2704
2705 @Override
2706 public void run() {
2707 Looper.prepare();
2708 synchronized (UnlockSim.this) {
2709 mHandler = new Handler() {
2710 @Override
2711 public void handleMessage(Message msg) {
2712 AsyncResult ar = (AsyncResult) msg.obj;
2713 switch (msg.what) {
2714 case SUPPLY_PIN_COMPLETE:
2715 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2716 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002717 mRetryCount = msg.arg1;
2718 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002719 CommandException.Error error = null;
2720 if (ar.exception instanceof CommandException) {
2721 error = ((CommandException) (ar.exception))
2722 .getCommandError();
2723 }
2724 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002725 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002726 } else if (error == CommandException.Error.ABORTED) {
2727 /* When UiccCardApp dispose, handle message and return
2728 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002729 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002730 } else {
2731 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2732 }
2733 } else {
2734 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2735 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002736 mDone = true;
2737 UnlockSim.this.notifyAll();
2738 }
2739 break;
2740 }
2741 }
2742 };
2743 UnlockSim.this.notifyAll();
2744 }
2745 Looper.loop();
2746 }
2747
2748 /*
2749 * Use PIN or PUK to unlock SIM card
2750 *
2751 * If PUK is null, unlock SIM card with PIN
2752 *
2753 * If PUK is not null, unlock SIM card with PUK and set PIN code
2754 */
Wink Saville9de0f752013-10-22 19:04:03 -07002755 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002756
2757 while (mHandler == null) {
2758 try {
2759 wait();
2760 } catch (InterruptedException e) {
2761 Thread.currentThread().interrupt();
2762 }
2763 }
2764 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2765
2766 if (puk == null) {
2767 mSimCard.supplyPin(pin, callback);
2768 } else {
2769 mSimCard.supplyPuk(puk, pin, callback);
2770 }
2771
2772 while (!mDone) {
2773 try {
2774 Log.d(LOG_TAG, "wait for done");
2775 wait();
2776 } catch (InterruptedException e) {
2777 // Restore the interrupted status
2778 Thread.currentThread().interrupt();
2779 }
2780 }
2781 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002782 int[] resultArray = new int[2];
2783 resultArray[0] = mResult;
2784 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002785
2786 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002787 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002788 }
2789
Wink Saville9de0f752013-10-22 19:04:03 -07002790 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002791 }
2792 }
2793
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002794 /**
2795 * This method has been removed due to privacy and stability concerns.
2796 */
2797 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002798 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002799 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2800 return;
Wink Saville36469e72014-06-11 15:17:00 -07002801 }
2802
Nathan Harold1f889d82020-06-04 17:05:26 -07002803 @Override
2804 public void updateServiceLocationWithPackageName(String callingPackage) {
2805 mApp.getSystemService(AppOpsManager.class)
2806 .checkPackage(Binder.getCallingUid(), callingPackage);
2807
Nathan Haroldf096d982020-11-18 17:18:06 -08002808 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002809 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2810 // Callers targeting S have no business invoking this method.
2811 return;
2812 }
2813
2814 LocationAccessPolicy.LocationPermissionResult locationResult =
2815 LocationAccessPolicy.checkLocationPermission(mApp,
2816 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2817 .setCallingPackage(callingPackage)
2818 .setCallingFeatureId(null)
2819 .setCallingPid(Binder.getCallingPid())
2820 .setCallingUid(Binder.getCallingUid())
2821 .setMethod("updateServiceLocation")
2822 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2823 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2824 .build());
2825 // Apps that lack location permission have no business calling this method;
2826 // however, because no permission was declared in the public API, denials must
2827 // all be "soft".
2828 switch (locationResult) {
2829 case DENIED_HARD: /* fall through */
2830 case DENIED_SOFT:
2831 return;
2832 }
2833
2834 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002835 final long identity = Binder.clearCallingIdentity();
2836 try {
Ling Mac28f0212023-03-24 16:07:15 -07002837 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002838 } finally {
2839 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002840 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002841 }
2842
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002843 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002844 @Override
2845 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002846 return isRadioOnWithFeature(callingPackage, null);
2847 }
2848
2849
2850 @Override
2851 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2852 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2853 callingFeatureId);
2854 }
2855
2856 @Deprecated
2857 @Override
2858 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2859 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002860 }
2861
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002862 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002863 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2864 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002865 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002866 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002867 return false;
2868 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002869
2870 final long identity = Binder.clearCallingIdentity();
2871 try {
2872 return isRadioOnForSubscriber(subId);
2873 } finally {
2874 Binder.restoreCallingIdentity(identity);
2875 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002876 }
2877
2878 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002879 final long identity = Binder.clearCallingIdentity();
2880 try {
2881 final Phone phone = getPhone(subId);
2882 if (phone != null) {
2883 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2884 } else {
2885 return false;
2886 }
2887 } finally {
2888 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002890 }
2891
2892 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002893 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002894 }
Wink Saville36469e72014-06-11 15:17:00 -07002895
Wink Savilleb564aae2014-10-23 10:18:09 -07002896 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002897 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002898
2899 final long identity = Binder.clearCallingIdentity();
2900 try {
2901 final Phone phone = getPhone(subId);
2902 if (phone != null) {
2903 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2904 }
2905 } finally {
2906 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002907 }
Wink Saville36469e72014-06-11 15:17:00 -07002908 }
2909
2910 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002911 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002912 }
2913
Wink Savilleb564aae2014-10-23 10:18:09 -07002914 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002915 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002916
2917 final long identity = Binder.clearCallingIdentity();
2918 try {
2919 final Phone phone = getPhone(subId);
2920 if (phone == null) {
2921 return false;
2922 }
2923 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2924 toggleRadioOnOffForSubscriber(subId);
2925 }
2926 return true;
2927 } finally {
2928 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002929 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002930 }
Wink Saville36469e72014-06-11 15:17:00 -07002931
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002932 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002933 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002934 /*
2935 * If any of the Radios are available, it will need to be
2936 * shutdown. So return true if any Radio is available.
2937 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938 final long identity = Binder.clearCallingIdentity();
2939 try {
2940 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2941 Phone phone = PhoneFactory.getPhone(i);
2942 if (phone != null && phone.isRadioAvailable()) return true;
2943 }
2944 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2945 return false;
2946 } finally {
2947 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002948 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002949 }
2950
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002952 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002953 enforceModifyPermission();
2954
2955 final long identity = Binder.clearCallingIdentity();
2956 try {
2957 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2958 logv("Shutting down Phone " + i);
2959 shutdownRadioUsingPhoneId(i);
2960 }
2961 } finally {
2962 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002963 }
2964 }
2965
2966 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002967 Phone phone = PhoneFactory.getPhone(phoneId);
2968 if (phone != null && phone.isRadioAvailable()) {
2969 phone.shutdownRadio();
2970 }
2971 }
2972
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002973 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002974 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002975
Ling Ma83dc5ea2023-01-12 15:06:04 -08002976 if (!turnOn) {
2977 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
2978 }
2979
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002980 final long identity = Binder.clearCallingIdentity();
2981 try {
2982 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2983 if (defaultPhone != null) {
2984 defaultPhone.setRadioPower(turnOn);
2985 return true;
2986 } else {
2987 loge("There's no default phone.");
2988 return false;
2989 }
2990 } finally {
2991 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002992 }
Wink Saville36469e72014-06-11 15:17:00 -07002993 }
2994
Wink Savilleb564aae2014-10-23 10:18:09 -07002995 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002996 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002997
Ling Ma83dc5ea2023-01-12 15:06:04 -08002998 if (!turnOn) {
2999 log("setRadioPowerForSubscriber off: subId=" + subId
3000 + ",callingPackage=" + getCurrentPackageName());
3001 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003002 final long identity = Binder.clearCallingIdentity();
3003 try {
3004 final Phone phone = getPhone(subId);
3005 if (phone != null) {
3006 phone.setRadioPower(turnOn);
3007 return true;
3008 } else {
3009 return false;
3010 }
3011 } finally {
3012 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003013 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003014 }
3015
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003016 /**
3017 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3018 * no reason to power it off. When any of the voters want to power it off, it will be turned
3019 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3020 * powering it off, and these radio off votes will be cleared.
3021 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3022 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3023 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3024 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3025 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3026 * check its vote.
3027 *
3028 * @param subId The subscription ID.
3029 * @param reason The reason for powering off radio.
3030 * @return true on success and false on failure.
3031 */
3032 public boolean requestRadioPowerOffForReason(int subId,
3033 @TelephonyManager.RadioPowerReason int reason) {
3034 enforceModifyPermission();
3035
Ling Ma83dc5ea2023-01-12 15:06:04 -08003036 log("requestRadioPowerOffForReason: subId=" + subId
3037 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003038 final long identity = Binder.clearCallingIdentity();
3039 try {
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003040 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003041 if (phone != null) {
3042 phone.setRadioPowerForReason(false, reason);
3043 return true;
3044 } else {
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003045 loge("requestRadioPowerOffForReason: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003046 return false;
3047 }
3048 } finally {
3049 Binder.restoreCallingIdentity(identity);
3050 }
3051 }
3052
3053 /**
3054 * Remove the vote on powering off the radio for a reason, as requested by
3055 * {@link requestRadioPowerOffForReason}.
3056 *
3057 * @param subId The subscription ID.
3058 * @param reason The reason for powering off radio.
3059 * @return true on success and false on failure.
3060 */
3061 public boolean clearRadioPowerOffForReason(int subId,
3062 @TelephonyManager.RadioPowerReason int reason) {
3063 enforceModifyPermission();
3064
3065 final long identity = Binder.clearCallingIdentity();
3066 try {
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003067 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003068 if (phone != null) {
3069 phone.setRadioPowerForReason(true, reason);
3070 return true;
3071 } else {
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003072 loge("clearRadioPowerOffForReason: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003073 return false;
3074 }
3075 } finally {
3076 Binder.restoreCallingIdentity(identity);
3077 }
3078 }
3079
3080 /**
3081 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3082 *
3083 * @param subId The subscription ID.
3084 * @param callingPackage The package making the call.
3085 * @param callingFeatureId The feature in the package.
3086 * @return List of reasons for powering off radio.
3087 */
3088 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3089 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3090
3091 final long identity = Binder.clearCallingIdentity();
3092 List result = new ArrayList();
3093 try {
3094 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3095 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3096 return result;
3097 }
3098
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003099 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003100 if (phone != null) {
3101 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003102 } else {
3103 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003104 }
3105 } finally {
3106 Binder.restoreCallingIdentity(identity);
3107 }
3108 return result;
3109 }
3110
Wink Saville36469e72014-06-11 15:17:00 -07003111 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003112 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003113 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003114 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003115
3116 final long identity = Binder.clearCallingIdentity();
3117 try {
Jack Yu285100e2022-12-02 22:48:35 -08003118 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003119 final Phone phone = getPhone(subId);
3120 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003121 phone.getDataSettingsManager().setDataEnabled(
3122 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003123 return true;
3124 } else {
3125 return false;
3126 }
3127 } finally {
3128 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003129 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003130 }
3131
Wink Saville36469e72014-06-11 15:17:00 -07003132 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003133 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003134 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003135 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003136
3137 final long identity = Binder.clearCallingIdentity();
3138 try {
Jack Yu285100e2022-12-02 22:48:35 -08003139 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003140 final Phone phone = getPhone(subId);
3141 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003142 phone.getDataSettingsManager().setDataEnabled(
3143 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003144 return true;
3145 } else {
3146 return false;
3147 }
3148 } finally {
3149 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003150 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003151 }
3152
Sanket Padawe356d7632015-06-22 14:03:32 -07003153 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003154 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003155 final long identity = Binder.clearCallingIdentity();
3156 try {
3157 final Phone phone = getPhone(subId);
3158 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003159 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003160 } else {
3161 return false;
3162 }
3163 } finally {
3164 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003165 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003166 }
3167
3168 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003169 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003170 }
3171
pkanwarae03a6b2016-11-06 20:37:09 -08003172 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003173 enforceCallPermission();
3174
3175 final long identity = Binder.clearCallingIdentity();
3176 try {
3177 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3178 return;
3179 }
3180 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3181 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3182 } finally {
3183 Binder.restoreCallingIdentity(identity);
3184 }
pkanwar32d516d2016-10-14 19:37:38 -07003185 };
3186
Wink Savilleb564aae2014-10-23 10:18:09 -07003187 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003188 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003189
3190 final long identity = Binder.clearCallingIdentity();
3191 try {
3192 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3193 return false;
3194 }
3195 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3196 } finally {
3197 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003198 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003199 }
3200
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003201 /**
3202 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3203 * tag on getCallState Binder call.
3204 */
3205 @Deprecated
3206 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003207 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003208 if (CompatChanges.isChangeEnabled(
3209 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3210 Binder.getCallingUid())) {
3211 // Do not allow this API to be called on API version 31+, it should only be
3212 // called on old apps using this Binder call directly.
3213 throw new SecurityException("This method can only be used for applications "
3214 + "targeting API version 30 or less.");
3215 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003216 final long identity = Binder.clearCallingIdentity();
3217 try {
Ling Mac28f0212023-03-24 16:07:15 -07003218 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3219 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003220 } finally {
3221 Binder.restoreCallingIdentity(identity);
3222 }
3223 }
3224
3225 @Override
3226 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3227 if (CompatChanges.isChangeEnabled(
3228 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3229 Binder.getCallingUid())) {
3230 // Check READ_PHONE_STATE for API version 31+
3231 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3232 featureId, "getCallStateForSubscription")) {
3233 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3234 + "targeting API level 31+.");
3235 }
3236 }
3237 final long identity = Binder.clearCallingIdentity();
3238 try {
3239 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003240 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3241 PhoneConstantConversions.convertCallState(phone.getState());
3242 } finally {
3243 Binder.restoreCallingIdentity(identity);
3244 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003245 }
3246
Sanket Padawe356d7632015-06-22 14:03:32 -07003247 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003248 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003249 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003250 }
3251
3252 @Override
3253 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003254 final long identity = Binder.clearCallingIdentity();
3255 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003256 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003257 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003258 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003259 } else {
3260 return PhoneConstantConversions.convertDataState(
3261 PhoneConstants.DataState.DISCONNECTED);
3262 }
3263 } finally {
3264 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003265 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003266 }
3267
Sanket Padawe356d7632015-06-22 14:03:32 -07003268 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003269 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003270 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003271 }
3272
3273 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003274 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003275 final long identity = Binder.clearCallingIdentity();
3276 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003277 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003278 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003279 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003280 } else {
3281 return TelephonyManager.DATA_ACTIVITY_NONE;
3282 }
3283 } finally {
3284 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003285 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003286 }
3287
3288 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003289 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003290 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003291 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003292
3293 LocationAccessPolicy.LocationPermissionResult locationResult =
3294 LocationAccessPolicy.checkLocationPermission(mApp,
3295 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3296 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003297 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003298 .setCallingPid(Binder.getCallingPid())
3299 .setCallingUid(Binder.getCallingUid())
3300 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003301 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003302 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3303 .build());
3304 switch (locationResult) {
3305 case DENIED_HARD:
3306 throw new SecurityException("Not allowed to access cell location");
3307 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003308 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3309 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003310 }
3311
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003312 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003313 final long identity = Binder.clearCallingIdentity();
3314 try {
3315 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003316 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003317 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003318 } finally {
3319 Binder.restoreCallingIdentity(identity);
3320 }
Svetoslav64fad262015-04-14 14:35:21 -07003321 }
3322
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003323 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003324 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003325 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3326 // registered cell info, so return a NULL country instead.
3327 final long identity = Binder.clearCallingIdentity();
3328 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003329 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3330 // Get default phone in this case.
3331 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3332 }
Jack Yu285100e2022-12-02 22:48:35 -08003333 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003334 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003335 if (phone == null) return "";
3336 ServiceStateTracker sst = phone.getServiceStateTracker();
3337 if (sst == null) return "";
3338 LocaleTracker lt = sst.getLocaleTracker();
3339 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003340 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003341 } finally {
3342 Binder.restoreCallingIdentity(identity);
3343 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003344 }
3345
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003346 /**
3347 * This method was removed due to potential issues caused by performing partial
3348 * updates of service state, and lack of a credible use case.
3349 *
3350 * This has the ability to break the telephony implementation by disabling notification of
3351 * changes in device connectivity. DO NOT USE THIS!
3352 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003353 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003354 public void enableLocationUpdates() {
3355 mApp.enforceCallingOrSelfPermission(
3356 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003357 }
3358
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003359 /**
3360 * This method was removed due to potential issues caused by performing partial
3361 * updates of service state, and lack of a credible use case.
3362 *
3363 * This has the ability to break the telephony implementation by disabling notification of
3364 * changes in device connectivity. DO NOT USE THIS!
3365 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003366 @Override
3367 public void disableLocationUpdates() {
3368 mApp.enforceCallingOrSelfPermission(
3369 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003370 }
3371
3372 @Override
3373 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003374 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3375 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003376 try {
3377 mApp.getSystemService(AppOpsManager.class)
3378 .checkPackage(Binder.getCallingUid(), callingPackage);
3379 } catch (SecurityException e) {
3380 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3381 throw e;
3382 }
3383
Nathan Haroldf096d982020-11-18 17:18:06 -08003384 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003385 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3386 throw new SecurityException(
3387 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3388 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003389
Jordan Liu1617b712019-07-10 15:06:26 -07003390 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003391 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3392 return null;
3393 }
Svetoslav64fad262015-04-14 14:35:21 -07003394
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003395 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003396
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003397 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003398 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003399
Nathan Haroldf180aac2018-06-01 18:43:55 -07003400 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3401 for (CellInfo ci : info) {
3402 if (ci instanceof CellInfoGsm) {
3403 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3404 } else if (ci instanceof CellInfoWcdma) {
3405 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003407 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003408 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003409 }
3410
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003411 private List<CellInfo> getCachedCellInfo() {
3412 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3413 for (Phone phone : PhoneFactory.getPhones()) {
3414 List<CellInfo> info = phone.getAllCellInfo();
3415 if (info != null) cellInfos.addAll(info);
3416 }
3417 return cellInfos;
3418 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003419
3420 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003421 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003422 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003423 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003424
3425 LocationAccessPolicy.LocationPermissionResult locationResult =
3426 LocationAccessPolicy.checkLocationPermission(mApp,
3427 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3428 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003429 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003430 .setCallingPid(Binder.getCallingPid())
3431 .setCallingUid(Binder.getCallingUid())
3432 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003433 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003434 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3435 .build());
3436 switch (locationResult) {
3437 case DENIED_HARD:
3438 throw new SecurityException("Not allowed to access cell info");
3439 case DENIED_SOFT:
3440 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003441 }
3442
Nathan Haroldf096d982020-11-18 17:18:06 -08003443 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003444 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3445 return getCachedCellInfo();
3446 }
3447
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003448 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003449 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003450 final long identity = Binder.clearCallingIdentity();
3451 try {
3452 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3453 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003454 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003455 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003456 if (info != null) cellInfos.addAll(info);
3457 }
3458 return cellInfos;
3459 } finally {
3460 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003461 }
3462 }
3463
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003464 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003465 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3466 String callingFeatureId) {
3467 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3468 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003469 }
3470
3471 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003472 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3473 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003474 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003475 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003476 }
3477
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003478 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3479 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003480 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003481 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003482
3483 LocationAccessPolicy.LocationPermissionResult locationResult =
3484 LocationAccessPolicy.checkLocationPermission(mApp,
3485 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3486 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003487 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003488 .setCallingPid(Binder.getCallingPid())
3489 .setCallingUid(Binder.getCallingUid())
3490 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003491 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3492 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003493 .build());
3494 switch (locationResult) {
3495 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003496 if (TelephonyPermissions
3497 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003498 // Safetynet logging for b/154934934
3499 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3500 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003501 throw new SecurityException("Not allowed to access cell info");
3502 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003503 if (TelephonyPermissions
3504 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003505 // Safetynet logging for b/154934934
3506 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3507 }
Nathan Harold5320c422019-05-09 10:26:08 -07003508 try {
3509 cb.onCellInfo(new ArrayList<CellInfo>());
3510 } catch (RemoteException re) {
3511 // Drop without consequences
3512 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003513 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003514 }
3515
Nathan Harolda939a962019-05-09 10:13:47 -07003516
3517 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003518 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3519
3520 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3521 }
3522
3523 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003524 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003525 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003526 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003527
3528 final long identity = Binder.clearCallingIdentity();
3529 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003530 Phone phone = getPhone(subId);
3531 if (phone == null) {
3532 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3533 } else {
3534 phone.setCellInfoListRate(rateInMillis, workSource);
3535 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003536 } finally {
3537 Binder.restoreCallingIdentity(identity);
3538 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003539 }
3540
Shishir Agrawala9f32182016-04-12 12:00:16 -07003541 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003542 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003543 Phone phone = PhoneFactory.getPhone(slotIndex);
3544 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003545 return null;
3546 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003547 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003548 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003549 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003550 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003551 return null;
3552 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003553
3554 final long identity = Binder.clearCallingIdentity();
3555 try {
3556 return phone.getImei();
3557 } finally {
3558 Binder.restoreCallingIdentity(identity);
3559 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003560 }
3561
3562 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003563 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3564 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3565 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3566 callingFeatureId, "getPrimaryImei")) {
3567 throw new SecurityException("Caller does not have permission");
3568 }
3569 final long identity = Binder.clearCallingIdentity();
3570 try {
3571 for (Phone phone : PhoneFactory.getPhones()) {
3572 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3573 return phone.getImei();
3574 }
3575 }
3576 throw new UnsupportedOperationException("Operation not supported");
3577 } finally {
3578 Binder.restoreCallingIdentity(identity);
3579 }
3580 }
3581
3582 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003583 public String getTypeAllocationCodeForSlot(int slotIndex) {
3584 Phone phone = PhoneFactory.getPhone(slotIndex);
3585 String tac = null;
3586 if (phone != null) {
3587 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003588 try {
3589 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3590 } catch (IndexOutOfBoundsException e) {
3591 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3592 return null;
3593 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003594 }
3595 return tac;
3596 }
3597
3598 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003599 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003600 try {
3601 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3602 } catch (SecurityException se) {
3603 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3604 throw new SecurityException("Package " + callingPackage + " does not belong to "
3605 + Binder.getCallingUid());
3606 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003607 Phone phone = PhoneFactory.getPhone(slotIndex);
3608 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003609 return null;
3610 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003611
Jeff Davidson913390f2018-02-23 17:11:49 -08003612 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003613 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003614 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003615 return null;
3616 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003617
3618 final long identity = Binder.clearCallingIdentity();
3619 try {
3620 return phone.getMeid();
3621 } finally {
3622 Binder.restoreCallingIdentity(identity);
3623 }
Jack Yu2af8d712017-03-15 17:14:14 -07003624 }
3625
3626 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003627 public String getManufacturerCodeForSlot(int slotIndex) {
3628 Phone phone = PhoneFactory.getPhone(slotIndex);
3629 String manufacturerCode = null;
3630 if (phone != null) {
3631 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003632 try {
3633 manufacturerCode =
3634 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3635 } catch (IndexOutOfBoundsException e) {
3636 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3637 return null;
3638 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003639 }
3640 return manufacturerCode;
3641 }
3642
3643 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003644 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3645 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003646 Phone phone = PhoneFactory.getPhone(slotIndex);
3647 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003648 return null;
3649 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003650 int subId = phone.getSubId();
3651 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003652 mApp, subId, callingPackage, callingFeatureId,
3653 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003654 return null;
3655 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003656
3657 final long identity = Binder.clearCallingIdentity();
3658 try {
3659 return phone.getDeviceSvn();
3660 } finally {
3661 Binder.restoreCallingIdentity(identity);
3662 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003663 }
3664
fionaxu43304da2017-11-27 22:51:16 -08003665 @Override
3666 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003667 final long identity = Binder.clearCallingIdentity();
3668 try {
3669 final Phone phone = getPhone(subId);
3670 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3671 } finally {
3672 Binder.restoreCallingIdentity(identity);
3673 }
fionaxu43304da2017-11-27 22:51:16 -08003674 }
3675
3676 @Override
3677 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003678 final long identity = Binder.clearCallingIdentity();
3679 try {
3680 final Phone phone = getPhone(subId);
3681 return phone == null ? null : phone.getCarrierName();
3682 } finally {
3683 Binder.restoreCallingIdentity(identity);
3684 }
fionaxu43304da2017-11-27 22:51:16 -08003685 }
3686
calvinpanffe225e2018-11-01 19:43:06 +08003687 @Override
chen xu0026ca62019-03-06 15:28:50 -08003688 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003689 final long identity = Binder.clearCallingIdentity();
3690 try {
3691 final Phone phone = getPhone(subId);
3692 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003693 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003694 } finally {
3695 Binder.restoreCallingIdentity(identity);
3696 }
3697 }
3698
3699 @Override
chen xu0026ca62019-03-06 15:28:50 -08003700 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003701 final long identity = Binder.clearCallingIdentity();
3702 try {
3703 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003704 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003705 } finally {
3706 Binder.restoreCallingIdentity(identity);
3707 }
3708 }
3709
chen xu651eec72018-11-11 19:03:44 -08003710 @Override
chen xu864e11c2018-12-06 22:10:03 -08003711 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3712 if (!isSubscriptionMccMnc) {
3713 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3714 }
chen xu651eec72018-11-11 19:03:44 -08003715 final Phone phone = PhoneFactory.getPhone(slotIndex);
3716 if (phone == null) {
3717 return TelephonyManager.UNKNOWN_CARRIER_ID;
3718 }
3719 final long identity = Binder.clearCallingIdentity();
3720 try {
3721 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3722 } finally {
3723 Binder.restoreCallingIdentity(identity);
3724 }
3725 }
3726
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003727 //
3728 // Internal helper methods.
3729 //
3730
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003731 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003732 * Make sure the caller is the calling package itself
3733 *
3734 * @throws SecurityException if the caller is not the calling package
3735 */
3736 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3737 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003738 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3739 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003740 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003741 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003742 } catch (PackageManager.NameNotFoundException e) {
3743 // packageUid is -1
3744 }
3745 if (packageUid != callingUid) {
3746 throw new SecurityException(message + ": Package " + callingPackage
3747 + " does not belong to " + callingUid);
3748 }
3749 }
3750
3751 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003752 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3753 *
3754 * @throws SecurityException if the caller does not have the required permission
3755 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003756 @VisibleForTesting
3757 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003758 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3759 }
3760
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003761 /**
arunvoddud7401012022-12-15 16:08:12 +00003762 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003763 *
3764 * @throws SecurityException if the caller does not have the required permission
3765 */
3766 @VisibleForTesting
3767 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003768 enforceReadPermission(null);
3769 }
3770
3771 /**
3772 * Make sure the caller has the READ_PHONE_STATE permissions.
3773 *
3774 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3775 */
3776 @VisibleForTesting
3777 public void enforceReadPermission(String msg) {
3778 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003779 }
3780
Shuo Qian3b6ee772019-11-13 17:43:31 -08003781 private void enforceActiveEmergencySessionPermission() {
3782 mApp.enforceCallingOrSelfPermission(
3783 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3784 }
3785
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003786 /**
3787 * Make sure the caller has the CALL_PHONE permission.
3788 *
3789 * @throws SecurityException if the caller does not have the required permission
3790 */
3791 private void enforceCallPermission() {
3792 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3793 }
3794
paulhu5a773602019-08-23 19:17:33 +08003795 private void enforceSettingsPermission() {
3796 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003797 }
3798
Michele Berionne5e411512020-11-13 02:36:59 +00003799 private void enforceRebootPermission() {
3800 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3801 }
3802
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003803 /**
3804 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3805 * @param message - log message to print.
3806 * @throws SecurityException if the caller does not have the required permission
3807 */
3808 private void enforceSatelliteCommunicationPermission(String message) {
3809 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3810 }
3811
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003812 private String createTelUrl(String number) {
3813 if (TextUtils.isEmpty(number)) {
3814 return null;
3815 }
3816
Jake Hambye994d462014-02-03 13:10:13 -08003817 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003818 }
3819
Ihab Awadf9e92732013-12-05 18:02:52 -08003820 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003821 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003822 }
3823
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003824 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003825 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003826 }
3827
Ihab Awadf9e92732013-12-05 18:02:52 -08003828 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003829 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003830 }
3831
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003832 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003833 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003834 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003835 }
3836
Sanket Padawe356d7632015-06-22 14:03:32 -07003837 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003838 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003839 final long identity = Binder.clearCallingIdentity();
3840 try {
3841 final Phone phone = PhoneFactory.getPhone(slotIndex);
3842 if (phone == null) {
3843 return PhoneConstants.PHONE_TYPE_NONE;
3844 } else {
3845 return phone.getPhoneType();
3846 }
3847 } finally {
3848 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003849 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003850 }
3851
3852 /**
3853 * Returns the CDMA ERI icon index to display
3854 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003855 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003856 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3857 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3858 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003859 }
3860
Sanket Padawe356d7632015-06-22 14:03:32 -07003861 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003862 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3863 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003864 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003865 mApp, subId, callingPackage, callingFeatureId,
3866 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003867 return -1;
3868 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003869
3870 final long identity = Binder.clearCallingIdentity();
3871 try {
3872 final Phone phone = getPhone(subId);
3873 if (phone != null) {
3874 return phone.getCdmaEriIconIndex();
3875 } else {
3876 return -1;
3877 }
3878 } finally {
3879 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003880 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003881 }
3882
3883 /**
3884 * Returns the CDMA ERI icon mode,
3885 * 0 - ON
3886 * 1 - FLASHING
3887 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003888 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003889 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3890 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3891 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003892 }
3893
Sanket Padawe356d7632015-06-22 14:03:32 -07003894 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003895 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3896 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003897 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003898 mApp, subId, callingPackage, callingFeatureId,
3899 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003900 return -1;
3901 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003902
3903 final long identity = Binder.clearCallingIdentity();
3904 try {
3905 final Phone phone = getPhone(subId);
3906 if (phone != null) {
3907 return phone.getCdmaEriIconMode();
3908 } else {
3909 return -1;
3910 }
3911 } finally {
3912 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003913 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003914 }
3915
3916 /**
3917 * Returns the CDMA ERI text,
3918 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003919 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003920 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3921 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3922 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003923 }
3924
Sanket Padawe356d7632015-06-22 14:03:32 -07003925 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003926 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3927 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003928 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003929 mApp, subId, callingPackage, callingFeatureId,
3930 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003931 return null;
3932 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003933
3934 final long identity = Binder.clearCallingIdentity();
3935 try {
3936 final Phone phone = getPhone(subId);
3937 if (phone != null) {
3938 return phone.getCdmaEriText();
3939 } else {
3940 return null;
3941 }
3942 } finally {
3943 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003944 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003945 }
3946
3947 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003948 * Returns the CDMA MDN.
3949 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003950 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003951 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3953 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003954
3955 final long identity = Binder.clearCallingIdentity();
3956 try {
3957 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003958 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003959 return phone.getLine1Number();
3960 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003961 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003962 return null;
3963 }
3964 } finally {
3965 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003966 }
3967 }
3968
3969 /**
3970 * Returns the CDMA MIN.
3971 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003972 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003973 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003974 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3975 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003976
3977 final long identity = Binder.clearCallingIdentity();
3978 try {
3979 final Phone phone = getPhone(subId);
3980 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3981 return phone.getCdmaMin();
3982 } else {
3983 return null;
3984 }
3985 } finally {
3986 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003987 }
3988 }
3989
Hall Liud892bec2018-11-30 14:51:45 -08003990 @Override
3991 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3992 INumberVerificationCallback callback, String callingPackage) {
3993 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3994 != PERMISSION_GRANTED) {
3995 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3996 }
3997 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3998
3999 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4000 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004001 throw new SecurityException("Calling package must be configured in the device config: "
4002 + "calling package: " + callingPackage
4003 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004004 }
4005
4006 if (range == null) {
4007 throw new NullPointerException("Range must be non-null");
4008 }
4009
4010 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004011 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004012
4013 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4014 }
4015
Junda Liuca05d5d2014-08-14 22:36:34 -07004016 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004017 * Returns true if CDMA provisioning needs to run.
4018 */
4019 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004020 final long identity = Binder.clearCallingIdentity();
4021 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004022 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004023 } finally {
4024 Binder.restoreCallingIdentity(identity);
4025 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004026 }
4027
4028 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004029 * Sets the voice mail number of a given subId.
4030 */
4031 @Override
4032 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004033 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4034 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004035
4036 final long identity = Binder.clearCallingIdentity();
4037 try {
4038 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4039 new Pair<String, String>(alphaTag, number), new Integer(subId));
4040 return success;
4041 } finally {
4042 Binder.restoreCallingIdentity(identity);
4043 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004044 }
4045
Ta-wei Yen87c49842016-05-13 21:19:52 -07004046 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004047 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4048 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004049 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4050 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004051 if (!TextUtils.equals(callingPackage, systemDialer)) {
4052 throw new SecurityException("caller must be system dialer");
4053 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004054
4055 final long identity = Binder.clearCallingIdentity();
4056 try {
4057 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4058 if (phoneAccountHandle == null) {
4059 return null;
4060 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004061 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004062 } finally {
4063 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004064 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004065 }
4066
4067 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004068 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4069 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004070 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004071 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004072 mApp, subId, callingPackage, callingFeatureId,
4073 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004074 return null;
4075 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004076
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004077 final long identity = Binder.clearCallingIdentity();
4078 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004079 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004080 } finally {
4081 Binder.restoreCallingIdentity(identity);
4082 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004083 }
4084
4085 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004086 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4087 VisualVoicemailSmsFilterSettings settings) {
4088 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004089
4090 final long identity = Binder.clearCallingIdentity();
4091 try {
4092 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004093 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004094 } finally {
4095 Binder.restoreCallingIdentity(identity);
4096 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004097 }
4098
4099 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004100 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4101 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004102
4103 final long identity = Binder.clearCallingIdentity();
4104 try {
4105 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004106 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004107 } finally {
4108 Binder.restoreCallingIdentity(identity);
4109 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004110 }
4111
4112 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004113 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4114 String callingPackage, int subId) {
4115 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004116
4117 final long identity = Binder.clearCallingIdentity();
4118 try {
4119 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004120 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004121 } finally {
4122 Binder.restoreCallingIdentity(identity);
4123 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004124 }
4125
4126 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004127 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004128 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004129
4130 final long identity = Binder.clearCallingIdentity();
4131 try {
4132 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004133 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004134 } finally {
4135 Binder.restoreCallingIdentity(identity);
4136 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004137 }
4138
4139 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004140 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4141 String callingAttributionTag, int subId, String number, int port, String text,
4142 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004143 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004144 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004145 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004146 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004147 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4148 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004149 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004150
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004151 /**
fionaxu0152e512016-11-14 13:36:14 -08004152 * Sets the voice activation state of a given subId.
4153 */
4154 @Override
4155 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4157 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004158
4159 final long identity = Binder.clearCallingIdentity();
4160 try {
4161 final Phone phone = getPhone(subId);
4162 if (phone != null) {
4163 phone.setVoiceActivationState(activationState);
4164 } else {
4165 loge("setVoiceActivationState fails with invalid subId: " + subId);
4166 }
4167 } finally {
4168 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004169 }
4170 }
4171
4172 /**
4173 * Sets the data activation state of a given subId.
4174 */
4175 @Override
4176 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004177 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4178 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004179
4180 final long identity = Binder.clearCallingIdentity();
4181 try {
4182 final Phone phone = getPhone(subId);
4183 if (phone != null) {
4184 phone.setDataActivationState(activationState);
4185 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004186 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004187 }
4188 } finally {
4189 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004190 }
4191 }
4192
4193 /**
4194 * Returns the voice activation state of a given subId.
4195 */
4196 @Override
4197 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004198 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004199
fionaxu0152e512016-11-14 13:36:14 -08004200 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004201 final long identity = Binder.clearCallingIdentity();
4202 try {
4203 if (phone != null) {
4204 return phone.getVoiceActivationState();
4205 } else {
4206 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4207 }
4208 } finally {
4209 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004210 }
4211 }
4212
4213 /**
4214 * Returns the data activation state of a given subId.
4215 */
4216 @Override
4217 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004218 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004219
fionaxu0152e512016-11-14 13:36:14 -08004220 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004221 final long identity = Binder.clearCallingIdentity();
4222 try {
4223 if (phone != null) {
4224 return phone.getDataActivationState();
4225 } else {
4226 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4227 }
4228 } finally {
4229 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004230 }
4231 }
4232
4233 /**
Wink Saville36469e72014-06-11 15:17:00 -07004234 * Returns the unread count of voicemails for a subId
4235 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004236 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004237 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4238 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004239 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004240 mApp, subId, callingPackage, callingFeatureId,
4241 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004242 return 0;
4243 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004244 final long identity = Binder.clearCallingIdentity();
4245 try {
4246 final Phone phone = getPhone(subId);
4247 if (phone != null) {
4248 return phone.getVoiceMessageCount();
4249 } else {
4250 return 0;
4251 }
4252 } finally {
4253 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004254 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004255 }
4256
4257 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004258 * returns true, if the device is in a state where both voice and data
4259 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004260 */
4261 @Override
4262 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004263 final long identity = Binder.clearCallingIdentity();
4264 try {
Ling Mac28f0212023-03-24 16:07:15 -07004265 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004266 } finally {
4267 Binder.restoreCallingIdentity(identity);
4268 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004269 }
4270
4271 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004272 * Send the dialer code if called from the current default dialer or the caller has
4273 * carrier privilege.
4274 * @param inputCode The dialer code to send
4275 */
4276 @Override
4277 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004278 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004279 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004280 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4281 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004282 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004283 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004284 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004285 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004286
4287 final long identity = Binder.clearCallingIdentity();
4288 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004289 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004290 } finally {
4291 Binder.restoreCallingIdentity(identity);
4292 }
fionaxu235cc5e2017-03-06 22:25:57 -08004293 }
4294
Pengquan Menga1bb6272018-09-06 09:59:22 -07004295 @Override
4296 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004297 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004298 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4299 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08004300 final long identity = Binder.clearCallingIdentity();
4301 try {
4302 if (!isActiveSubscription(subId)) {
4303 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4304 }
4305 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4306 } finally {
4307 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004308 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004309 }
4310
Brad Ebinger35c841c2018-10-01 10:40:55 -07004311 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004312 public boolean isInEmergencySmsMode() {
4313 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4314 final long identity = Binder.clearCallingIdentity();
4315 try {
4316 for (Phone phone : PhoneFactory.getPhones()) {
4317 if (phone.isInEmergencySmsMode()) {
4318 return true;
4319 }
4320 }
4321 } finally {
4322 Binder.restoreCallingIdentity(identity);
4323 }
4324 return false;
4325 }
4326
shilu366312e2019-12-17 09:28:10 -08004327 /**
4328 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4329 * @param subId The subscription to use to check the configuration.
4330 * @param c The callback that will be used to send the result.
4331 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004332 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004333 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4334 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004335 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004336 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004337
4338 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4339 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4340 "IMS not available on device.");
4341 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004342 final long token = Binder.clearCallingIdentity();
4343 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004344 int slotId = getSlotIndexOrException(subId);
4345 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004346
4347 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4348 if (controller != null) {
4349 ImsManager imsManager = controller.getImsManager(subId);
4350 if (imsManager != null) {
4351 imsManager.addRegistrationCallbackForSubscription(c, subId);
4352 } else {
4353 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4354 }
4355 } else {
4356 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4357 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004358 } catch (ImsException e) {
4359 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004360 } finally {
4361 Binder.restoreCallingIdentity(token);
4362 }
4363 }
4364
shilu366312e2019-12-17 09:28:10 -08004365 /**
4366 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4367 * @param subId The subscription to use to check the configuration.
4368 * @param c The callback that will be used to send the result.
4369 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004370 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004371 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004372 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004373 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004374 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4375 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4376 }
Meng Wangafbc5852019-09-19 17:37:13 -07004377 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004378
Meng Wangafbc5852019-09-19 17:37:13 -07004379 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004380 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4381 if (controller != null) {
4382 ImsManager imsManager = controller.getImsManager(subId);
4383 if (imsManager != null) {
4384 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4385 } else {
4386 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4387 + "is inactive, ignoring unregister.");
4388 // If the ImsManager is not valid, just return, since the callback
4389 // will already have been removed internally.
4390 }
4391 }
Meng Wangafbc5852019-09-19 17:37:13 -07004392 } finally {
4393 Binder.restoreCallingIdentity(token);
4394 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004395 }
4396
Brad Ebingera34a6c22019-10-22 17:36:18 -07004397 /**
4398 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4399 */
4400 @Override
4401 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4402 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4403 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4404 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4405 "IMS not available on device.");
4406 }
4407 final long token = Binder.clearCallingIdentity();
4408 try {
4409 Phone phone = getPhone(subId);
4410 if (phone == null) {
4411 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4412 + subId + "'");
4413 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4414 }
4415 phone.getImsRegistrationState(regState -> {
4416 try {
4417 consumer.accept((regState == null)
4418 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4419 } catch (RemoteException e) {
4420 // Ignore if the remote process is no longer available to call back.
4421 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4422 }
4423 });
4424 } finally {
4425 Binder.restoreCallingIdentity(token);
4426 }
4427 }
4428
4429 /**
4430 * Get the transport type for the IMS service registration state.
4431 */
4432 @Override
4433 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004434 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004435 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004436 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4437 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4438 "IMS not available on device.");
4439 }
4440 final long token = Binder.clearCallingIdentity();
4441 try {
4442 Phone phone = getPhone(subId);
4443 if (phone == null) {
4444 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4445 + subId + "'");
4446 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4447 }
4448 phone.getImsRegistrationTech(regTech -> {
4449 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4450 int regTechConverted = (regTech == null)
4451 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4452 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4453 regTechConverted);
4454 try {
4455 consumer.accept(regTechConverted);
4456 } catch (RemoteException e) {
4457 // Ignore if the remote process is no longer available to call back.
4458 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4459 }
4460 });
4461 } finally {
4462 Binder.restoreCallingIdentity(token);
4463 }
4464 }
4465
shilu366312e2019-12-17 09:28:10 -08004466 /**
4467 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4468 * @param subId The subscription to use to check the configuration.
4469 * @param c The callback that will be used to send the result.
4470 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004471 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004472 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4473 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004474 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004475 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004476 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4477 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4478 "IMS not available on device.");
4479 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004480 final long token = Binder.clearCallingIdentity();
4481 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004482 int slotId = getSlotIndexOrException(subId);
4483 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004484
4485 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4486 if (controller != null) {
4487 ImsManager imsManager = controller.getImsManager(subId);
4488 if (imsManager != null) {
4489 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4490 } else {
4491 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4492 }
4493 } else {
4494 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4495 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004496 } catch (ImsException e) {
4497 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004498 } finally {
4499 Binder.restoreCallingIdentity(token);
4500 }
4501 }
4502
shilu366312e2019-12-17 09:28:10 -08004503 /**
4504 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4505 * @param subId The subscription to use to check the configuration.
4506 * @param c The callback that will be used to send the result.
4507 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004508 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004509 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004510 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004511 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004512 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4513 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4514 }
Meng Wangafbc5852019-09-19 17:37:13 -07004515
4516 final long token = Binder.clearCallingIdentity();
4517 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004518 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4519 if (controller != null) {
4520 ImsManager imsManager = controller.getImsManager(subId);
4521 if (imsManager != null) {
4522 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4523 } else {
4524 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4525 + " is inactive, ignoring unregister.");
4526 // If the ImsManager is not valid, just return, since the callback
4527 // will already have been removed internally.
4528 }
4529 }
Meng Wangafbc5852019-09-19 17:37:13 -07004530 } finally {
4531 Binder.restoreCallingIdentity(token);
4532 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004533 }
4534
4535 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004536 public boolean isCapable(int subId, int capability, int regTech) {
4537 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004538 final long token = Binder.clearCallingIdentity();
4539 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004540 int slotId = getSlotIndexOrException(subId);
4541 verifyImsMmTelConfiguredOrThrow(slotId);
4542 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4543 } catch (com.android.ims.ImsException e) {
4544 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4545 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004546 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004547 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4548 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004549 } finally {
4550 Binder.restoreCallingIdentity(token);
4551 }
4552 }
4553
4554 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004555 public boolean isAvailable(int subId, int capability, int regTech) {
4556 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004557 final long token = Binder.clearCallingIdentity();
4558 try {
4559 Phone phone = getPhone(subId);
4560 if (phone == null) return false;
4561 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004562 } catch (com.android.ims.ImsException e) {
4563 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4564 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004565 } finally {
4566 Binder.restoreCallingIdentity(token);
4567 }
4568 }
4569
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004570 /**
4571 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4572 * subscription.
4573 * @param subId The subscription to use to check the configuration.
4574 * @param callback The callback that will be used to send the result.
4575 * @param capability The MmTelFeature capability that will be used to send the result.
4576 * @param transportType The transport type of the MmTelFeature capability.
4577 */
4578 @Override
4579 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4580 int transportType) {
4581 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004582 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4583 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4584 "IMS not available on device.");
4585 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004586 final long token = Binder.clearCallingIdentity();
4587 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004588 int slotId = getSlotIndex(subId);
4589 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4590 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4591 + subId + "'");
4592 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4593 }
4594 verifyImsMmTelConfiguredOrThrow(slotId);
4595 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4596 transportType, aBoolean -> {
4597 try {
4598 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4599 } catch (RemoteException e) {
4600 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4601 + "running. Ignore");
4602 }
4603 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004604 } catch (ImsException e) {
4605 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004606 } finally {
4607 Binder.restoreCallingIdentity(token);
4608 }
4609 }
4610
shilu366312e2019-12-17 09:28:10 -08004611 /**
4612 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4613 * @param subId The subscription to use to check the configuration.
4614 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004615 @Override
4616 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004617 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004618 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004619
Brad Ebinger35c841c2018-10-01 10:40:55 -07004620 final long token = Binder.clearCallingIdentity();
4621 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004622 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004623 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004624 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004625 } catch (ImsException e) {
4626 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004627 } finally {
4628 Binder.restoreCallingIdentity(token);
4629 }
4630 }
4631
4632 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004633 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004635 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004636 final long identity = Binder.clearCallingIdentity();
4637 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004638 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004639 // This setting doesn't require an active ImsService connection, so do not verify. The
4640 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004641 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004642 } catch (ImsException e) {
4643 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004644 } finally {
4645 Binder.restoreCallingIdentity(identity);
4646 }
4647 }
4648
shilu366312e2019-12-17 09:28:10 -08004649 /**
4650 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4651 * @param subId The subscription to use to check the configuration.
4652 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004653 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004654 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004655 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004656 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004657 final long identity = Binder.clearCallingIdentity();
4658 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004659 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004660 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004661 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004662 } catch (ImsException e) {
4663 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004664 } finally {
4665 Binder.restoreCallingIdentity(identity);
4666 }
4667 }
4668
4669 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004670 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004671 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004672 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004673 final long identity = Binder.clearCallingIdentity();
4674 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004675 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004676 // This setting doesn't require an active ImsService connection, so do not verify. The
4677 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004678 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004679 } catch (ImsException e) {
4680 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004681 } finally {
4682 Binder.restoreCallingIdentity(identity);
4683 }
4684 }
4685
shilu366312e2019-12-17 09:28:10 -08004686 /**
4687 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4688 * @param subId The subscription to use to check the configuration.
4689 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004690 @Override
4691 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004692 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004693 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004694 final long identity = Binder.clearCallingIdentity();
4695 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004696 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004697 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004698 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004699 } catch (ImsException e) {
4700 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004701 } finally {
4702 Binder.restoreCallingIdentity(identity);
4703 }
4704 }
4705
4706 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004707 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004708 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004709 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004710 final long identity = Binder.clearCallingIdentity();
4711 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004712 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004713 // This setting doesn't require an active ImsService connection, so do not verify. The
4714 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004715 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004716 } catch (ImsException e) {
4717 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004718 } finally {
4719 Binder.restoreCallingIdentity(identity);
4720 }
4721 }
4722
shilu366312e2019-12-17 09:28:10 -08004723 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004724 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4725 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4726 * @param subId The subscription to use to check the configuration.
4727 */
4728 @Override
4729 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004730 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004731 mApp, subId, "isCrossSimCallingEnabledByUser");
4732 final long identity = Binder.clearCallingIdentity();
4733 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004734 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004735 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004736 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004737 } catch (ImsException e) {
4738 throw new ServiceSpecificException(e.getCode());
4739 } finally {
4740 Binder.restoreCallingIdentity(identity);
4741 }
4742 }
4743
4744 /**
4745 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4746 * Requires MODIFY_PHONE_STATE permission.
4747 * @param subId The subscription to use to check the configuration.
4748 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4749 * false otherwise
4750 */
4751 @Override
4752 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4753 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4754 "setCrossSimCallingEnabled");
4755 final long identity = Binder.clearCallingIdentity();
4756 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004757 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004758 // This setting doesn't require an active ImsService connection, so do not verify. The
4759 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004760 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004761 } catch (ImsException e) {
4762 throw new ServiceSpecificException(e.getCode());
4763 } finally {
4764 Binder.restoreCallingIdentity(identity);
4765 }
4766 }
4767
4768 /**
shilu366312e2019-12-17 09:28:10 -08004769 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4770 * @param subId The subscription to use to check the configuration.
4771 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004772 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004773
Brad Ebinger35c841c2018-10-01 10:40:55 -07004774 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004775 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004776 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004777 final long identity = Binder.clearCallingIdentity();
4778 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004779 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004780 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004781 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004782 } catch (ImsException e) {
4783 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004784 } finally {
4785 Binder.restoreCallingIdentity(identity);
4786 }
4787 }
4788
4789 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004790 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004791 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004792 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004793 final long identity = Binder.clearCallingIdentity();
4794 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004795 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004796 // This setting doesn't require an active ImsService connection, so do not verify. The
4797 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004798 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004799 } catch (ImsException e) {
4800 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004801 } finally {
4802 Binder.restoreCallingIdentity(identity);
4803 }
4804 }
4805
4806 @Override
4807 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4808 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4809 "setVoWiFiNonPersistent");
4810 final long identity = Binder.clearCallingIdentity();
4811 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004812 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004813 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004814 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004815 } catch (ImsException e) {
4816 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004817 } finally {
4818 Binder.restoreCallingIdentity(identity);
4819 }
4820 }
4821
shilu366312e2019-12-17 09:28:10 -08004822 /**
4823 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4824 * @param subId The subscription to use to check the configuration.
4825 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004826 @Override
4827 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004828 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004829 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004830 final long identity = Binder.clearCallingIdentity();
4831 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004832 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004833 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004834 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004835 } catch (ImsException e) {
4836 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004837 } finally {
4838 Binder.restoreCallingIdentity(identity);
4839 }
4840 }
4841
4842 @Override
4843 public void setVoWiFiModeSetting(int subId, int mode) {
4844 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4845 "setVoWiFiModeSetting");
4846 final long identity = Binder.clearCallingIdentity();
4847 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004848 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004849 // This setting doesn't require an active ImsService connection, so do not verify. The
4850 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004851 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004852 } catch (ImsException e) {
4853 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004854 } finally {
4855 Binder.restoreCallingIdentity(identity);
4856 }
4857 }
4858
4859 @Override
4860 public int getVoWiFiRoamingModeSetting(int subId) {
4861 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4862 final long identity = Binder.clearCallingIdentity();
4863 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004864 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004865 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004866 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004867 } catch (ImsException e) {
4868 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004869 } finally {
4870 Binder.restoreCallingIdentity(identity);
4871 }
4872 }
4873
4874 @Override
4875 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4876 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4877 "setVoWiFiRoamingModeSetting");
4878 final long identity = Binder.clearCallingIdentity();
4879 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004880 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004881 // This setting doesn't require an active ImsService connection, so do not verify. The
4882 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004883 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004884 } catch (ImsException e) {
4885 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004886 } finally {
4887 Binder.restoreCallingIdentity(identity);
4888 }
4889 }
4890
4891 @Override
4892 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4893 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4894 "setRttCapabilityEnabled");
4895 final long identity = Binder.clearCallingIdentity();
4896 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004897 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004898 // This setting doesn't require an active ImsService connection, so do not verify. The
4899 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004900 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004901 } catch (ImsException e) {
4902 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004903 } finally {
4904 Binder.restoreCallingIdentity(identity);
4905 }
4906 }
4907
shilu366312e2019-12-17 09:28:10 -08004908 /**
4909 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4910 * @param subId The subscription to use to check the configuration.
4911 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004912 @Override
4913 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004914 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004915 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004916 final long identity = Binder.clearCallingIdentity();
4917 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004918 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004919 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004920 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004921 } catch (ImsException e) {
4922 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004923 } finally {
4924 Binder.restoreCallingIdentity(identity);
4925 }
4926 }
4927
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004928 @Override
4929 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4930 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004931
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004932 final long identity = Binder.clearCallingIdentity();
4933 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004934 if (!isImsAvailableOnDevice()) {
4935 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4936 "IMS not available on device.");
4937 }
4938 int slotId = getSlotIndexOrException(subId);
4939 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004940
4941 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4942 if (controller != null) {
4943 ImsManager imsManager = controller.getImsManager(subId);
4944 if (imsManager != null) {
4945 imsManager.addProvisioningCallbackForSubscription(callback, subId);
4946 } else {
4947 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4948 }
4949 } else {
4950 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4951 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004952 } catch (ImsException e) {
4953 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004954 } finally {
4955 Binder.restoreCallingIdentity(identity);
4956 }
4957 }
4958
4959 @Override
4960 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4961 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004962
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004963 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004964 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4965 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4966 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004967 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004968 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4969 if (controller != null) {
4970 ImsManager imsManager = controller.getImsManager(subId);
4971 if (imsManager != null) {
4972 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
4973 } else {
4974 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4975 + " is inactive, ignoring unregister.");
4976 // If the ImsManager is not valid, just return, since the callback will already
4977 // have been removed internally.
4978 }
4979 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004980 } finally {
4981 Binder.restoreCallingIdentity(identity);
4982 }
4983 }
4984
joonhunshincffb7fc2021-11-28 07:32:01 +00004985 @Override
4986 public void registerFeatureProvisioningChangedCallback(int subId,
4987 IFeatureProvisioningCallback callback) {
4988 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4989 mApp, subId, "registerFeatureProvisioningChangedCallback");
4990
4991 final long identity = Binder.clearCallingIdentity();
4992 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4993 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4994 }
4995
joonhunshin91bc1952022-04-29 08:47:15 +00004996 try {
4997 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4998 if (controller == null) {
4999 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5000 "Device does not support IMS");
5001 }
5002 controller.addFeatureProvisioningChangedCallback(subId, callback);
5003 } finally {
5004 Binder.restoreCallingIdentity(identity);
5005 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005006 }
5007
5008 @Override
5009 public void unregisterFeatureProvisioningChangedCallback(int subId,
5010 IFeatureProvisioningCallback callback) {
5011 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5012 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5013
5014 final long identity = Binder.clearCallingIdentity();
5015 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5016 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5017 }
5018
joonhunshin91bc1952022-04-29 08:47:15 +00005019 try {
5020 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5021 if (controller == null) {
5022 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5023 return;
5024 }
5025 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5026 } finally {
5027 Binder.restoreCallingIdentity(identity);
5028 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005029 }
allenwtsu99c623b2020-01-03 18:24:23 +08005030
5031 private void checkModifyPhoneStatePermission(int subId, String message) {
5032 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5033 message);
5034 }
5035
allenwtsu99c623b2020-01-03 18:24:23 +08005036 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005037 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005038 boolean isProvisioned) {
5039 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5040
5041 final long identity = Binder.clearCallingIdentity();
5042 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005043 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5044 if (controller == null) {
5045 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5046 return;
5047 }
5048 controller.setRcsProvisioningStatusForCapability(
5049 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005050 } finally {
5051 Binder.restoreCallingIdentity(identity);
5052 }
allenwtsu99c623b2020-01-03 18:24:23 +08005053 }
5054
5055
5056 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005057 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5058 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5059 mApp, subId, "getRcsProvisioningStatusForCapability");
5060
allenwtsu99c623b2020-01-03 18:24:23 +08005061 final long identity = Binder.clearCallingIdentity();
5062 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005063 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5064 if (controller == null) {
5065 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5066
5067 // device does not support IMS, this method will return true always.
5068 return true;
5069 }
5070 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005071 } finally {
5072 Binder.restoreCallingIdentity(identity);
5073 }
5074 }
5075
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005076 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005077 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5078 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005079 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005080
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005081 final long identity = Binder.clearCallingIdentity();
5082 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005083 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5084 if (controller == null) {
5085 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5086 return;
5087 }
5088 controller.setImsProvisioningStatusForCapability(
5089 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005090 } finally {
5091 Binder.restoreCallingIdentity(identity);
5092 }
5093 }
5094
5095 @Override
5096 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005097 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5098 mApp, subId, "getProvisioningStatusForCapability");
5099
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005100 final long identity = Binder.clearCallingIdentity();
5101 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005102 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5103 if (controller == null) {
5104 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005105
joonhunshin91bc1952022-04-29 08:47:15 +00005106 // device does not support IMS, this method will return true always.
5107 return true;
5108 }
5109 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005110 } finally {
5111 Binder.restoreCallingIdentity(identity);
5112 }
5113 }
5114
5115 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005116 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5117 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5118 mApp, subId, "isProvisioningRequiredForCapability");
5119
5120 final long identity = Binder.clearCallingIdentity();
5121 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005122 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5123 if (controller == null) {
5124 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5125
5126 // device does not support IMS, this method will return false
5127 return false;
5128 }
5129 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005130 } finally {
5131 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005132 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005133 }
5134
5135 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005136 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5137 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5138 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005139
joonhunshincffb7fc2021-11-28 07:32:01 +00005140 final long identity = Binder.clearCallingIdentity();
5141 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005142 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5143 if (controller == null) {
5144 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5145
5146 // device does not support IMS, this method will return false
5147 return false;
5148 }
5149 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005150 } finally {
5151 Binder.restoreCallingIdentity(identity);
5152 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005153 }
5154
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005155 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005156 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005157 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5158 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5159 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005160 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5161 mApp, subId, "getImsProvisioningInt");
5162
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005163 final long identity = Binder.clearCallingIdentity();
5164 try {
5165 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005166 int slotId = getSlotIndex(subId);
5167 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5168 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5169 + subId + "' for key:" + key);
5170 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5171 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005172
joonhunshin91bc1952022-04-29 08:47:15 +00005173 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5174 if (controller == null) {
5175 loge("getImsProvisioningInt: Device does not support IMS");
5176
5177 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5178 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5179 }
5180 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005181 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5182 return retVal;
5183 }
5184
calvinpanb5a34062021-02-08 19:59:36 +08005185 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005186 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005187 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5188 + subId + "' for key:" + key);
5189 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005190 } finally {
5191 Binder.restoreCallingIdentity(identity);
5192 }
5193 }
5194
5195 @Override
5196 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005197 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5198 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5199 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005200 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5201 mApp, subId, "getImsProvisioningString");
5202
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005203 final long identity = Binder.clearCallingIdentity();
5204 try {
5205 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005206 int slotId = getSlotIndex(subId);
5207 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5208 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5209 + subId + "' for key:" + key);
5210 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5211 }
calvinpanb5a34062021-02-08 19:59:36 +08005212 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005213 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005214 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5215 + subId + "' for key:" + key);
5216 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005217 } finally {
5218 Binder.restoreCallingIdentity(identity);
5219 }
5220 }
5221
5222 @Override
5223 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005224 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5225 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5226 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005227 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5228 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005229
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005230 final long identity = Binder.clearCallingIdentity();
5231 try {
5232 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005233 int slotId = getSlotIndex(subId);
5234 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5235 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5236 + subId + "' for key:" + key);
5237 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5238 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005239
joonhunshin91bc1952022-04-29 08:47:15 +00005240 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5241 if (controller == null) {
5242 loge("setImsProvisioningInt: Device does not support IMS");
5243
5244 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5245 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5246 }
5247 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005248 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5249 return retVal;
5250 }
5251
calvinpanb5a34062021-02-08 19:59:36 +08005252 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5253 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005254 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005255 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005256 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005257 } finally {
5258 Binder.restoreCallingIdentity(identity);
5259 }
5260 }
5261
5262 @Override
5263 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005264 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5265 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5266 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005267 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5268 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005269 final long identity = Binder.clearCallingIdentity();
5270 try {
5271 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005272 int slotId = getSlotIndex(subId);
5273 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5274 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5275 + subId + "' for key:" + key);
5276 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5277 }
calvinpanb5a34062021-02-08 19:59:36 +08005278 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5279 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005280 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005281 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005282 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005283 } finally {
5284 Binder.restoreCallingIdentity(identity);
5285 }
5286 }
5287
Brad Ebinger919631e2021-06-02 17:46:35 -07005288 /**
5289 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5290 * for the given slot ID or no ImsResolver instance has been created.
5291 * @param slotId The slot ID that the IMS service is created for.
5292 * @throws ImsException If there is no ImsService configured for this slot.
5293 */
5294 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5295 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5296 ImsFeature.FEATURE_MMTEL)) {
5297 throw new ImsException("This subscription does not support MMTEL over IMS",
5298 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5299 }
5300 }
5301
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005302 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005303 int slotId = SubscriptionManager.getSlotIndex(subId);
5304 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005305 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5306 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005307 }
5308 return slotId;
5309 }
5310
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005311 private int getSlotIndex(int subId) {
5312 int slotId = SubscriptionManager.getSlotIndex(subId);
5313 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5314 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5315 }
5316 return slotId;
5317 }
5318
Wink Saville36469e72014-06-11 15:17:00 -07005319 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005320 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005321 */
5322 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005323 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5324 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005325 try {
5326 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5327 } catch (SecurityException se) {
5328 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5329 throw new SecurityException("Package " + callingPackage + " does not belong to "
5330 + Binder.getCallingUid());
5331 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005332 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005333 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005334 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005335 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005336 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005337 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005338 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005339 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5340 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005341
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005342 final long identity = Binder.clearCallingIdentity();
5343 try {
5344 final Phone phone = getPhone(subId);
5345 if (phone != null) {
5346 return phone.getServiceState().getDataNetworkType();
5347 } else {
5348 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5349 }
5350 } finally {
5351 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005352 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005353 }
5354
5355 /**
5356 * Returns the data network type
5357 */
5358 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005359 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005360 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005361 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005362 }
5363
5364 /**
5365 * Returns the data network type for a subId
5366 */
5367 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005368 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5369 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005370 String functionName = "getDataNetworkTypeForSubscriber";
5371 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5372 mApp, functionName)) {
5373 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5374 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5375 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5376 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005377 }
5378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005379 final long identity = Binder.clearCallingIdentity();
5380 try {
5381 final Phone phone = getPhone(subId);
5382 if (phone != null) {
5383 return phone.getServiceState().getDataNetworkType();
5384 } else {
5385 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5386 }
5387 } finally {
5388 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005389 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005390 }
5391
5392 /**
Wink Saville36469e72014-06-11 15:17:00 -07005393 * Returns the Voice network type for a subId
5394 */
5395 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005396 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5397 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005398 String functionName = "getVoiceNetworkTypeForSubscriber";
5399 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5400 mApp, functionName)) {
5401 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5402 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5403 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5404 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005405 }
5406
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005407 final long identity = Binder.clearCallingIdentity();
5408 try {
5409 final Phone phone = getPhone(subId);
5410 if (phone != null) {
5411 return phone.getServiceState().getVoiceNetworkType();
5412 } else {
5413 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5414 }
5415 } finally {
5416 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005417 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005418 }
5419
5420 /**
5421 * @return true if a ICC card is present
5422 */
5423 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005424 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005425 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005426 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005427 }
5428
5429 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005430 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005431 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005432 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005433 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005434 final long identity = Binder.clearCallingIdentity();
5435 try {
5436 final Phone phone = PhoneFactory.getPhone(slotIndex);
5437 if (phone != null) {
5438 return phone.getIccCard().hasIccCard();
5439 } else {
5440 return false;
5441 }
5442 } finally {
5443 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005445 }
5446
5447 /**
5448 * Return if the current radio is LTE on CDMA. This
5449 * is a tri-state return value as for a period of time
5450 * the mode may be unknown.
5451 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005452 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005453 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005454 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005455 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005456 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005457 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5458 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5459 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005460 }
5461
Sanket Padawe356d7632015-06-22 14:03:32 -07005462 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005463 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5464 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005465 try {
5466 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5467 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005468 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5469 }
5470
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005471 final long identity = Binder.clearCallingIdentity();
5472 try {
5473 final Phone phone = getPhone(subId);
5474 if (phone == null) {
5475 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5476 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005477 return TelephonyProperties.lte_on_cdma_device()
5478 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005479 }
5480 } finally {
5481 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005482 }
Wink Saville36469e72014-06-11 15:17:00 -07005483 }
5484
Wink Saville36469e72014-06-11 15:17:00 -07005485 /**
5486 * {@hide}
5487 * Returns Default subId, 0 in the case of single standby.
5488 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005489 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005490 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005491 }
5492
Shishir Agrawala9f32182016-04-12 12:00:16 -07005493 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005494 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005495 }
5496
Wink Savilleb564aae2014-10-23 10:18:09 -07005497 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005498 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005499 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005500
Pengquan Menge92a50d2018-09-21 15:54:48 -07005501 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08005502 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08005503 return getSubscriptionManagerService().isActiveSubId(subId,
Jack Yu285100e2022-12-02 22:48:35 -08005504 mApp.getOpPackageName(), mApp.getFeatureId());
5505 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07005506 return mSubscriptionController.isActiveSubId(subId);
5507 }
5508
Ihab Awadf2177b72013-11-25 13:33:23 -08005509 /**
5510 * @see android.telephony.TelephonyManager.WifiCallingChoices
5511 */
5512 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005513 final long identity = Binder.clearCallingIdentity();
5514 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005515 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005516 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5517 getWhenToMakeWifiCallsDefaultPreference());
5518 } finally {
5519 Binder.restoreCallingIdentity(identity);
5520 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005521 }
5522
5523 /**
5524 * @see android.telephony.TelephonyManager.WifiCallingChoices
5525 */
5526 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005527 final long identity = Binder.clearCallingIdentity();
5528 try {
5529 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005530 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005531 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5532 } finally {
5533 Binder.restoreCallingIdentity(identity);
5534 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005535 }
5536
Sailesh Nepald1e68152013-12-12 19:08:02 -08005537 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005538 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005539 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005540 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005541
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005542 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5543 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5544 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005545 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005546 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005547 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005548 }
5549 return PhoneFactory.getPhone(phoneId);
5550 }
5551
Shishir Agrawal566b7612013-10-28 14:41:00 -07005552 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005553 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005554 @NonNull IccLogicalChannelRequest request) {
5555 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5556 /*message=*/ "iccOpenLogicalChannel");
5557
5558 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5559 // Verify that the callingPackage in the request belongs to the calling UID
5560 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5561
5562 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005563 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005564
Rambo Wanga1782702021-11-10 20:15:19 -08005565 private Phone getPhoneFromValidIccLogicalChannelRequest(
5566 @NonNull IccLogicalChannelRequest request, String message) {
5567 Phone phone;
5568 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5569 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5570 mApp, request.subId, message);
5571 phone = getPhoneFromSubId(request.subId);
5572 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5573 enforceModifyPermission();
5574 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5575 } else {
5576 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005577 }
Rambo Wanga1782702021-11-10 20:15:19 -08005578 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005579 }
5580
5581 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005582 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005583 final long identity = Binder.clearCallingIdentity();
5584 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005585 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005586 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005587 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5588 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005589 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5590 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005591 loge("The calling package is not allowed to access ISD-R.");
5592 throw new SecurityException(
5593 "The calling package is not allowed to access ISD-R.");
5594 }
Derek Tan740e1672017-06-27 14:56:27 -07005595 }
Derek Tan740e1672017-06-27 14:56:27 -07005596
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005597 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005598 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5599 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005600 return response;
5601 } finally {
5602 Binder.restoreCallingIdentity(identity);
5603 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005604 }
5605
5606 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005607 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5608 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5609 /*message=*/"iccCloseLogicalChannel");
5610
5611 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5612
5613 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005614 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005615
Rambo Wanga1782702021-11-10 20:15:19 -08005616 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5617 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005618 // before this feature is enabled, this API should only return false if
5619 // the operation fails instead of throwing runtime exception for
5620 // backward-compatibility.
5621 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5622 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005623 final long identity = Binder.clearCallingIdentity();
5624 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005625 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005626 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005627 }
Chen Xue9d737e2022-01-01 23:41:31 -08005628 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005629 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005630 Boolean success = false;
5631 if (result instanceof RuntimeException) {
5632 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005633 if (shouldThrowExceptionOnFailure) {
5634 throw (RuntimeException) result;
5635 } else {
5636 return false;
5637 }
Chen Xue9d737e2022-01-01 23:41:31 -08005638 } else if (result instanceof Boolean) {
5639 success = (Boolean) result;
5640 } else {
5641 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5642 }
Rambo Wanga1782702021-11-10 20:15:19 -08005643 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005644 return success;
5645 } finally {
5646 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005647 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005648 }
5649
5650 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005651 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005652 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005653 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5654 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005655 if (DBG) {
5656 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5657 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5658 + p3 + " data=" + data);
5659 }
5660 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5661 command, p1, p2, p3, data);
5662 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005663
Jordan Liu4c733742019-02-28 12:03:40 -08005664 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005665 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005666 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005667 enforceModifyPermission();
5668 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005669 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005670 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5671 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005672 }
5673 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005674 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5675 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005676 }
5677
5678 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5679 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005680 final long identity = Binder.clearCallingIdentity();
5681 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005682 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005683 return "";
5684 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005685
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005686 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005687 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5688 null /* workSource */);
5689 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005690
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005691 // Append the returned status code to the end of the response payload.
5692 String s = Integer.toHexString(
5693 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5694 if (response.payload != null) {
5695 s = IccUtils.bytesToHexString(response.payload) + s;
5696 }
5697 return s;
5698 } finally {
5699 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005700 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005701 }
Jake Hambye994d462014-02-03 13:10:13 -08005702
Evan Charltonc66da362014-05-16 14:06:40 -07005703 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005704 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5705 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005706 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5707 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005709 if (DBG) {
5710 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5711 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5712 }
5713 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5714 cla, command, p1, p2, p3, data);
5715 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005716
Jordan Liu4c733742019-02-28 12:03:40 -08005717 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005718 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005719 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005720 enforceModifyPermission();
5721 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5722 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005723 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005724 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5725 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005726 }
5727
5728 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005729 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5730 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005731 }
5732
5733 // open APDU basic channel assuming the caller has sufficient permissions
5734 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5735 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005736 final long identity = Binder.clearCallingIdentity();
5737 try {
5738 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5739 && TextUtils.equals(ISDR_AID, data)) {
5740 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005741 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5742 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005743 if (bestComponent == null
5744 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5745 loge("The calling package is not allowed to select ISD-R.");
5746 throw new SecurityException(
5747 "The calling package is not allowed to select ISD-R.");
5748 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005749 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005750
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005751 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005752 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5753 null /* workSource */);
5754 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005755
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005756 // Append the returned status code to the end of the response payload.
5757 String s = Integer.toHexString(
5758 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5759 if (response.payload != null) {
5760 s = IccUtils.bytesToHexString(response.payload) + s;
5761 }
5762 return s;
5763 } finally {
5764 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005765 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005766 }
5767
5768 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005769 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005770 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5772 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005773
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774 final long identity = Binder.clearCallingIdentity();
5775 try {
5776 if (DBG) {
5777 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5778 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5779 }
5780
5781 IccIoResult response =
5782 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5783 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5784 subId);
5785
5786 if (DBG) {
5787 log("Exchange SIM_IO [R]" + response);
5788 }
5789
5790 byte[] result = null;
5791 int length = 2;
5792 if (response.payload != null) {
5793 length = 2 + response.payload.length;
5794 result = new byte[length];
5795 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5796 } else {
5797 result = new byte[length];
5798 }
5799
5800 result[length - 1] = (byte) response.sw2;
5801 result[length - 2] = (byte) response.sw1;
5802 return result;
5803 } finally {
5804 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005805 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005806 }
5807
Nathan Haroldb3014052017-01-25 15:57:32 -08005808 /**
5809 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5810 * on a particular subscription
5811 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005812 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5813 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005814 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005815 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005816 return null;
5817 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005818
5819 final long identity = Binder.clearCallingIdentity();
5820 try {
5821 if (appType != TelephonyManager.APPTYPE_USIM
5822 && appType != TelephonyManager.APPTYPE_SIM) {
5823 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5824 return null;
5825 }
5826 Object response = sendRequest(
5827 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5828 if (response instanceof String[]) {
5829 return (String[]) response;
5830 }
yincheng zhao2737e882019-09-06 17:06:54 -07005831 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005832 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005833 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005834 } finally {
5835 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005836 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005837 }
5838
yincheng zhao2737e882019-09-06 17:06:54 -07005839 /**
5840 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5841 * subscription.
5842 *
5843 * @param subId the id of the subscription.
5844 * @param appType the uicc app type, must be USIM or SIM.
5845 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5846 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005847 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005848 * @return number of fplmns that is successfully written to the SIM.
5849 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005850 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5851 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5853 mApp, subId, "setForbiddenPlmns");
5854
yincheng zhao2737e882019-09-06 17:06:54 -07005855 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5856 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5857 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5858 }
5859 if (fplmns == null) {
5860 throw new IllegalArgumentException("Fplmn List provided is null");
5861 }
5862 for (String fplmn : fplmns) {
5863 if (!CellIdentity.isValidPlmn(fplmn)) {
5864 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5865 }
5866 }
5867 final long identity = Binder.clearCallingIdentity();
5868 try {
5869 Object response = sendRequest(
5870 CMD_SET_FORBIDDEN_PLMNS,
5871 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5872 subId);
5873 return (int) response;
5874 } finally {
5875 Binder.restoreCallingIdentity(identity);
5876 }
5877 }
5878
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005879 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005880 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005881 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5882 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005883
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005884 final long identity = Binder.clearCallingIdentity();
5885 try {
5886 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5887 if (response.payload == null) {
5888 return "";
5889 }
Evan Charltonc66da362014-05-16 14:06:40 -07005890
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005891 // Append the returned status code to the end of the response payload.
5892 String s = Integer.toHexString(
5893 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5894 s = IccUtils.bytesToHexString(response.payload) + s;
5895 return s;
5896 } finally {
5897 Binder.restoreCallingIdentity(identity);
5898 }
Evan Charltonc66da362014-05-16 14:06:40 -07005899 }
5900
Jake Hambye994d462014-02-03 13:10:13 -08005901 /**
5902 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5903 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5904 *
5905 * @param itemID the ID of the item to read
5906 * @return the NV item as a String, or null on error.
5907 */
5908 @Override
5909 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005910 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005911 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5912 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005913
5914 final long identity = Binder.clearCallingIdentity();
5915 try {
5916 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005917 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005918 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5919 return value;
5920 } finally {
5921 Binder.restoreCallingIdentity(identity);
5922 }
Jake Hambye994d462014-02-03 13:10:13 -08005923 }
5924
5925 /**
5926 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5927 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5928 *
5929 * @param itemID the ID of the item to read
5930 * @param itemValue the value to write, as a String
5931 * @return true on success; false on any failure
5932 */
5933 @Override
5934 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005935 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5937 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005938
5939 final long identity = Binder.clearCallingIdentity();
5940 try {
5941 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5942 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005943 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005944 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5945 return success;
5946 } finally {
5947 Binder.restoreCallingIdentity(identity);
5948 }
Jake Hambye994d462014-02-03 13:10:13 -08005949 }
5950
5951 /**
5952 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5953 * Used for device configuration by some CDMA operators.
5954 *
5955 * @param preferredRoamingList byte array containing the new PRL
5956 * @return true on success; false on any failure
5957 */
5958 @Override
5959 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005960 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5961 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005962
5963 final long identity = Binder.clearCallingIdentity();
5964 try {
5965 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5966 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5967 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5968 return success;
5969 } finally {
5970 Binder.restoreCallingIdentity(identity);
5971 }
Jake Hambye994d462014-02-03 13:10:13 -08005972 }
5973
5974 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005975 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005976 * Used for device configuration by some CDMA operators.
5977 *
chen xu6dac5ab2018-10-26 17:39:23 -07005978 * @param slotIndex - device slot.
5979 *
Jake Hambye994d462014-02-03 13:10:13 -08005980 * @return true on success; false on any failure
5981 */
5982 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005983 public boolean resetModemConfig(int slotIndex) {
5984 Phone phone = PhoneFactory.getPhone(slotIndex);
5985 if (phone != null) {
5986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5987 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988
chen xu6dac5ab2018-10-26 17:39:23 -07005989 final long identity = Binder.clearCallingIdentity();
5990 try {
5991 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5992 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5993 return success;
5994 } finally {
5995 Binder.restoreCallingIdentity(identity);
5996 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005997 }
chen xu6dac5ab2018-10-26 17:39:23 -07005998 return false;
5999 }
6000
6001 /**
6002 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6003 *
6004 * @param slotIndex - device slot.
6005 *
6006 * @return true on success; false on any failure
6007 */
6008 @Override
6009 public boolean rebootModem(int slotIndex) {
6010 Phone phone = PhoneFactory.getPhone(slotIndex);
6011 if (phone != null) {
6012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6013 mApp, phone.getSubId(), "rebootModem");
6014
6015 final long identity = Binder.clearCallingIdentity();
6016 try {
6017 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6018 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6019 return success;
6020 } finally {
6021 Binder.restoreCallingIdentity(identity);
6022 }
6023 }
6024 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006025 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006026
Brad Ebinger51f743a2017-01-23 13:50:20 -08006027 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006028 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6029 * {@link #disableIms(int)}.
6030 * @param slotIndex device slot.
6031 */
6032 public void resetIms(int slotIndex) {
6033 enforceModifyPermission();
6034
6035 final long identity = Binder.clearCallingIdentity();
6036 try {
6037 if (mImsResolver == null) {
6038 // may happen if the does not support IMS.
6039 return;
6040 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006041 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006042 } finally {
6043 Binder.restoreCallingIdentity(identity);
6044 }
6045 }
6046
6047 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006048 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6049 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006050 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006051 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006052 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006053
6054 final long identity = Binder.clearCallingIdentity();
6055 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006056 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006057 // may happen if the device does not support IMS.
6058 return;
6059 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006060 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006061 } finally {
6062 Binder.restoreCallingIdentity(identity);
6063 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006064 }
6065
6066 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006067 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6068 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006069 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006070 public void disableIms(int slotId) {
6071 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006072
6073 final long identity = Binder.clearCallingIdentity();
6074 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006075 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006076 // may happen if the device does not support IMS.
6077 return;
6078 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006079 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006080 } finally {
6081 Binder.restoreCallingIdentity(identity);
6082 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006083 }
6084
6085 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006086 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6087 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006088 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006089 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006090 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006091 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006092
6093 final long identity = Binder.clearCallingIdentity();
6094 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006095 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006096 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6097 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006098 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006099 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006100 } finally {
6101 Binder.restoreCallingIdentity(identity);
6102 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006103 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006104 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006105 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6106 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006107 @Override
6108 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006109 enforceModifyPermission();
6110
6111 final long identity = Binder.clearCallingIdentity();
6112 try {
6113 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006114 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006115 } finally {
6116 Binder.restoreCallingIdentity(identity);
6117 }
6118 }
6119
6120 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006121 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006122 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006123 */
6124 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6125 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006126
6127 final long identity = Binder.clearCallingIdentity();
6128 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006129 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006130 // may happen if the device does not support IMS.
6131 return null;
6132 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006133 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006134 } finally {
6135 Binder.restoreCallingIdentity(identity);
6136 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006137 }
6138
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006139 /**
6140 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006141 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006142 */
6143 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6144 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006145
6146 final long identity = Binder.clearCallingIdentity();
6147 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006148 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006149 // may happen if the device does not support IMS.
6150 return null;
6151 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006152 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006153 } finally {
6154 Binder.restoreCallingIdentity(identity);
6155 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006156 }
6157
Brad Ebinger884c07b2018-02-15 16:17:40 -08006158 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006159 * Sets the ImsService Package Name that Telephony will bind to.
6160 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006161 * @param slotIndex the slot ID that the ImsService should bind for.
6162 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006163 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006164 * @param featureTypes An integer array of feature types associated with a packageName.
6165 * @param packageName The name of the package that the current configuration will be replaced
6166 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006167 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006168 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006169 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6170 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006171 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006172 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006173 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006174
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006175 final long identity = Binder.clearCallingIdentity();
6176 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006177 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006178 // may happen if the device does not support IMS.
6179 return false;
6180 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006181 Map<Integer, String> featureConfig = new HashMap<>();
6182 for (int featureType : featureTypes) {
6183 featureConfig.put(featureType, packageName);
6184 }
6185 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6186 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006187 } finally {
6188 Binder.restoreCallingIdentity(identity);
6189 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006190 }
6191
6192 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006193 * Clears any carrier ImsService overrides for the slot index specified that were previously
6194 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6195 *
6196 * This should only be used for testing.
6197 *
6198 * @param slotIndex the slot ID that the ImsService should bind for.
6199 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6200 */
6201 @Override
6202 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006203 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6204 "clearCarrierImsServiceOverride");
6205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006206 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006207
6208 final long identity = Binder.clearCallingIdentity();
6209 try {
6210 if (mImsResolver == null) {
6211 // may happen if the device does not support IMS.
6212 return false;
6213 }
6214 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6215 } finally {
6216 Binder.restoreCallingIdentity(identity);
6217 }
6218 }
6219
6220 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006221 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006222 *
6223 * @param slotId The slot that the ImsService is associated with.
6224 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6225 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006226 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006227 * @return the package name of the ImsService configuration.
6228 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006229 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6230 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006231 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006232 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6233 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006234
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006235 final long identity = Binder.clearCallingIdentity();
6236 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006237 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006238 // may happen if the device does not support IMS.
6239 return "";
6240 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006241 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006242 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6243 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006244 } finally {
6245 Binder.restoreCallingIdentity(identity);
6246 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006247 }
6248
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006249 /**
6250 * Get the MmTelFeature state associated with the requested subscription id.
6251 * @param subId The subscription that the MmTelFeature is associated with.
6252 * @param callback A callback with an integer containing the
6253 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6254 */
6255 @Override
6256 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6257 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006258 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6259 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6260 "IMS not available on device.");
6261 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006262 final long token = Binder.clearCallingIdentity();
6263 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006264 int slotId = getSlotIndex(subId);
6265 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6266 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6267 + subId + "'");
6268 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6269 }
6270 verifyImsMmTelConfiguredOrThrow(slotId);
6271 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6272 try {
6273 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6274 } catch (RemoteException e) {
6275 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6276 + "Ignore");
6277 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006278 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006279 } catch (ImsException e) {
6280 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006281 } finally {
6282 Binder.restoreCallingIdentity(token);
6283 }
6284 }
6285
Daniel Brightbb5840b2021-01-12 15:48:18 -08006286 /**
6287 * Sets the ims registration state on all valid {@link Phone}s.
6288 */
6289 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006290 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006291
6292 final long identity = Binder.clearCallingIdentity();
6293 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006294 // NOTE: Before S, this method only set the default phone.
6295 for (final Phone phone : PhoneFactory.getPhones()) {
6296 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6297 phone.setImsRegistrationState(registered);
6298 }
6299 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006300 } finally {
6301 Binder.restoreCallingIdentity(identity);
6302 }
Wink Saville36469e72014-06-11 15:17:00 -07006303 }
6304
6305 /**
Stuart Scott54788802015-03-30 13:18:01 -07006306 * Set the network selection mode to automatic.
6307 *
6308 */
6309 @Override
6310 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006311 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6312 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006313
6314 final long identity = Binder.clearCallingIdentity();
6315 try {
shilufc958392020-01-20 11:36:01 -08006316 if (!isActiveSubscription(subId)) {
6317 return;
6318 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006319 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006320 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6321 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006322 } finally {
6323 Binder.restoreCallingIdentity(identity);
6324 }
Stuart Scott54788802015-03-30 13:18:01 -07006325 }
6326
Jack Yud10cdd42020-09-28 20:28:01 -07006327 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006328 * Ask the radio to connect to the input network and change selection mode to manual.
6329 *
6330 * @param subId the id of the subscription.
6331 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6332 * the operator to attach to.
6333 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6334 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6335 * normal network selection next time.
6336 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006337 */
6338 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006339 public boolean setNetworkSelectionModeManual(
6340 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006341 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6342 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006343
Jack Yu285100e2022-12-02 22:48:35 -08006344 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006345 if (!isActiveSubscription(subId)) {
6346 return false;
6347 }
6348
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006349 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006350 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006351 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006352 if (DBG) {
6353 log("setNetworkSelectionModeManual: subId: " + subId
6354 + " operator: " + operatorInfo);
6355 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006356 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6357 } finally {
6358 Binder.restoreCallingIdentity(identity);
6359 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006360 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006361 /**
shilu84f6e8b2019-12-19 13:58:01 -08006362 * Get the manual network selection
6363 *
6364 * @param subId the id of the subscription.
6365 *
6366 * @return the previously saved user selected PLMN
6367 */
6368 @Override
6369 public String getManualNetworkSelectionPlmn(int subId) {
6370 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006371 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6372 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006373
6374 final long identity = Binder.clearCallingIdentity();
6375 try {
6376 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006377 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006378 }
6379
6380 final Phone phone = getPhone(subId);
6381 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006382 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006383 }
6384 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6385 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006386 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006387 } finally {
6388 Binder.restoreCallingIdentity(identity);
6389 }
6390 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006391
6392 /**
6393 * Scans for available networks.
6394 */
6395 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006396 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6397 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6399 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006400 LocationAccessPolicy.LocationPermissionResult locationResult =
6401 LocationAccessPolicy.checkLocationPermission(mApp,
6402 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6403 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006404 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006405 .setCallingPid(Binder.getCallingPid())
6406 .setCallingUid(Binder.getCallingUid())
6407 .setMethod("getCellNetworkScanResults")
6408 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006409 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6410 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006411 .build());
6412 switch (locationResult) {
6413 case DENIED_HARD:
6414 throw new SecurityException("Not allowed to access scan results -- location");
6415 case DENIED_SOFT:
6416 return null;
6417 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006418
Pengquan Menga1bb6272018-09-06 09:59:22 -07006419 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006420 try {
6421 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006422 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006423 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006424 } finally {
6425 Binder.restoreCallingIdentity(identity);
6426 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006427 }
6428
6429 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006430 * Get the call forwarding info, given the call forwarding reason.
6431 */
6432 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006433 public void getCallForwarding(int subId, int callForwardingReason,
6434 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006435 enforceReadPrivilegedPermission("getCallForwarding");
6436 long identity = Binder.clearCallingIdentity();
6437 try {
6438 if (DBG) {
6439 log("getCallForwarding: subId " + subId
6440 + " callForwardingReason" + callForwardingReason);
6441 }
Hall Liu27d24262020-09-18 19:04:59 -07006442
6443 Phone phone = getPhone(subId);
6444 if (phone == null) {
6445 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006446 callback.onError(
6447 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006448 } catch (RemoteException e) {
6449 // ignore
6450 }
6451 return;
6452 }
6453
6454 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6455 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6456 @Override
6457 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6458 try {
6459 callback.onCallForwardingInfoAvailable(info);
6460 } catch (RemoteException e) {
6461 // ignore
6462 }
6463 }
6464
6465 @Override
6466 public void onError(int error) {
6467 try {
6468 callback.onError(error);
6469 } catch (RemoteException e) {
6470 // ignore
6471 }
6472 }
6473 });
6474 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006475 } finally {
6476 Binder.restoreCallingIdentity(identity);
6477 }
6478 }
6479
6480 /**
6481 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6482 * reason, the number to forward, and the timeout before the forwarding is attempted.
6483 */
6484 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006485 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6486 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006487 enforceModifyPermission();
6488 long identity = Binder.clearCallingIdentity();
6489 try {
6490 if (DBG) {
6491 log("setCallForwarding: subId " + subId
6492 + " callForwardingInfo" + callForwardingInfo);
6493 }
Hall Liu27d24262020-09-18 19:04:59 -07006494
6495 Phone phone = getPhone(subId);
6496 if (phone == null) {
6497 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006498 callback.accept(
6499 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006500 } catch (RemoteException e) {
6501 // ignore
6502 }
6503 return;
6504 }
6505
6506 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6507 FunctionalUtils.ignoreRemoteException(callback::accept));
6508
6509 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006510 } finally {
6511 Binder.restoreCallingIdentity(identity);
6512 }
6513 }
6514
6515 /**
Hall Liu27d24262020-09-18 19:04:59 -07006516 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006517 */
6518 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006519 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006520 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006521 long identity = Binder.clearCallingIdentity();
6522 try {
Hall Liu27d24262020-09-18 19:04:59 -07006523 Phone phone = getPhone(subId);
6524 if (phone == null) {
6525 try {
6526 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6527 } catch (RemoteException e) {
6528 // ignore
6529 }
6530 return;
6531 }
SongFerngWang0e767992021-03-31 22:08:45 +08006532 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6533 PersistableBundle c = configManager.getConfigForSubId(subId);
6534 boolean requireUssd = c.getBoolean(
6535 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006536
Shuo Qian4a594052020-01-23 11:59:30 -08006537 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006538 if (requireUssd) {
6539 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6540 getSubscriptionCarrierId(subId));
6541 String newUssdCommand = "";
6542 try {
6543 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006544 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006545 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6546 } catch (NullPointerException e) {
6547 loge("Failed to generate USSD number" + e);
6548 }
6549 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6550 mMainThreadHandler, callback, carrierXmlParser,
6551 CarrierXmlParser.SsEntry.SSAction.QUERY);
6552 final String ussdCommand = newUssdCommand;
6553 Executors.newSingleThreadExecutor().execute(() -> {
6554 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6555 });
6556 } else {
6557 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6558 callback::accept);
6559 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6560 }
Shuo Qian4a594052020-01-23 11:59:30 -08006561 } finally {
6562 Binder.restoreCallingIdentity(identity);
6563 }
6564 }
6565
6566 /**
Hall Liu27d24262020-09-18 19:04:59 -07006567 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006568 */
6569 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006570 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006571 enforceModifyPermission();
6572 long identity = Binder.clearCallingIdentity();
6573 try {
Hall Liu27d24262020-09-18 19:04:59 -07006574 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6575
6576 Phone phone = getPhone(subId);
6577 if (phone == null) {
6578 try {
6579 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6580 } catch (RemoteException e) {
6581 // ignore
6582 }
6583 return;
6584 }
6585
SongFerngWang0e767992021-03-31 22:08:45 +08006586 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6587 PersistableBundle c = configManager.getConfigForSubId(subId);
6588 boolean requireUssd = c.getBoolean(
6589 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006590
SongFerngWang0e767992021-03-31 22:08:45 +08006591 if (DBG) log("getCallWaitingStatus: subId " + subId);
6592 if (requireUssd) {
6593 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6594 getSubscriptionCarrierId(subId));
6595 CarrierXmlParser.SsEntry.SSAction ssAction =
6596 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6597 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6598 String newUssdCommand = "";
6599 try {
6600 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006601 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006602 .makeCommand(ssAction, null);
6603 } catch (NullPointerException e) {
6604 loge("Failed to generate USSD number" + e);
6605 }
6606 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6607 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6608 final String ussdCommand = newUssdCommand;
6609 Executors.newSingleThreadExecutor().execute(() -> {
6610 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6611 });
6612 } else {
6613 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6614 FunctionalUtils.ignoreRemoteException(callback::accept));
6615
6616 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6617 }
Shuo Qian4a594052020-01-23 11:59:30 -08006618 } finally {
6619 Binder.restoreCallingIdentity(identity);
6620 }
6621 }
6622
6623 /**
yinxub1bed742017-04-17 11:45:04 -07006624 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006625 *
yinxub1bed742017-04-17 11:45:04 -07006626 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006627 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6628 * location related information which will be sent if the caller already possess
6629 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006630 * @param request contains the radio access networks with bands/channels to scan
6631 * @param messenger callback messenger for scan results or errors
6632 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006633 * @return the id of the requested scan which can be used to stop the scan.
6634 */
6635 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006636 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6637 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006638 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006639 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6640 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006641 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006642 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6643 if (!renounceFineLocationAccess) {
6644 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006645 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6646 .setCallingPackage(callingPackage)
6647 .setCallingFeatureId(callingFeatureId)
6648 .setCallingPid(Binder.getCallingPid())
6649 .setCallingUid(Binder.getCallingUid())
6650 .setMethod("requestNetworkScan")
6651 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6652 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6653 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6654 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006655 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006656 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006657 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6658 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006659 if (e != null) {
6660 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6661 throw e;
6662 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006663 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006664 return TelephonyScanManager.INVALID_SCAN_ID;
6665 }
6666 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006667 }
Hall Liu912dfd32019-04-25 14:02:26 -07006668 int callingUid = Binder.getCallingUid();
6669 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006670 final long identity = Binder.clearCallingIdentity();
6671 try {
6672 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07006673 renounceFineLocationAccess, request, messenger, binder,
6674 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006675 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006676 } finally {
6677 Binder.restoreCallingIdentity(identity);
6678 }
yinxu504e1392017-04-12 16:03:22 -07006679 }
6680
Hall Liub2ac8ef2019-02-28 15:56:23 -08006681 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006682 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006683 boolean hasCarrierPriv;
6684 final long identity = Binder.clearCallingIdentity();
6685 try {
6686 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6687 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6688 } finally {
6689 Binder.restoreCallingIdentity(identity);
6690 }
Hall Liu558027f2019-05-15 19:14:05 -07006691 boolean hasNetworkScanPermission =
6692 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006693 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07006694
6695 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6696 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6697 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006698 }
6699
6700 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6701 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006702 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6703 return new SecurityException("Specific channels must not be"
6704 + " scanned without location access.");
6705 }
6706 }
6707 }
6708
Hall Liub2ac8ef2019-02-28 15:56:23 -08006709 return null;
6710 }
6711
yinxu504e1392017-04-12 16:03:22 -07006712 /**
6713 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006714 *
6715 * @param subId id of the subscription
6716 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006717 */
6718 @Override
6719 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006720 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6721 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006722
Hall Liu912dfd32019-04-25 14:02:26 -07006723 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006724 final long identity = Binder.clearCallingIdentity();
6725 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006726 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006727 } finally {
6728 Binder.restoreCallingIdentity(identity);
6729 }
yinxu504e1392017-04-12 16:03:22 -07006730 }
6731
6732 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006733 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006734 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006735 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006736 */
6737 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006738 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006739 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006740 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006741 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006742
6743 final long identity = Binder.clearCallingIdentity();
6744 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006745 if (DBG) log("getAllowedNetworkTypesBitmask");
6746 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6747 int networkTypesBitmask = (result != null ? result[0] : -1);
6748 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6749 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006750 } finally {
6751 Binder.restoreCallingIdentity(identity);
6752 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006753 }
6754
6755 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006756 * Get the allowed network types for certain reason.
6757 *
6758 * @param subId the id of the subscription.
6759 * @param reason the reason the allowed network type change is taking place
6760 * @return the allowed network types.
6761 */
6762 @Override
6763 public long getAllowedNetworkTypesForReason(int subId,
6764 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006765 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006766 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006767 final long identity = Binder.clearCallingIdentity();
6768 try {
Jack Yu7247ac82023-03-02 23:52:10 -08006769 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006770 } finally {
6771 Binder.restoreCallingIdentity(identity);
6772 }
6773 }
6774
6775 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006776 * Enable/Disable E-UTRA-NR Dual Connectivity
6777 * @param subId subscription id of the sim card
6778 * @param nrDualConnectivityState expected NR dual connectivity state
6779 * This can be passed following states
6780 * <ol>
6781 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6782 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6783 * <li>Disable NR dual connectivity and force secondary cell to be released
6784 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6785 * </ol>
6786 * @return operation result.
6787 */
6788 @Override
6789 public int setNrDualConnectivityState(int subId,
6790 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6791 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6792 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006793 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006794 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6795 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6796 }
6797
Sooraj Sasindran37444802020-08-11 10:40:43 -07006798 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6799 final long identity = Binder.clearCallingIdentity();
6800 try {
6801 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6802 nrDualConnectivityState, subId,
6803 workSource);
6804 if (DBG) log("enableNRDualConnectivity result: " + result);
6805 return result;
6806 } finally {
6807 Binder.restoreCallingIdentity(identity);
6808 }
6809 }
6810
6811 /**
6812 * Is E-UTRA-NR Dual Connectivity enabled
6813 * @return true if dual connectivity is enabled else false
6814 */
6815 @Override
6816 public boolean isNrDualConnectivityEnabled(int subId) {
6817 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006818 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006819 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006820 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006821 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6822 return false;
6823 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006824 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6825 final long identity = Binder.clearCallingIdentity();
6826 try {
6827 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6828 null, subId, workSource);
6829 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6830 return isEnabled;
6831 } finally {
6832 Binder.restoreCallingIdentity(identity);
6833 }
6834 }
6835
6836 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006837 * Set the allowed network types of the device and
6838 * provide the reason triggering the allowed network change.
6839 *
6840 * @param subId the id of the subscription.
6841 * @param reason the reason the allowed network type change is taking place
6842 * @param allowedNetworkTypes the allowed network types.
6843 * @return true on success; false on any failure.
6844 */
6845 @Override
6846 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006847 @TelephonyManager.AllowedNetworkTypesReason int reason,
6848 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006849 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6850 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006851 // If the caller only has carrier privileges, then they should not be able to override
6852 // any network types which were set for security reasons.
6853 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6854 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006855 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006856 throw new SecurityException(
6857 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006858 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006859 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006860 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006861 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08006862 return false;
6863 }
6864 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6865 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006866 return false;
6867 }
6868
Jack Yu5b494332023-01-23 18:18:04 +00006869 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
6870 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006871
Jack Yue37dd262022-12-16 11:53:37 -08006872 Phone phone = getPhone(subId);
6873 if (phone == null) {
6874 return false;
6875 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006876
Jack Yue37dd262022-12-16 11:53:37 -08006877 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006878 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006879 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006880 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006881
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006882 final long identity = Binder.clearCallingIdentity();
6883 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006884 Boolean success = (Boolean) sendRequest(
6885 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6886 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6887
6888 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6889 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006890 } finally {
6891 Binder.restoreCallingIdentity(identity);
6892 }
6893 }
6894
6895 /**
Miaoa84611c2019-03-15 09:21:10 +08006896 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006897 *
Miaoa84611c2019-03-15 09:21:10 +08006898 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006899 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006900 * @hide
6901 */
6902 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006903 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006904 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006905 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006906 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006907 try {
Miaoa84611c2019-03-15 09:21:10 +08006908 if (phone != null) {
6909 return phone.hasMatchedTetherApnSetting();
6910 } else {
6911 return false;
6912 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006913 } finally {
6914 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006915 }
Junda Liu475951f2014-11-07 16:45:03 -08006916 }
6917
6918 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006919 * Get the user enabled state of Mobile Data.
6920 *
6921 * TODO: remove and use isUserDataEnabled.
6922 * This can't be removed now because some vendor codes
6923 * calls through ITelephony directly while they should
6924 * use TelephonyManager.
6925 *
6926 * @return true on enabled
6927 */
6928 @Override
6929 public boolean getDataEnabled(int subId) {
6930 return isUserDataEnabled(subId);
6931 }
6932
6933 /**
6934 * Get whether mobile data is enabled per user setting.
6935 *
6936 * There are other factors deciding whether mobile data is actually enabled, but they are
6937 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006938 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006939 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6940 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006941 *
6942 * @return {@code true} if data is enabled else {@code false}
6943 */
6944 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006945 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006946 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006947 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006948 try {
6949 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6950 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006951 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006952 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6953 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006954 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006956 mApp, subId, functionName);
6957
Robert Greenwalt646120a2014-05-23 11:54:03 -07006958 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006959
6960 final long identity = Binder.clearCallingIdentity();
6961 try {
Jack Yu285100e2022-12-02 22:48:35 -08006962 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006963 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6964 Phone phone = PhoneFactory.getPhone(phoneId);
6965 if (phone != null) {
6966 boolean retVal = phone.isUserDataEnabled();
6967 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6968 return retVal;
6969 } else {
6970 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6971 return false;
6972 }
6973 } finally {
6974 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006975 }
6976 }
6977
6978 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006979 * Checks if the device is capable of mobile data by considering whether whether the
6980 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6981 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006982 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006983 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006984 */
6985 @Override
6986 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006987 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006988 try {
6989 try {
6990 mApp.enforceCallingOrSelfPermission(
6991 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006992 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006993 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006994 try {
6995 mApp.enforceCallingOrSelfPermission(
6996 android.Manifest.permission.READ_PHONE_STATE,
6997 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006998 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006999 mApp.enforceCallingOrSelfPermission(
7000 permission.READ_BASIC_PHONE_STATE, functionName);
7001 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007002 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007003 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007004 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007005 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007006
7007 final long identity = Binder.clearCallingIdentity();
7008 try {
Jack Yu285100e2022-12-02 22:48:35 -08007009 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007010 Phone phone = PhoneFactory.getPhone(phoneId);
7011 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007012 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007013 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007014 return retVal;
7015 } else {
7016 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7017 return false;
7018 }
7019 } finally {
7020 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007021 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007022 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007023
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007024 /**
7025 * Check if data is enabled for a specific reason
7026 * @param subId Subscription index
7027 * @param reason the reason the data enable change is taking place
7028 * @return {@code true} if the overall data is enabled; {@code false} if not.
7029 */
7030 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007031 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007032 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007033 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007034 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007035 try {
7036 mApp.enforceCallingOrSelfPermission(
7037 android.Manifest.permission.ACCESS_NETWORK_STATE,
7038 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007039 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007040 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7041 functionName);
7042 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007043 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007044 try {
7045 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007046 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007047 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007049 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007050 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007051 }
7052
7053
7054 final long identity = Binder.clearCallingIdentity();
7055 try {
Jack Yu285100e2022-12-02 22:48:35 -08007056 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007057 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007058 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007059 + " reason=" + reason);
7060 }
7061 Phone phone = PhoneFactory.getPhone(phoneId);
7062 if (phone != null) {
7063 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007064 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007065 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007066 return retVal;
7067 } else {
7068 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007069 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007070 + subId + " retVal=false");
7071 }
7072 return false;
7073 }
7074 } finally {
7075 Binder.restoreCallingIdentity(identity);
7076 }
7077 }
7078
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007079 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007080 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007081 // No permission needed; this only lets the caller inspect their own status.
7082 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007083 }
Junda Liu29340342014-07-10 15:23:27 -07007084
7085 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007086 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007087 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007088 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7089 }
7090
7091 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7092 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007093 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007094 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007095 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7096 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007097 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7098 if (cpt == null) {
7099 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007100 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7101 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007102 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007103 }
7104
7105 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007106 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007107 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007108 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007109 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007110 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007111 Phone phone = getPhone(subId);
7112 if (phone == null) {
7113 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7114 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7115 }
7116 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7117 if (cpt == null) {
7118 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007119 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7120 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007121 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007122 }
7123
7124 @Override
7125 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007126 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007127 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7128 }
7129
7130 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007131 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007132 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007133 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007134 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007135 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7136 Phone phone = PhoneFactory.getPhone(phoneId);
7137 if (phone == null) {
7138 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007139 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007140 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7141 if (cpt == null) {
7142 continue;
7143 }
7144 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007145 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7146 break;
7147 }
7148 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007149 return result;
Junda Liu29340342014-07-10 15:23:27 -07007150 }
Derek Tan89e89d42014-07-08 17:00:10 -07007151
7152 @Override
Junda Liue64de782015-04-16 17:19:16 -07007153 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007154 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007155 Phone phone = PhoneFactory.getPhone(phoneId);
7156 if (phone == null) {
7157 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007158 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007159 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7160 if (cpt == null) {
7161 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007162 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007163 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007164 }
7165
Amith Yamasani6e118872016-02-19 12:53:51 -08007166 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007167 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007168 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007169 Phone phone = PhoneFactory.getPhone(phoneId);
7170 if (phone == null) {
7171 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007172 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007173 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7174 if (cpt == null) {
7175 return Collections.emptyList();
7176 }
7177 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007178 }
7179
chen xuf7e9fe82019-05-09 19:31:02 -07007180 @Override
7181 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007182 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007183 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007184 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007185 try {
7186 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7187 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7188 }
7189 } finally {
7190 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007191 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007192 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007193 }
7194
Rambo Wang6812ffb2022-03-15 16:54:17 -07007195 @Override
7196 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7197 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7198
7199 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7200 if (phone == null) {
7201 return null;
7202 }
7203 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7204 if (cpt == null) {
7205 return null;
7206 }
7207 return cpt.getCarrierServicePackageName();
7208 }
7209
Wink Savilleb564aae2014-10-23 10:18:09 -07007210 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007211 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007212 UiccPort port = phone == null ? null : phone.getUiccPort();
7213 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007214 return null;
7215 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007216 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007217 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007218 return null;
7219 }
7220 return iccId;
7221 }
7222
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007223 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007224 public void setCallComposerStatus(int subId, int status) {
7225 enforceModifyPermission();
7226
7227 final long identity = Binder.clearCallingIdentity();
7228 try {
7229 Phone phone = getPhone(subId);
7230 if (phone != null) {
7231 Phone defaultPhone = phone.getImsPhone();
7232 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7233 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7234 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007235 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7236 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007237 }
7238 }
Shuo Qian284ae752020-12-22 19:10:14 -08007239 } catch (ImsException e) {
7240 throw new ServiceSpecificException(e.getCode());
7241 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007242 Binder.restoreCallingIdentity(identity);
7243 }
7244 }
7245
7246 @Override
7247 public int getCallComposerStatus(int subId) {
7248 enforceReadPrivilegedPermission("getCallComposerStatus");
7249
7250 final long identity = Binder.clearCallingIdentity();
7251 try {
7252 Phone phone = getPhone(subId);
7253 if (phone != null) {
7254 Phone defaultPhone = phone.getImsPhone();
7255 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7256 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7257 return imsPhone.getCallComposerStatus();
7258 }
7259 }
7260 } finally {
7261 Binder.restoreCallingIdentity(identity);
7262 }
7263 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7264 }
7265
7266 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007267 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7268 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007269 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007270 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007271
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007272 final long identity = Binder.clearCallingIdentity();
7273 try {
7274 final String iccId = getIccId(subId);
7275 final Phone phone = getPhone(subId);
7276 if (phone == null) {
7277 return false;
7278 }
7279 final String subscriberId = phone.getSubscriberId();
7280
7281 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007282 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007283 + subscriberId + " to " + number);
7284 }
7285
7286 if (TextUtils.isEmpty(iccId)) {
7287 return false;
7288 }
7289
7290 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7291
7292 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7293 if (alphaTag == null) {
7294 editor.remove(alphaTagPrefKey);
7295 } else {
7296 editor.putString(alphaTagPrefKey, alphaTag);
7297 }
7298
7299 // Record both the line number and IMSI for this ICCID, since we need to
7300 // track all merged IMSIs based on line number
7301 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7302 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7303 if (number == null) {
7304 editor.remove(numberPrefKey);
7305 editor.remove(subscriberPrefKey);
7306 } else {
7307 editor.putString(numberPrefKey, number);
7308 editor.putString(subscriberPrefKey, subscriberId);
7309 }
7310
7311 editor.commit();
7312 return true;
7313 } finally {
7314 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007315 }
Derek Tan7226c842014-07-02 17:42:23 -07007316 }
7317
7318 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007319 public String getLine1NumberForDisplay(int subId, String callingPackage,
7320 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007321 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007322 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007323 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007324 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007325 return null;
7326 }
Derek Tan97ebb422014-09-05 16:55:38 -07007327
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007328 final long identity = Binder.clearCallingIdentity();
7329 try {
7330 String iccId = getIccId(subId);
7331 if (iccId != null) {
7332 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7333 if (DBG_MERGE) {
7334 log("getLine1NumberForDisplay returning "
7335 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7336 }
7337 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007338 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007339 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7340 return null;
7341 } finally {
7342 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007343 }
Derek Tan7226c842014-07-02 17:42:23 -07007344 }
7345
7346 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007347 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7348 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007349 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007350 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007351 return null;
7352 }
Derek Tan97ebb422014-09-05 16:55:38 -07007353
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007354 final long identity = Binder.clearCallingIdentity();
7355 try {
7356 String iccId = getIccId(subId);
7357 if (iccId != null) {
7358 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7359 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7360 }
7361 return null;
7362 } finally {
7363 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007364 }
Derek Tan7226c842014-07-02 17:42:23 -07007365 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007366
7367 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007368 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7369 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007370 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7371 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007372 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007373 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007374 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007375 return null;
7376 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007377
Jordan Liub49b04b2019-05-06 14:45:15 -07007378 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7379 // the process, where TelephonyManager was instantiated.
7380 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007381 final long identity = Binder.clearCallingIdentity();
7382 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007383 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007384 final TelephonyManager tele = TelephonyManager.from(context);
7385 final SubscriptionManager sub = SubscriptionManager.from(context);
7386
7387 // Figure out what subscribers are currently active
7388 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007389
Jordan Liub49b04b2019-05-06 14:45:15 -07007390 // Only consider subs which match the current subId
7391 // This logic can be simplified. See b/131189269 for progress.
7392 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007393 activeSubscriberIds.add(tele.getSubscriberId(subId));
7394 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007395
7396 // First pass, find a number override for an active subscriber
7397 String mergeNumber = null;
7398 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7399 for (String key : prefs.keySet()) {
7400 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7401 final String subscriberId = (String) prefs.get(key);
7402 if (activeSubscriberIds.contains(subscriberId)) {
7403 final String iccId = key.substring(
7404 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7405 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7406 mergeNumber = (String) prefs.get(numberKey);
7407 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007408 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007409 + " for active subscriber " + subscriberId);
7410 }
7411 if (!TextUtils.isEmpty(mergeNumber)) {
7412 break;
7413 }
7414 }
7415 }
7416 }
7417
7418 // Shortcut when no active merged subscribers
7419 if (TextUtils.isEmpty(mergeNumber)) {
7420 return null;
7421 }
7422
7423 // Second pass, find all subscribers under that line override
7424 final ArraySet<String> result = new ArraySet<>();
7425 for (String key : prefs.keySet()) {
7426 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7427 final String number = (String) prefs.get(key);
7428 if (mergeNumber.equals(number)) {
7429 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7430 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7431 final String subscriberId = (String) prefs.get(subscriberKey);
7432 if (!TextUtils.isEmpty(subscriberId)) {
7433 result.add(subscriberId);
7434 }
7435 }
7436 }
7437 }
7438
7439 final String[] resultArray = result.toArray(new String[result.size()]);
7440 Arrays.sort(resultArray);
7441 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007442 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007443 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7444 }
7445 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007446 } finally {
7447 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007448 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007449 }
7450
7451 @Override
zoey chen38003472019-12-13 17:16:31 +08007452 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7453 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007454
7455 final long identity = Binder.clearCallingIdentity();
7456 try {
7457 final TelephonyManager telephonyManager = mApp.getSystemService(
7458 TelephonyManager.class);
7459 String subscriberId = telephonyManager.getSubscriberId(subId);
7460 if (subscriberId == null) {
7461 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007462 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007463 + subId);
7464 }
7465 return null;
7466 }
7467
Jack Yu285100e2022-12-02 22:48:35 -08007468 ParcelUuid groupUuid;
7469 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08007470 final SubscriptionInfo info = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08007471 .getSubscriptionInfo(subId);
7472 groupUuid = info.getGroupUuid();
7473 } else {
7474 final SubscriptionInfo info = mSubscriptionController
7475 .getSubscriptionInfo(subId);
7476 groupUuid = info.getGroupUuid();
7477 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007478 // If it doesn't belong to any group, return just subscriberId of itself.
7479 if (groupUuid == null) {
7480 return new String[]{subscriberId};
7481 }
7482
7483 // Get all subscriberIds from the group.
7484 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08007485 List<SubscriptionInfo> groupInfos;
7486 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08007487 groupInfos = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08007488 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7489 mApp.getAttributionTag());
7490 } else {
7491 groupInfos = mSubscriptionController
7492 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7493 mApp.getAttributionTag());
7494 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007495 for (SubscriptionInfo subInfo : groupInfos) {
7496 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7497 if (subscriberId != null) {
7498 mergedSubscriberIds.add(subscriberId);
7499 }
7500 }
7501
7502 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7503 } finally {
7504 Binder.restoreCallingIdentity(identity);
7505
7506 }
7507 }
7508
7509 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007510 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007511 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007512 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007513
7514 final long identity = Binder.clearCallingIdentity();
7515 try {
7516 final Phone phone = getPhone(subId);
7517 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7518 } finally {
7519 Binder.restoreCallingIdentity(identity);
7520 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007521 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007522
7523 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007524 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007525 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7526 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007527 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7528 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007529
7530 final long identity = Binder.clearCallingIdentity();
7531 try {
7532 final Phone phone = getPhone(subId);
7533 if (phone == null) {
7534 return false;
7535 }
7536 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7537 cdmaNonRoamingList);
7538 } finally {
7539 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007540 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007541 }
7542
7543 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007544 @Deprecated
7545 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7546 enforceModifyPermission();
7547
7548 int returnValue = 0;
7549 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007550 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007551 if(result.exception == null) {
7552 if (result.result != null) {
7553 byte[] responseData = (byte[])(result.result);
7554 if(responseData.length > oemResp.length) {
7555 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7556 responseData.length + "bytes. Buffer Size is " +
7557 oemResp.length + "bytes.");
7558 }
7559 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7560 returnValue = responseData.length;
7561 }
7562 } else {
7563 CommandException ex = (CommandException) result.exception;
7564 returnValue = ex.getCommandError().ordinal();
7565 if(returnValue > 0) returnValue *= -1;
7566 }
7567 } catch (RuntimeException e) {
7568 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7569 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7570 if(returnValue > 0) returnValue *= -1;
7571 }
7572
7573 return returnValue;
7574 }
7575
7576 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007577 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007578 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007579 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007580 if (phone == null) {
7581 return raf;
7582 }
7583
Shuo Qiandee53402020-05-29 14:08:15 -07007584 try {
7585 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007586 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007587 mApp, phone.getSubId(), "getRadioAccessFamily");
7588 } catch (SecurityException e) {
7589 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7590 throw e;
7591 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007592
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007593 final long identity = Binder.clearCallingIdentity();
7594 try {
chen xub97461a2018-10-26 14:17:57 -07007595 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007596 } finally {
7597 Binder.restoreCallingIdentity(identity);
7598 }
chen xub97461a2018-10-26 14:17:57 -07007599 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007600 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007601
7602 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007603 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007604 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007605 try {
7606 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7607 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007608 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007609 }
7610 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007611 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007612 }
7613 RoleManager rm = mApp.getSystemService(RoleManager.class);
7614 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7615 if (!dialerRoleHolders.contains(callingPackage)) {
7616 throw new SecurityException("App must be the dialer role holder to"
7617 + " upload a call composer pic");
7618 }
7619
7620 Executors.newSingleThreadExecutor().execute(() -> {
7621 ByteArrayOutputStream output = new ByteArrayOutputStream(
7622 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7623 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7624 boolean readUntilEnd = false;
7625 int totalBytesRead = 0;
7626 byte[] buffer = new byte[16 * 1024];
7627 while (true) {
7628 int numRead;
7629 try {
7630 numRead = input.read(buffer);
7631 } catch (IOException e) {
7632 try {
7633 fd.checkError();
7634 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7635 null);
7636 } catch (IOException e1) {
7637 // This means that the other side closed explicitly with an error. If this
7638 // happens, log and ignore.
7639 loge("Remote end of call composer picture pipe closed: " + e1);
7640 }
7641 break;
7642 }
7643 if (numRead == -1) {
7644 readUntilEnd = true;
7645 break;
7646 }
7647 totalBytesRead += numRead;
7648 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7649 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7650 try {
7651 input.close();
7652 } catch (IOException e) {
7653 // ignore
7654 }
7655 break;
7656 }
7657 output.write(buffer, 0, numRead);
7658 }
7659 // Generally, the remote end will close the file descriptors. The only case where we
7660 // close is above, where the picture size is too big.
7661
7662 try {
7663 fd.checkError();
7664 } catch (IOException e) {
7665 loge("Remote end for call composer closed with an error: " + e);
7666 return;
7667 }
7668
Hall Liuaa4211e2021-01-20 15:43:39 -08007669 if (!readUntilEnd) {
7670 loge("Did not finish reading entire image; aborting");
7671 return;
7672 }
Hall Liu82694d52020-12-11 18:22:04 -08007673
Hall Liuaa4211e2021-01-20 15:43:39 -08007674 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7675 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7676 new CallComposerPictureTransfer.Factory() {},
7677 imageData,
7678 (result) -> {
7679 if (result.first != null) {
7680 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7681 Bundle outputResult = new Bundle();
7682 outputResult.putParcelable(
7683 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7684 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7685 outputResult);
7686 } else {
7687 callback.send(result.second, null);
7688 }
7689 }
7690 );
Hall Liu82694d52020-12-11 18:22:04 -08007691 });
7692 }
7693
7694 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007695 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007696 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007697 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007698
7699 final long identity = Binder.clearCallingIdentity();
7700 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007701 ImsManager.getInstance(defaultPhone.getContext(),
7702 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007703 } finally {
7704 Binder.restoreCallingIdentity(identity);
7705 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007706 }
7707
7708 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007709 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007710 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007711 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7712 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007713 return false;
7714 }
Svet Ganovb320e182015-04-16 12:30:10 -07007715
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007716 final long identity = Binder.clearCallingIdentity();
7717 try {
7718 // Check the user preference and the system-level IMS setting. Even if the user has
7719 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7720 // In the long run, we may instead need to check if there exists a connection service
7721 // which can support video calling.
7722 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007723 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007724 return imsManager.isVtEnabledByPlatform()
7725 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7726 && imsManager.isVtEnabledByUser();
7727 } finally {
7728 Binder.restoreCallingIdentity(identity);
7729 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007730 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007731
Andrew Leea1239f22015-03-02 17:44:07 -08007732 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007733 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7734 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007735 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007736 mApp, subId, callingPackage, callingFeatureId,
7737 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007738 return false;
7739 }
7740
7741 final long identity = Binder.clearCallingIdentity();
7742 try {
7743 CarrierConfigManager configManager =
7744 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007745 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007746 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7747 } finally {
7748 Binder.restoreCallingIdentity(identity);
7749 }
Andrew Leea1239f22015-03-02 17:44:07 -08007750 }
7751
7752 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007753 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007754 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007755 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007756 return false;
7757 }
7758
7759 final long identity = Binder.clearCallingIdentity();
7760 try {
7761 CarrierConfigManager configManager =
7762 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007763 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007764 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7765 } finally {
7766 Binder.restoreCallingIdentity(identity);
7767 }
Andrew Leea1239f22015-03-02 17:44:07 -08007768 }
7769
Andrew Lee9431b832015-03-09 18:46:45 -07007770 @Override
7771 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007772 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007773 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007774 }
7775
7776 @Override
7777 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007778 final long identity = Binder.clearCallingIdentity();
7779 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007780 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007781 } finally {
7782 Binder.restoreCallingIdentity(identity);
7783 }
Andrew Lee9431b832015-03-09 18:46:45 -07007784 }
7785
Hall Liuf6668912018-10-31 17:05:23 -07007786 /**
7787 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7788 * support for the feature and device firmware support.
7789 *
7790 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7791 */
7792 @Override
7793 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007794 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007795 final Phone phone = getPhone(subscriptionId);
7796 if (phone == null) {
7797 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7798 return false;
7799 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007800 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007801 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007802 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7803 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007804 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007805 return isCarrierSupported && isDeviceSupported;
7806 } finally {
7807 Binder.restoreCallingIdentity(identity);
7808 }
Hall Liu98187582018-01-22 19:15:32 -08007809 }
7810
Hall Liuf6668912018-10-31 17:05:23 -07007811 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007812 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7813 * RTT setting, will return true if the device and carrier both support RTT.
7814 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007815 */
7816 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007817 final long identity = Binder.clearCallingIdentity();
7818 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007819 boolean isRttSupported = isRttSupported(subscriptionId);
7820 boolean isUserRttSettingOn = Settings.Secure.getInt(
7821 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7822 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7823 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7824 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007825 } finally {
7826 Binder.restoreCallingIdentity(identity);
7827 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007828 }
7829
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007830 @Deprecated
7831 @Override
7832 public String getDeviceId(String callingPackage) {
7833 return getDeviceIdWithFeature(callingPackage, null);
7834 }
7835
Sanket Padawe7310cc72015-01-14 09:53:20 -08007836 /**
7837 * Returns the unique device ID of phone, for example, the IMEI for
7838 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7839 *
7840 * <p>Requires Permission:
7841 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7842 */
7843 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007844 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007845 try {
7846 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7847 } catch (SecurityException se) {
7848 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7849 throw new SecurityException("Package " + callingPackage + " does not belong to "
7850 + Binder.getCallingUid());
7851 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007852 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007853 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007854 return null;
7855 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007856 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007857 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007858 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007859 return null;
7860 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007861
7862 final long identity = Binder.clearCallingIdentity();
7863 try {
7864 return phone.getDeviceId();
7865 } finally {
7866 Binder.restoreCallingIdentity(identity);
7867 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007868 }
7869
Ping Sunc67b7c22016-03-02 19:16:45 +08007870 /**
7871 * {@hide}
7872 * Returns the IMS Registration Status on a particular subid
7873 *
7874 * @param subId
7875 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007876 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007877 Phone phone = getPhone(subId);
7878 if (phone != null) {
7879 return phone.isImsRegistered();
7880 } else {
7881 return false;
7882 }
7883 }
7884
Santos Cordon7a1885b2015-02-03 11:15:19 -08007885 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007886 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007887 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007888 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007889 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007890 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7891 }
7892 final long identity = Binder.clearCallingIdentity();
7893 try {
7894 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7895 } finally {
7896 Binder.restoreCallingIdentity(identity);
7897 }
7898 }
7899
7900 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007901 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007902 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007903 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007904 mApp,
7905 subscriptionId,
7906 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
7907 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007908 final long identity = Binder.clearCallingIdentity();
7909 try {
7910 Phone phone = getPhone(subscriptionId);
7911 if (phone == null) {
7912 return null;
7913 }
7914 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7915 } finally {
7916 Binder.restoreCallingIdentity(identity);
7917 }
7918 }
7919
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007920 /**
7921 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007922 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007923 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007924 final long identity = Binder.clearCallingIdentity();
7925 try {
7926 Phone phone = getPhone(subId);
7927 if (phone != null) {
7928 return phone.isWifiCallingEnabled();
7929 } else {
7930 return false;
7931 }
7932 } finally {
7933 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007934 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007935 }
7936
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007937 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007938 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007939 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007940 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007941 final long identity = Binder.clearCallingIdentity();
7942 try {
7943 Phone phone = getPhone(subId);
7944 if (phone != null) {
7945 return phone.isVideoEnabled();
7946 } else {
7947 return false;
7948 }
7949 } finally {
7950 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007951 }
7952 }
7953
7954 /**
7955 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7956 * defined in {@link ImsRegistrationImplBase}.
7957 */
7958 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007959 final long identity = Binder.clearCallingIdentity();
7960 try {
7961 Phone phone = getPhone(subId);
7962 if (phone != null) {
7963 return phone.getImsRegistrationTech();
7964 } else {
7965 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7966 }
7967 } finally {
7968 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007969 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007970 }
7971
Stuart Scott8eef64f2015-04-08 15:13:54 -07007972 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007973 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007974 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007975 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7976 return;
7977 }
Kai Shif70f46f2021-03-03 13:59:46 -08007978 Phone defaultPhone = getDefaultPhone();
7979 if (defaultPhone != null) {
7980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7981 mApp, getDefaultPhone().getSubId(), "factoryReset");
7982 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007983 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007984
Svet Ganovcc087f82015-05-12 20:35:54 -07007985 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007986 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7987 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007988 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007989 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007990 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007991 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007992 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007993 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007994 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007995 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007996 // There has been issues when Sms raw table somehow stores orphan
7997 // fragments. They lead to garbled message when new fragments come
7998 // in and combined with those stale ones. In case this happens again,
7999 // user can reset all network settings which will clean up this table.
8000 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008001 // Clean up IMS settings as well here.
8002 int slotId = getSlotIndex(subId);
8003 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8004 ImsManager.getInstance(mApp, slotId).factoryReset();
8005 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008006
Kai Shif70f46f2021-03-03 13:59:46 -08008007 if (defaultPhone == null) {
8008 return;
8009 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008010 // Erase modem config if erase modem on network setting is enabled.
8011 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8012 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8013 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008014 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008015 }
Kai Shif70f46f2021-03-03 13:59:46 -08008016
8017 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008018 } finally {
8019 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008020 }
8021 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008022
SongFerngWangfd89b102021-05-27 22:44:54 +08008023 @VisibleForTesting
8024 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8025 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8026 return;
8027 }
8028 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8029 RILConstants.PREFERRED_NETWORK_MODE);
8030 SubscriptionManager.setSubscriptionProperty(subId,
8031 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8032 "user=" + defaultNetworkType);
8033 phone.loadAllowedNetworksFromSubscriptionDatabase();
8034 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8035 defaultNetworkType, null);
8036 }
8037
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008038 private void cleanUpSmsRawTable(Context context) {
8039 ContentResolver resolver = context.getContentResolver();
8040 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8041 resolver.delete(uri, null, null);
8042 }
8043
Narayan Kamath1c496c22015-04-16 14:40:19 +01008044 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008045 public String getSimLocaleForSubscriber(int subId) {
8046 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
8047 final Phone phone = getPhone(subId);
8048 if (phone == null) {
8049 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008050 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008051 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008052 final long identity = Binder.clearCallingIdentity();
8053 try {
Jack Yu285100e2022-12-02 22:48:35 -08008054 SubscriptionInfo info;
8055 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008056 info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
Jack Yu285100e2022-12-02 22:48:35 -08008057 phone.getContext().getOpPackageName(),
8058 phone.getContext().getAttributionTag());
8059 if (info == null) {
8060 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8061 return null;
8062 }
8063 } else {
8064 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
8065 phone.getContext().getOpPackageName(),
8066 phone.getContext().getAttributionTag());
8067 if (info == null) {
8068 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8069 return null;
8070 }
chen xu6291c472019-02-04 12:55:53 -08008071 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008072 // Try and fetch the locale from the carrier properties or from the SIM language
8073 // preferences (EF-PL and EF-LI)...
8074 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008075 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008076 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8077 if (localeFromDefaultSim != null) {
8078 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8079 if (DBG) log("Using locale from subId: " + subId + " locale: "
8080 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008081 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008082 } else {
8083 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008084 }
8085 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008086
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008087 // The SIM language preferences only store a language (e.g. fr = French), not an
8088 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8089 // the SIM and carrier preferences does not include a country we add the country
8090 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008091 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008092 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008093 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008094 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008095 }
8096
8097 if (DBG) log("No locale found - returning null");
8098 return null;
8099 } finally {
8100 Binder.restoreCallingIdentity(identity);
8101 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008102 }
8103
tom hsu0b59d292022-09-29 23:49:21 +08008104 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008105 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008106 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008107 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008108 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008109 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8110 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008111 Locale.forLanguageTag(localeTag).getCountry())) {
8112 return localeTag;
8113 }
8114 }
8115 return inputLocale.toLanguageTag();
8116 }
8117
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008118 /**
8119 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8120 */
8121 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08008122 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008123 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Jack Yu285100e2022-12-02 22:48:35 -08008124 mApp.getOpPackageName(), mApp.getAttributionTag());
8125 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008126 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08008127 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008128 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008129
Gary Jian3aa9a762022-01-24 16:41:19 +08008130 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8131 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008132
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008133 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008134 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8135 * representing the state of the modem.
8136 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008137 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8138 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008139 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008140 */
8141 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008142 public void requestModemActivityInfo(ResultReceiver result) {
8143 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008144 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008145
8146 final long identity = Binder.clearCallingIdentity();
8147 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008148 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008149 } finally {
8150 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008151 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008152 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008153
Gary Jian76280a42022-12-07 16:18:33 +08008154 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008155 // less than total activity duration.
8156 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8157 if (info == null) {
8158 return false;
8159 }
8160 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008161 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008162 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8163
Hall Liu49656c02020-10-09 19:00:11 -07008164 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8165
Siddharth Rayb8114062018-06-17 15:02:38 -07008166 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008167 && (info.getSleepTimeMillis() <= activityDurationMs)
8168 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008169 }
8170
Gary Jian3aa9a762022-01-24 16:41:19 +08008171 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8172 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8173 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8174 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8175
8176 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8177 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8178 }
8179
8180 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8181 mLastModemActivityInfo.setReceiveTimeMillis(
8182 rat,
8183 freq,
8184 info.getReceiveTimeMillis(rat, freq)
8185 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8186 }
8187
8188 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8189 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8190 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8191 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8192
8193 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8194 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8195 }
8196 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8197 mLastModemActivityInfo.setReceiveTimeMillis(
8198 rat,
8199 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8200 }
8201
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008202 /**
8203 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8204 * @param info recent ModemActivityInfo
8205 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008206 private void mergeModemActivityInfo(ModemActivityInfo info) {
8207 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008208 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008209 boolean matched;
8210 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8211 matched = false;
8212 int rat = info.getSpecificInfoRat(i);
8213 int freq = info.getSpecificInfoFrequencyRange(i);
8214 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8215 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8216 //if it already exists
8217 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8218 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8219 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8220 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8221 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8222 updateLastModemActivityInfo(info, rat, freq);
8223 matched = true;
8224 }
8225 } else {
8226 updateLastModemActivityInfo(info, rat);
8227 matched = true;
8228 }
8229 }
8230 }
8231
8232 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008233 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008234 new ActivityStatsTechSpecificInfo(
8235 rat,
8236 freq,
8237 info.getTransmitTimeMillis(rat, freq),
8238 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008239 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008240 }
8241 }
8242 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8243 mLastModemActivitySpecificInfo =
8244 new ActivityStatsTechSpecificInfo[merged.size()];
8245 merged.toArray(mLastModemActivitySpecificInfo);
8246
8247 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8248 mLastModemActivityInfo.setSleepTimeMillis(
8249 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008250 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008251 mLastModemActivityInfo.setIdleTimeMillis(
8252 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008253 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008254
8255 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008256 new ModemActivityInfo(
8257 mLastModemActivityInfo.getTimestampMillis(),
8258 mLastModemActivityInfo.getSleepTimeMillis(),
8259 mLastModemActivityInfo.getIdleTimeMillis(),
8260 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008261 }
8262
8263 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8264 ActivityStatsTechSpecificInfo[] info) {
8265 int infoSize = info.length;
8266 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8267 for (int i = 0; i < infoSize; i++) {
8268 ret[i] = new ActivityStatsTechSpecificInfo(
8269 info[i].getRat(), info[i].getFrequencyRange(),
8270 info[i].getTransmitTimeMillis(),
8271 (int) info[i].getReceiveTimeMillis());
8272 }
8273 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008274 }
8275
Jack Yu85bd38a2015-11-09 11:34:32 -08008276 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008277 * Returns the service state information on specified subscription.
8278 */
8279 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008280 public ServiceState getServiceStateForSubscriber(int subId,
8281 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8282 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008283 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008284 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008285 return null;
8286 }
8287
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008288 boolean hasFinePermission = false;
8289 boolean hasCoarsePermission = false;
8290 if (!renounceFineLocationAccess) {
8291 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8292 LocationAccessPolicy.checkLocationPermission(mApp,
8293 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8294 .setCallingPackage(callingPackage)
8295 .setCallingFeatureId(callingFeatureId)
8296 .setCallingPid(Binder.getCallingPid())
8297 .setCallingUid(Binder.getCallingUid())
8298 .setMethod("getServiceStateForSubscriber")
8299 .setLogAsInfo(true)
8300 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8301 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8302 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8303 .build());
8304 hasFinePermission =
8305 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8306 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008307
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008308 if (!renounceCoarseLocationAccess) {
8309 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8310 LocationAccessPolicy.checkLocationPermission(mApp,
8311 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8312 .setCallingPackage(callingPackage)
8313 .setCallingFeatureId(callingFeatureId)
8314 .setCallingPid(Binder.getCallingPid())
8315 .setCallingUid(Binder.getCallingUid())
8316 .setMethod("getServiceStateForSubscriber")
8317 .setLogAsInfo(true)
8318 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8319 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8320 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8321 .build());
8322 hasCoarsePermission =
8323 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8324 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008325
Jack Yu479f40e2020-10-27 21:29:25 -07008326 final Phone phone = getPhone(subId);
8327 if (phone == null) {
8328 return null;
8329 }
8330
Jordan Liu0f2bc442020-11-18 16:47:37 -08008331 final long identity = Binder.clearCallingIdentity();
8332
Jack Yu479f40e2020-10-27 21:29:25 -07008333 boolean isCallingPackageDataService = phone.getDataServicePackages()
8334 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008335 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008336 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008337 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008338 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08008339 .getSubscriptionInfoInternal(subId);
8340 if (subInfo == null || !subInfo.isActive()) {
8341 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8342 + "subId=" + subId);
8343 return null;
8344 }
8345 } else {
8346 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8347 callingFeatureId)) {
8348 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8349 + "subId=" + subId);
8350 return null;
8351 }
Jordan Liuc437b192020-08-17 10:59:12 -07008352 }
8353
Hall Liuf19c44f2018-11-27 14:38:17 -08008354 ServiceState ss = phone.getServiceState();
8355
8356 // Scrub out the location info in ServiceState depending on what level of access
8357 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008358 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008359 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8360 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008361 } finally {
8362 Binder.restoreCallingIdentity(identity);
8363 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008364 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008365
8366 /**
8367 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8368 *
8369 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8370 * voicemail ringtone.
8371 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8372 * PhoneAccount.
8373 */
8374 @Override
8375 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008376 final long identity = Binder.clearCallingIdentity();
8377 try {
8378 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8379 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008380 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008381 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008382
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008383 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8384 } finally {
8385 Binder.restoreCallingIdentity(identity);
8386 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008387 }
8388
8389 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008390 * Sets the per-account voicemail ringtone.
8391 *
8392 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8393 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8394 *
8395 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8396 * voicemail ringtone.
8397 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8398 * PhoneAccount.
8399 */
8400 @Override
8401 public void setVoicemailRingtoneUri(String callingPackage,
8402 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008403 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008404 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008405 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8406 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008407 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8408 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8409 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008410 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008411
8412 final long identity = Binder.clearCallingIdentity();
8413 try {
8414 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8415 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008416 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008417 }
8418 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8419 } finally {
8420 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008421 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008422 }
8423
8424 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008425 * Returns whether vibration is set for voicemail notification in Phone settings.
8426 *
8427 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8428 * voicemail vibration setting.
8429 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8430 */
8431 @Override
8432 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008433 final long identity = Binder.clearCallingIdentity();
8434 try {
8435 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8436 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008437 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008438 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008439
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008440 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8441 } finally {
8442 Binder.restoreCallingIdentity(identity);
8443 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008444 }
8445
Youhan Wange64578a2016-05-02 15:32:42 -07008446 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008447 * Sets the per-account voicemail vibration.
8448 *
8449 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8450 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8451 *
8452 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8453 * voicemail vibration setting.
8454 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8455 * specific PhoneAccount.
8456 */
8457 @Override
8458 public void setVoicemailVibrationEnabled(String callingPackage,
8459 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008460 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008461 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008462 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8463 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8465 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8466 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008467 }
8468
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008469 final long identity = Binder.clearCallingIdentity();
8470 try {
8471 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8472 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008473 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008474 }
8475 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8476 } finally {
8477 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008478 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008479 }
8480
8481 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008482 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8483 *
8484 * @throws SecurityException if the caller does not have the required permission
8485 */
arunvoddud7401012022-12-15 16:08:12 +00008486 @VisibleForTesting
8487 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008488 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008489 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008490 }
8491
8492 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008493 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8494 * permission.
8495 *
8496 * @throws SecurityException if the caller does not have the required permission
8497 */
8498 private void enforceSendSmsPermission() {
8499 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8500 }
8501
8502 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008503 * Make sure either called from same process as self (phone) or IPC caller has interact across
8504 * users permission.
8505 *
8506 * @throws SecurityException if the caller does not have the required permission
8507 */
8508 private void enforceInteractAcrossUsersPermission(String message) {
8509 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8510 }
8511
8512 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008513 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008514 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008515 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008516 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008517 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008518 final long identity = Binder.clearCallingIdentity();
8519 try {
8520 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008521 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008522 if (componentName == null) {
8523 throw new SecurityException(
8524 "Caller not current active visual voicemail package[null]");
8525 }
8526 String vvmPackage = componentName.getPackageName();
8527 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008528 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008529 }
8530 } finally {
8531 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008532 }
8533 }
8534
8535 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008536 * Return the application ID for the app type.
8537 *
8538 * @param subId the subscription ID that this request applies to.
8539 * @param appType the uicc app type.
8540 * @return Application ID for specificied app type, or null if no uicc.
8541 */
8542 @Override
8543 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008544 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008545 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008546
8547 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008548 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008549 if (phone == null) {
8550 return null;
8551 }
8552 String aid = null;
8553 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008554 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008555 .getApplicationByType(appType).getAid();
8556 } catch (Exception e) {
8557 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8558 }
8559 return aid;
8560 } finally {
8561 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008562 }
Youhan Wange64578a2016-05-02 15:32:42 -07008563 }
8564
Youhan Wang4001d252016-05-11 10:29:41 -07008565 /**
8566 * Return the Electronic Serial Number.
8567 *
8568 * @param subId the subscription ID that this request applies to.
8569 * @return ESN or null if error.
8570 */
8571 @Override
8572 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008573 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008574 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008575
8576 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008577 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008578 if (phone == null) {
8579 return null;
8580 }
8581 String esn = null;
8582 try {
8583 esn = phone.getEsn();
8584 } catch (Exception e) {
8585 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8586 }
8587 return esn;
8588 } finally {
8589 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008590 }
Youhan Wang4001d252016-05-11 10:29:41 -07008591 }
8592
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008593 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008594 * Return the Preferred Roaming List Version.
8595 *
8596 * @param subId the subscription ID that this request applies to.
8597 * @return PRLVersion or null if error.
8598 */
8599 @Override
8600 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008601 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008602 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008603
8604 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008605 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008606 if (phone == null) {
8607 return null;
8608 }
8609 String cdmaPrlVersion = null;
8610 try {
8611 cdmaPrlVersion = phone.getCdmaPrlVersion();
8612 } catch (Exception e) {
8613 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8614 }
8615 return cdmaPrlVersion;
8616 } finally {
8617 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008618 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008619 }
8620
8621 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008622 * Get snapshot of Telephony histograms
8623 * @return List of Telephony histograms
8624 * @hide
8625 */
8626 @Override
8627 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8629 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008630
8631 final long identity = Binder.clearCallingIdentity();
8632 try {
8633 return RIL.getTelephonyRILTimingHistograms();
8634 } finally {
8635 Binder.restoreCallingIdentity(identity);
8636 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008637 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008638
8639 /**
8640 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008641 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8642 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008643 * Require system privileges. In the future we may add this to carrier APIs.
8644 *
Michele Berionne482f8202018-11-27 18:57:59 -08008645 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008646 */
8647 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008648 @TelephonyManager.SetCarrierRestrictionResult
8649 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008650 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008651 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008652
Michele Berionne482f8202018-11-27 18:57:59 -08008653 if (carrierRestrictionRules == null) {
8654 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008655 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008656
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008657 final long identity = Binder.clearCallingIdentity();
8658 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008659 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008660 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008661 } finally {
8662 Binder.restoreCallingIdentity(identity);
8663 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008664 }
8665
8666 /**
8667 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008668 * Get the allowed carrier list and the excluded carrier list, including the priority between
8669 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008670 * Require system privileges. In the future we may add this to carrier APIs.
8671 *
Michele Berionne482f8202018-11-27 18:57:59 -08008672 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008673 */
8674 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008675 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008676 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008677 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008678
8679 final long identity = Binder.clearCallingIdentity();
8680 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008681 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8682 if (response instanceof CarrierRestrictionRules) {
8683 return (CarrierRestrictionRules) response;
8684 }
8685 // Response is an Exception of some kind,
8686 // which is signalled to the user as a NULL retval
8687 return null;
8688 } catch (Exception e) {
8689 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8690 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008691 } finally {
8692 Binder.restoreCallingIdentity(identity);
8693 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008694 }
8695
fionaxu59545b42016-05-25 15:53:37 -07008696 /**
arunvoddud7401012022-12-15 16:08:12 +00008697 * Fetches the carrier restriction status of the device and sends the status to the caller
8698 * through the callback.
8699 *
8700 * @param callback The callback that will be used to send the result.
8701 * @throws SecurityException if the caller does not have the required permission/privileges or
8702 * the caller is not allowlisted.
8703 */
8704 @Override
8705 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
8706 enforceReadPermission("getCarrierRestrictionStatus");
8707 int carrierId = validateCallerAndGetCarrierId(packageName);
8708 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
8709 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
8710 throw new SecurityException("Not an authorized caller");
8711 }
8712 final long identity = Binder.clearCallingIdentity();
8713 try {
8714 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
8715 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
8716 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
8717 } finally {
8718 Binder.restoreCallingIdentity(identity);
8719 }
8720 }
8721
8722 @VisibleForTesting
8723 public int validateCallerAndGetCarrierId(String packageName) {
8724 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8725 return allowListInfo.validateCallerAndGetCarrierId(packageName);
8726 }
8727
8728 /**
fionaxu59545b42016-05-25 15:53:37 -07008729 * Action set from carrier signalling broadcast receivers to enable/disable radio
8730 * @param subId the subscription ID that this action applies to.
8731 * @param enabled control enable or disable radio.
8732 * {@hide}
8733 */
8734 @Override
8735 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8736 enforceModifyPermission();
8737 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008738
8739 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008740 if (phone == null) {
8741 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8742 return;
8743 }
8744 try {
8745 phone.carrierActionSetRadioEnabled(enabled);
8746 } catch (Exception e) {
8747 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008748 } finally {
8749 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008750 }
8751 }
8752
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008753 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008754 * Enable or disable Voice over NR (VoNR)
8755 * @param subId the subscription ID that this action applies to.
8756 * @param enabled enable or disable VoNR.
8757 * @return operation result.
8758 */
8759 @Override
8760 public int setVoNrEnabled(int subId, boolean enabled) {
8761 enforceModifyPermission();
8762 final Phone phone = getPhone(subId);
8763
8764 final long identity = Binder.clearCallingIdentity();
8765 if (phone == null) {
8766 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8767 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8768 }
8769
8770 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8771 try {
8772 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8773 workSource);
8774 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008775
8776 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8777 if (DBG) {
8778 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8779 }
8780 SubscriptionManager.setSubscriptionProperty(
8781 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8782 (enabled ? "1" : "0"));
8783 }
8784
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008785 return result;
8786 } finally {
8787 Binder.restoreCallingIdentity(identity);
8788 }
8789 }
8790
8791 /**
8792 * Is voice over NR enabled
8793 * @return true if VoNR is enabled else false
8794 */
8795 @Override
8796 public boolean isVoNrEnabled(int subId) {
8797 enforceReadPrivilegedPermission("isVoNrEnabled");
8798 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8799 final long identity = Binder.clearCallingIdentity();
8800 try {
8801 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8802 null, subId, workSource);
8803 if (DBG) log("isVoNrEnabled: " + isEnabled);
8804 return isEnabled;
8805 } finally {
8806 Binder.restoreCallingIdentity(identity);
8807 }
8808 }
8809
8810 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008811 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8812 * network status based on which carrier apps could apply actions accordingly,
8813 * enable/disable default url handler for example.
8814 *
8815 * @param subId the subscription ID that this action applies to.
8816 * @param report control start/stop reporting the default network status.
8817 * {@hide}
8818 */
8819 @Override
8820 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8821 enforceModifyPermission();
8822 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008823
8824 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008825 if (phone == null) {
8826 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8827 return;
8828 }
8829 try {
8830 phone.carrierActionReportDefaultNetworkStatus(report);
8831 } catch (Exception e) {
8832 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008833 } finally {
8834 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008835 }
8836 }
8837
8838 /**
fionaxud9622282017-07-17 17:51:30 -07008839 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8840 * @param subId the subscription ID that this action applies to.
8841 * {@hide}
8842 */
8843 @Override
8844 public void carrierActionResetAll(int subId) {
8845 enforceModifyPermission();
8846 final Phone phone = getPhone(subId);
8847 if (phone == null) {
8848 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8849 return;
8850 }
8851 try {
8852 phone.carrierActionResetAll();
8853 } catch (Exception e) {
8854 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8855 }
8856 }
8857
8858 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008859 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8860 * bug report is being generated.
8861 */
8862 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008863 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008864 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8865 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008866 writer.println("Permission Denial: can't dump Phone from pid="
8867 + Binder.getCallingPid()
8868 + ", uid=" + Binder.getCallingUid()
8869 + "without permission "
8870 + android.Manifest.permission.DUMP);
8871 return;
8872 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008873 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008874 }
Jack Yueb89b242016-06-22 13:27:47 -07008875
Brad Ebingerdac2f002018-04-03 15:17:52 -07008876 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008877 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8878 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8879 @NonNull String[] args) {
8880 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8881 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008882 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008883 }
8884
Jack Yueb89b242016-06-22 13:27:47 -07008885 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008886 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008887 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008888 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008889 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008890 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008891 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008892 */
8893 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008894 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008895 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008896 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8897 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8898 try {
8899 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008900 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008901 } catch (SecurityException se) {
8902 enforceModifyPermission();
8903 }
8904 } else {
8905 enforceModifyPermission();
8906 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008907
8908 final long identity = Binder.clearCallingIdentity();
8909 try {
8910 Phone phone = getPhone(subId);
8911 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008912 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8913 phone.carrierActionSetMeteredApnsEnabled(enabled);
8914 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008915 phone.getDataSettingsManager().setDataEnabled(
8916 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008917 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008918 }
8919 } finally {
8920 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008921 }
8922 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008923
8924 /**
8925 * Get Client request stats
8926 * @return List of Client Request Stats
8927 * @hide
8928 */
8929 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008930 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8931 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008932 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008933 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008934 return null;
8935 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008936 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008937
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008938 final long identity = Binder.clearCallingIdentity();
8939 try {
8940 if (phone != null) {
8941 return phone.getClientRequestStats();
8942 }
8943
8944 return null;
8945 } finally {
8946 Binder.restoreCallingIdentity(identity);
8947 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008948 }
8949
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008950 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008951 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008952 if (uid == Process.ROOT_UID && packageName == null) {
8953 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8954 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8955 // exception. ROOT_UID seems not to have a valid package name returned by
8956 // PackageManager, so just fake it here to avoid issues when running telephony shell
8957 // commands that plumb through the RIL as root, like so:
8958 // $ adb root
8959 // $ adb shell cmd phone ...
8960 packageName = "root";
8961 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008962 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008963 }
Jack Yueb4124c2017-02-16 15:32:43 -08008964
8965 /**
Grace Chen70990072017-03-24 17:21:30 -07008966 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008967 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008968 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008969 * @param state State of SIM (power down, power up, pass through)
8970 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8971 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8972 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008973 *
8974 **/
8975 @Override
Grace Chen70990072017-03-24 17:21:30 -07008976 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008977 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008978 Phone phone = PhoneFactory.getPhone(slotIndex);
8979
vagdeviaf9a5b92018-08-15 16:01:53 -07008980 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8981
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008982 final long identity = Binder.clearCallingIdentity();
8983 try {
8984 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008985 phone.setSimPowerState(state, null, workSource);
8986 }
8987 } finally {
8988 Binder.restoreCallingIdentity(identity);
8989 }
8990 }
8991
8992 /**
8993 * Set SIM card power state.
8994 *
8995 * @param slotIndex SIM slot id.
8996 * @param state State of SIM (power down, power up, pass through)
8997 * @param callback callback to trigger after success or failure
8998 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8999 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9000 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9001 *
9002 **/
9003 @Override
9004 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9005 IIntegerConsumer callback) {
9006 enforceModifyPermission();
9007 Phone phone = PhoneFactory.getPhone(slotIndex);
9008
9009 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9010
9011 final long identity = Binder.clearCallingIdentity();
9012 try {
9013 if (phone != null) {
9014 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9015 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009016 }
9017 } finally {
9018 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009019 }
9020 }
Shuo Qiandd210312017-04-12 22:11:33 +00009021
Tyler Gunn65d45c22017-06-05 11:22:26 -07009022 private boolean isUssdApiAllowed(int subId) {
9023 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009024 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009025 if (configManager == null) {
9026 return false;
9027 }
9028 PersistableBundle pb = configManager.getConfigForSubId(subId);
9029 if (pb == null) {
9030 return false;
9031 }
9032 return pb.getBoolean(
9033 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9034 }
9035
Shuo Qiandd210312017-04-12 22:11:33 +00009036 /**
Ling Mac28f0212023-03-24 16:07:15 -07009037 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009038 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009039 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009040 */
goneil9c5f4872017-12-05 14:07:56 -08009041 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009042 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009043 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009044 final long identity = Binder.clearCallingIdentity();
9045 try {
Ling Mac28f0212023-03-24 16:07:15 -07009046 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009047 } finally {
9048 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009049 }
9050 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009051
9052 /**
9053 * Get the current signal strength information for the given subscription.
9054 * Because this information is not updated when the device is in a low power state
9055 * it should not be relied-upon to be current.
9056 * @param subId Subscription index
9057 * @return the most recent cached signal strength info from the modem
9058 */
9059 @Override
9060 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009061 final long identity = Binder.clearCallingIdentity();
9062 try {
9063 Phone p = getPhone(subId);
9064 if (p == null) {
9065 return null;
9066 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009067
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009068 return p.getSignalStrength();
9069 } finally {
9070 Binder.restoreCallingIdentity(identity);
9071 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009072 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009073
Pengquan Meng77b7f132018-08-22 14:49:57 -07009074 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009075 * Get the current modem radio state for the given slot.
9076 * @param slotIndex slot index.
9077 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009078 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009079 * @return the current radio power state from the modem
9080 */
9081 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009082 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009083 Phone phone = PhoneFactory.getPhone(slotIndex);
9084 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009085 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9086 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009087 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9088 }
9089
9090 final long identity = Binder.clearCallingIdentity();
9091 try {
9092 return phone.getRadioPowerState();
9093 } finally {
9094 Binder.restoreCallingIdentity(identity);
9095 }
9096 }
9097 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9098 }
9099
9100 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009101 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9102 *
9103 * <p>Requires one of the following permissions:
9104 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009105 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009106 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9107 * privileges.
9108 *
9109 * @param subId subscription id
9110 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9111 * {@code false}.
9112 */
9113 @Override
9114 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009115 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009116 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009117 try {
9118 mApp.enforceCallingOrSelfPermission(
9119 android.Manifest.permission.ACCESS_NETWORK_STATE,
9120 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009121 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009122 mApp.enforceCallingOrSelfPermission(
9123 permission.READ_BASIC_PHONE_STATE, functionName);
9124 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009125 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009126 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009127 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009128 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009129
Pengquan Menga1bb6272018-09-06 09:59:22 -07009130 boolean isEnabled = false;
9131 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009132 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009133 Phone phone = getPhone(subId);
9134 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009135 } finally {
9136 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009137 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009138 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009139 }
9140
9141
9142 /**
9143 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9144 *
9145 * <p> Requires permission:
9146 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9147 * privileges.
9148 *
9149 * @param subId subscription id
9150 * @param isEnabled {@code true} means enable, {@code false} means disable.
9151 */
9152 @Override
9153 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9155 mApp, subId, "setDataRoamingEnabled");
9156
Pengquan Menga1bb6272018-09-06 09:59:22 -07009157 final long identity = Binder.clearCallingIdentity();
9158 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009159 Phone phone = getPhone(subId);
9160 if (phone != null) {
9161 phone.setDataRoamingEnabled(isEnabled);
9162 }
9163 } finally {
9164 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009165 }
9166 }
9167
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009168 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009169 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009170 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009171 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009172 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009173
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009174 boolean isAllowed = true;
9175 final long identity = Binder.clearCallingIdentity();
9176 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009177 Phone phone = getPhone(subId);
9178 if (phone != null) {
9179 isAllowed = phone.isCspPlmnEnabled();
9180 }
9181 } finally {
9182 Binder.restoreCallingIdentity(identity);
9183 }
9184 return isAllowed;
9185 }
9186
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009187 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9188 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009189 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009190 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009191 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009192 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9193 if (phone == null) {
9194 return false;
9195 }
9196 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9197 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9198 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009199 }
9200
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009201 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009202 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009203 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009204 mApp.getSystemService(AppOpsManager.class)
9205 .checkPackage(Binder.getCallingUid(), callingPackage);
9206
Jordan Liu1e142fc2019-04-22 15:10:43 -07009207 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009208 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009209 try {
9210 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009211 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009212 } catch (SecurityException e) {
9213 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9214 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009215 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009216 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009217 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009218 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009219 }
sandeepjsb6c87872021-09-27 15:34:44 +00009220 // checking compatibility, if calling app's target SDK is T and beyond.
9221 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9222 Binder.getCallingUid())) {
9223 isIccIdAccessRestricted = true;
9224 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009225 final long identity = Binder.clearCallingIdentity();
9226 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009227 UiccController uiccController = UiccController.getInstance();
9228 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009229 if (hasReadPermission) {
9230 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009231 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009232
9233 // Remove private info if the caller doesn't have access
9234 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9235 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009236 //setting the value after compatibility check
9237 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009238 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9239 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009240 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009241 if (card == null) {
9242 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009243 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009244 continue;
9245 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009246 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9247 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009248 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009249 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009250 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009251 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9252 for (UiccPortInfo portInfo : portInfos) {
9253 UiccPort port = uiccController.getUiccPortForSlot(
9254 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9255 if (port == null) {
9256 // assume no access if port is null
9257 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9258 continue;
9259 }
9260 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9261 uiccPortInfos.add(portInfo);
9262 } else {
9263 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9264 }
9265 }
9266 filteredInfos.add(new UiccCardInfo(
9267 cardInfo.isEuicc(),
9268 cardInfo.getCardId(),
9269 null,
9270 cardInfo.getPhysicalSlotIndex(),
9271 cardInfo.isRemovable(),
9272 cardInfo.isMultipleEnabledProfilesSupported(),
9273 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009274 }
9275 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009276 } finally {
9277 Binder.restoreCallingIdentity(identity);
9278 }
9279 }
9280
sandeepjsb6c87872021-09-27 15:34:44 +00009281 /**
9282 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9283 * generally private and require carrier privileges to view.
9284 *
9285 * @hide
9286 */
9287 @NonNull
9288 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9289 List<UiccPortInfo> portinfo = new ArrayList<>();
9290 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9291 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9292 }
9293 return new UiccCardInfo(
9294 cardInfo.isEuicc(),
9295 cardInfo.getCardId(),
9296 null,
9297 cardInfo.getPhysicalSlotIndex(),
9298 cardInfo.isRemovable(),
9299 cardInfo.isMultipleEnabledProfilesSupported(),
9300 portinfo
9301 );
9302 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009303
sandeepjsb6c87872021-09-27 15:34:44 +00009304 /**
9305 * @hide
9306 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9307 * These values are generally private and require carrier privileges to view.
9308 */
9309 @NonNull
9310 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9311 return new UiccPortInfo(
9312 UiccPortInfo.ICCID_REDACTED,
9313 portInfo.getPortIndex(),
9314 portInfo.getLogicalSlotIndex(),
9315 portInfo.isActive()
9316 );
9317 }
9318 @Override
9319 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009320 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009321 mApp.getSystemService(AppOpsManager.class)
9322 .checkPackage(Binder.getCallingUid(), callingPackage);
9323
sandeepjsb6c87872021-09-27 15:34:44 +00009324 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009325
Aman Guptaf3c90b32022-03-17 04:54:16 +00009326 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9327 // we are reading iccId which is PII data.
9328 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009329
9330 // checking compatibility, if calling app's target SDK is T and beyond.
9331 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9332 Binder.getCallingUid())) {
9333 isLogicalSlotAccessRestricted = true;
9334 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009335 final long identity = Binder.clearCallingIdentity();
9336 try {
9337 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009338 if (slots == null || slots.length == 0) {
9339 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009340 return null;
9341 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009342 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9343 for (int i = 0; i < slots.length; i++) {
9344 UiccSlot slot = slots[i];
9345 if (slot == null) {
9346 continue;
9347 }
9348
Jordan Liu7be7e652019-05-06 18:55:02 +00009349 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009350 UiccCard card = slot.getUiccCard();
9351 if (card != null) {
9352 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009353 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009354 cardId = slot.getEid();
9355 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009356 // If cardId is null, use iccId of default port as cardId.
9357 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009358 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009359 }
9360
Jordan Liu857451f2019-05-09 16:35:35 -07009361 if (cardId != null) {
9362 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9363 // if cardId is an EID, it's all digits so this is fine
9364 cardId = IccUtils.stripTrailingFs(cardId);
9365 }
9366
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009367 int cardState = 0;
9368 switch (slot.getCardState()) {
9369 case CARDSTATE_ABSENT:
9370 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9371 break;
9372 case CARDSTATE_PRESENT:
9373 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9374 break;
9375 case CARDSTATE_ERROR:
9376 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9377 break;
9378 case CARDSTATE_RESTRICTED:
9379 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9380 break;
9381 default:
9382 break;
9383
9384 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009385 List<UiccPortInfo> portInfos = new ArrayList<>();
9386 int[] portIndexes = slot.getPortList();
9387 for (int portIdx : portIndexes) {
9388 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009389 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009390 portInfos.add(new UiccPortInfo(iccId, portIdx,
9391 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009392 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009393 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009394 slot.isEuicc(),
9395 cardId,
9396 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009397 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009398 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009399 //setting the value after compatibility check
9400 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009401 }
9402 return infos;
9403 } finally {
9404 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009405 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009406 }
9407
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009408 /* Returns null if doesn't have read permission or carrier privilege access. */
9409 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9410 boolean hasReadPermission) {
9411 String iccId = slot.getIccId(portIndex);
9412 if (hasReadPermission) { // if has read permission
9413 return iccId;
9414 } else {
9415 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9416 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9417 // if no read permission, checking carrier privilege access
9418 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9419 return iccId;
9420 }
9421 }
9422 }
9423 // No read permission or carrier privilege access.
9424 return UiccPortInfo.ICCID_REDACTED;
9425 }
9426
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009427 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009428 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009429 public boolean switchSlots(int[] physicalSlots) {
9430 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009431
9432 final long identity = Binder.clearCallingIdentity();
9433 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009434 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9435 for (int i = 0; i < physicalSlots.length; i++) {
9436 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9437 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9438 physicalSlots[i], i));
9439 }
9440 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009441 } finally {
9442 Binder.restoreCallingIdentity(identity);
9443 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009444 }
Jack Yu4c988042018-02-27 15:30:01 -08009445
9446 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009447 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9448 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9449 enforceModifyPermission();
9450
9451 final long identity = Binder.clearCallingIdentity();
9452 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009453 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009454 } finally {
9455 Binder.restoreCallingIdentity(identity);
9456 }
9457 }
9458
9459 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009460 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009461 final long identity = Binder.clearCallingIdentity();
9462 try {
9463 return UiccController.getInstance().getCardIdForDefaultEuicc();
9464 } finally {
9465 Binder.restoreCallingIdentity(identity);
9466 }
9467 }
9468
Pengquan Meng85728fb2018-03-12 16:31:21 -07009469 /**
goneil47ffb6e2018-04-06 15:40:58 -07009470 * A test API to reload the UICC profile.
9471 *
9472 * <p>Requires that the calling app has permission
9473 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9474 * @hide
9475 */
9476 @Override
9477 public void refreshUiccProfile(int subId) {
9478 enforceModifyPermission();
9479
9480 final long identity = Binder.clearCallingIdentity();
9481 try {
9482 Phone phone = getPhone(subId);
9483 if (phone == null) {
9484 return;
9485 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009486 UiccPort uiccPort = phone.getUiccPort();
9487 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009488 return;
9489 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009490 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009491 if (uiccProfile == null) {
9492 return;
9493 }
9494 uiccProfile.refresh();
9495 } finally {
9496 Binder.restoreCallingIdentity(identity);
9497 }
9498 }
9499
9500 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009501 * Returns false if the mobile data is disabled by default, otherwise return true.
9502 */
9503 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009504 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009505 }
9506
9507 /**
9508 * Returns true if the data roaming is enabled by default, i.e the system property
9509 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9510 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9511 */
9512 private boolean getDefaultDataRoamingEnabled(int subId) {
9513 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009514 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009515 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009516 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9517 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9518 return isDataRoamingEnabled;
9519 }
9520
9521 /**
9522 * Returns the default network type for the given {@code subId}, if the default network type is
9523 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9524 */
9525 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009526 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009527 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009528 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9529 return list.get(phoneId);
9530 }
9531 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009532 }
fionaxua13278b2018-03-21 00:08:13 -07009533
9534 @Override
9535 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009536 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009537 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009538
9539 final long identity = Binder.clearCallingIdentity();
9540 try {
9541 final Phone phone = getPhone(subId);
9542 if (phone == null) {
9543 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9544 return;
9545 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009546 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9547 if (cpt != null) {
9548 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9549 }
9550 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009551 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9552 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009553 if (carrierPrivilegeRules == null) {
9554 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9555 } else {
9556 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9557 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009558 } finally {
9559 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009560 }
fionaxua13278b2018-03-21 00:08:13 -07009561 }
9562
9563 @Override
Benedict Wong66477622023-02-03 23:30:57 +00009564 public void setCarrierServicePackageOverride(
9565 int subId, String carrierServicePackage, String callingPackage) {
9566 TelephonyPermissions.enforceShellOnly(
9567 Binder.getCallingUid(), "setCarrierServicePackageOverride");
9568
9569 // Verify that the callingPackage belongs to the calling UID
9570 mApp.getSystemService(AppOpsManager.class)
9571 .checkPackage(Binder.getCallingUid(), callingPackage);
9572
9573 final long identity = Binder.clearCallingIdentity();
9574 try {
9575 final Phone phone = getPhone(subId);
9576 if (phone == null || phone.getSubId() != subId) {
9577 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
9578 throw new IllegalArgumentException("No phone for subid");
9579 }
9580 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9581 if (cpt == null) {
9582 loge("setCarrierServicePackageOverride failed with no CPT for phone");
9583 throw new IllegalStateException("No CPT for phone");
9584 }
9585 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
9586 } finally {
9587 Binder.restoreCallingIdentity(identity);
9588 }
9589 }
9590
9591 @Override
fionaxua13278b2018-03-21 00:08:13 -07009592 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009593 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009594
9595 final long identity = Binder.clearCallingIdentity();
9596 try {
9597 final Phone phone = getPhone(subId);
9598 if (phone == null) {
9599 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9600 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9601 }
9602 return phone.getCarrierIdListVersion();
9603 } finally {
9604 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009605 }
fionaxua13278b2018-03-21 00:08:13 -07009606 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009607
9608 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009609 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9610 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009611 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009612 mApp, subId, callingPackage, callingFeatureId,
9613 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009614 return -1;
9615 }
9616
9617 final long identity = Binder.clearCallingIdentity();
9618 try {
9619 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9620 } finally {
9621 Binder.restoreCallingIdentity(identity);
9622 }
9623 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009624
9625 @Override
9626 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009627 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009628 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009629 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -07009630
9631 final long identity = Binder.clearCallingIdentity();
9632 try {
9633 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9634 } finally {
9635 Binder.restoreCallingIdentity(identity);
9636 }
9637 }
9638
9639 @Override
9640 public boolean setCdmaRoamingMode(int subId, int mode) {
9641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9642 mApp, subId, "setCdmaRoamingMode");
9643
9644 final long identity = Binder.clearCallingIdentity();
9645 try {
9646 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9647 } finally {
9648 Binder.restoreCallingIdentity(identity);
9649 }
9650 }
9651
9652 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009653 public int getCdmaSubscriptionMode(int subId) {
9654 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009655 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009656 mApp, subId, "getCdmaSubscriptionMode");
9657
9658 final long identity = Binder.clearCallingIdentity();
9659 try {
9660 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9661 } finally {
9662 Binder.restoreCallingIdentity(identity);
9663 }
9664 }
9665
9666 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009667 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9668 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9669 mApp, subId, "setCdmaSubscriptionMode");
9670
9671 final long identity = Binder.clearCallingIdentity();
9672 try {
9673 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9674 } finally {
9675 Binder.restoreCallingIdentity(identity);
9676 }
9677 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009678
sqianc5eccab2018-10-19 18:46:41 -07009679 @Override
sqian8c685422019-02-22 15:55:18 -08009680 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009681 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009682 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009683 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9684 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009685 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9686 }
9687 final long identity = Binder.clearCallingIdentity();
9688 try {
sqian854d44b2018-12-12 16:48:18 -08009689 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9690 for (Phone phone: PhoneFactory.getPhones()) {
9691 if (phone.getEmergencyNumberTracker() != null
9692 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9693 emergencyNumberListInternal.put(
9694 phone.getSubId(),
9695 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9696 }
sqian11b7a0e2018-12-05 18:48:28 -08009697 }
sqian854d44b2018-12-12 16:48:18 -08009698 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009699 } finally {
9700 Binder.restoreCallingIdentity(identity);
9701 }
sqianc5eccab2018-10-19 18:46:41 -07009702 }
9703
9704 @Override
sqian8c685422019-02-22 15:55:18 -08009705 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009706 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009707 if (!exactMatch) {
9708 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009709 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009710 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009711 }
9712 final long identity = Binder.clearCallingIdentity();
9713 try {
sqian854d44b2018-12-12 16:48:18 -08009714 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009715 //Note: we ignore passed in param exactMatch. We can remove it once
9716 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009717 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009718 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009719 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009720 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009721 }
sqian11b7a0e2018-12-05 18:48:28 -08009722 }
9723 return false;
9724 } finally {
9725 Binder.restoreCallingIdentity(identity);
9726 }
9727 }
9728
sqianf4ca7ed2019-01-15 18:32:07 -08009729 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009730 * Start emergency callback mode for GsmCdmaPhone for testing.
9731 */
9732 @Override
9733 public void startEmergencyCallbackMode() {
9734 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9735 "startEmergencyCallbackMode");
9736 enforceModifyPermission();
9737 final long identity = Binder.clearCallingIdentity();
9738 try {
9739 for (Phone phone : PhoneFactory.getPhones()) {
9740 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9741 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9742 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9743 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9744 gsmCdmaPhone.obtainMessage(
9745 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9746 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9747 }
9748 }
9749 } finally {
9750 Binder.restoreCallingIdentity(identity);
9751 }
9752 }
9753
9754 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009755 * Update emergency number list for test mode.
9756 */
9757 @Override
9758 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9759 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9760 "updateEmergencyNumberListTestMode");
9761
9762 final long identity = Binder.clearCallingIdentity();
9763 try {
9764 for (Phone phone: PhoneFactory.getPhones()) {
9765 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9766 if (tracker != null) {
9767 tracker.executeEmergencyNumberTestModeCommand(action, num);
9768 }
9769 }
9770 } finally {
9771 Binder.restoreCallingIdentity(identity);
9772 }
9773 }
9774
9775 /**
9776 * Get the full emergency number list for test mode.
9777 */
9778 @Override
9779 public List<String> getEmergencyNumberListTestMode() {
9780 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9781 "getEmergencyNumberListTestMode");
9782
9783 final long identity = Binder.clearCallingIdentity();
9784 try {
9785 Set<String> emergencyNumbers = new HashSet<>();
9786 for (Phone phone: PhoneFactory.getPhones()) {
9787 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9788 if (tracker != null) {
9789 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9790 emergencyNumbers.add(num.getNumber());
9791 }
9792 }
9793 }
9794 return new ArrayList<>(emergencyNumbers);
9795 } finally {
9796 Binder.restoreCallingIdentity(identity);
9797 }
9798 }
9799
chen xud6b45bd2018-10-30 22:27:10 -07009800 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009801 public int getEmergencyNumberDbVersion(int subId) {
9802 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9803
9804 final long identity = Binder.clearCallingIdentity();
9805 try {
9806 final Phone phone = getPhone(subId);
9807 if (phone == null) {
9808 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9809 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9810 }
9811 return phone.getEmergencyNumberDbVersion();
9812 } finally {
9813 Binder.restoreCallingIdentity(identity);
9814 }
9815 }
9816
9817 @Override
9818 public void notifyOtaEmergencyNumberDbInstalled() {
9819 enforceModifyPermission();
9820
9821 final long identity = Binder.clearCallingIdentity();
9822 try {
9823 for (Phone phone: PhoneFactory.getPhones()) {
9824 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9825 if (tracker != null) {
9826 tracker.updateOtaEmergencyNumberDatabase();
9827 }
9828 }
9829 } finally {
9830 Binder.restoreCallingIdentity(identity);
9831 }
9832 }
9833
9834 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009835 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009836 enforceActiveEmergencySessionPermission();
9837
9838 final long identity = Binder.clearCallingIdentity();
9839 try {
9840 for (Phone phone: PhoneFactory.getPhones()) {
9841 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9842 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009843 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9844 }
9845 }
9846 } finally {
9847 Binder.restoreCallingIdentity(identity);
9848 }
9849 }
9850
9851 @Override
9852 public void resetOtaEmergencyNumberDbFilePath() {
9853 enforceActiveEmergencySessionPermission();
9854
9855 final long identity = Binder.clearCallingIdentity();
9856 try {
9857 for (Phone phone: PhoneFactory.getPhones()) {
9858 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9859 if (tracker != null) {
9860 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009861 }
9862 }
9863 } finally {
9864 Binder.restoreCallingIdentity(identity);
9865 }
9866 }
9867
9868 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009869 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9870 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9871 Phone phone = getPhone(subId);
9872 if (phone == null) {
9873 return null;
9874 }
9875 final long identity = Binder.clearCallingIdentity();
9876 try {
9877 UiccProfile profile = UiccController.getInstance()
9878 .getUiccProfileForPhone(phone.getPhoneId());
9879 if (profile != null) {
9880 return profile.getCertsFromCarrierPrivilegeAccessRules();
9881 }
9882 } finally {
9883 Binder.restoreCallingIdentity(identity);
9884 }
9885 return null;
9886 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009887
9888 /**
9889 * Enable or disable a modem stack.
9890 */
9891 @Override
9892 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9893 enforceModifyPermission();
9894
9895 final long identity = Binder.clearCallingIdentity();
9896 try {
9897 Phone phone = PhoneFactory.getPhone(slotIndex);
9898 if (phone == null) {
9899 return false;
9900 } else {
9901 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9902 }
9903 } finally {
9904 Binder.restoreCallingIdentity(identity);
9905 }
9906 }
Michelecea4cf22018-12-21 15:00:11 -08009907
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009908 /**
9909 * Whether a modem stack is enabled or not.
9910 */
9911 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009912 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9913 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009914 Phone phone = PhoneFactory.getPhone(slotIndex);
9915 if (phone == null) return false;
9916
9917 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009918 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9919 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009920 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9921 }
9922
9923 final long identity = Binder.clearCallingIdentity();
9924 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009925 try {
9926 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9927 } catch (NoSuchElementException ex) {
9928 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9929 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009930 } finally {
9931 Binder.restoreCallingIdentity(identity);
9932 }
9933 }
9934
Michelecea4cf22018-12-21 15:00:11 -08009935 @Override
Michele0ea7d782019-03-19 14:58:42 -07009936 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009937 enforceModifyPermission();
9938
9939 final long identity = Binder.clearCallingIdentity();
9940 try {
9941 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009942 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009943 .commit();
9944 } finally {
9945 Binder.restoreCallingIdentity(identity);
9946 }
9947 }
9948
9949 @Override
Michele0ea7d782019-03-19 14:58:42 -07009950 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009951 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009952 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009953 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9954 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009955 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009956 }
Michelecea4cf22018-12-21 15:00:11 -08009957
9958 final long identity = Binder.clearCallingIdentity();
9959 try {
Michele0ea7d782019-03-19 14:58:42 -07009960 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009961 } finally {
9962 Binder.restoreCallingIdentity(identity);
9963 }
9964 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009965
Michele0ea7d782019-03-19 14:58:42 -07009966 @TelephonyManager.IsMultiSimSupportedResult
9967 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009968 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9969 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9970 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009971 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9972 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009973 }
9974 // Check if the hardware supports multisim functionality. If usage of multisim is not
9975 // supported by the modem, indicate that it is restricted.
9976 PhoneCapability staticCapability =
9977 mPhoneConfigurationManager.getStaticPhoneCapability();
9978 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009979 loge("isMultiSimSupportedInternal: no static configuration available");
9980 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009981 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009982 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009983 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9984 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009985 }
9986 // Check if support of multiple SIMs is restricted by carrier
9987 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009988 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009989 }
9990
Michele0ea7d782019-03-19 14:58:42 -07009991 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009992 }
9993
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009994 /**
9995 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009996 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9997 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9998 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009999 * @param numOfSims number of active sims we want to switch to
10000 */
10001 @Override
10002 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010003 if (numOfSims == 1) {
10004 enforceModifyPermission();
10005 } else {
10006 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10007 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10008 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010009 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010010
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010011 try {
Michele30b57b22019-03-01 12:01:14 -080010012 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010013 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010014 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10015 return;
10016 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010017 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10018 } finally {
10019 Binder.restoreCallingIdentity(identity);
10020 }
10021 }
10022
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010023 @Override
10024 public boolean isApplicationOnUicc(int subId, int appType) {
10025 enforceReadPrivilegedPermission("isApplicationOnUicc");
10026 Phone phone = getPhone(subId);
10027 if (phone == null) {
10028 return false;
10029 }
10030 final long identity = Binder.clearCallingIdentity();
10031 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010032 UiccPort uiccPort = phone.getUiccPort();
10033 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010034 return false;
10035 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010036 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010037 if (uiccProfile == null) {
10038 return false;
10039 }
10040 if (TelephonyManager.APPTYPE_SIM <= appType
10041 && appType <= TelephonyManager.APPTYPE_ISIM) {
10042 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10043 }
10044 return false;
10045 } finally {
10046 Binder.restoreCallingIdentity(identity);
10047 }
10048 }
10049
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010050 /**
chen xub4baa772019-04-03 10:23:41 -070010051 * Get whether making changes to modem configurations will trigger reboot.
10052 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010053 */
10054 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010055 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10056 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010057 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010058 mApp, subId, callingPackage, callingFeatureId,
10059 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010060 return false;
10061 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010062 final long identity = Binder.clearCallingIdentity();
10063 try {
10064 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10065 } finally {
10066 Binder.restoreCallingIdentity(identity);
10067 }
10068 }
10069
Nathan Harold29f5f052019-02-15 13:41:57 -080010070 private void updateModemStateMetrics() {
10071 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10072 // TODO: check the state for each modem if the api is ready.
10073 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10074 }
10075
Pengquan Meng3889a572019-01-23 11:16:29 -080010076 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010077 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010078 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010079 // Verify that the callingPackage belongs to the calling UID
10080 mApp.getSystemService(AppOpsManager.class)
10081 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010082 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010083 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010084 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010085 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10086 if (slotInfos != null) {
10087 for (int i = 0; i < slotInfos.length; i++) {
10088 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10089 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10090 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10091 portInfo.getLogicalSlotIndex()));
10092 }
10093 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010094 }
10095 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010096 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010097 } finally {
10098 Binder.restoreCallingIdentity(identity);
10099 }
10100 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010101
10102 /**
10103 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010104 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010105 */
jimsunf9ec1622022-09-13 21:18:43 +080010106 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010107 @Override
10108 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010109 return getHalVersion(HAL_SERVICE_RADIO);
10110 }
10111
10112 /**
10113 * Get the HAL Version of a specific service
10114 */
10115 @Override
10116 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010117 Phone phone = getDefaultPhone();
10118 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010119 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010120 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10121 return hv.major * 100 + hv.minor;
10122 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010123
10124 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010125 * Get the current calling package name.
10126 * @return the current calling package name
10127 */
10128 @Override
10129 public String getCurrentPackageName() {
10130 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10131 }
10132
10133 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010134 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10135 * corresponding network requests on a subId.
10136 *
10137 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010138 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010139 * 2) APN is un-metered for this subscription, or
10140 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010141 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010142 *
10143 * @return whether data is allowed for a apn type.
10144 *
10145 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010146 */
10147 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010148 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010149 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10150 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010151
10152 // Now that all security checks passes, perform the operation as ourselves.
10153 final long identity = Binder.clearCallingIdentity();
10154 try {
10155 Phone phone = getPhone(subId);
10156 if (phone == null) return false;
10157
Jack Yu27422a52022-03-21 10:38:05 -070010158 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010159 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010160 isMetered = phone.getDataNetworkController().getDataConfigManager()
10161 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10162 phone.getServiceState().getDataRoaming());
10163 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010164 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010165 } finally {
10166 Binder.restoreCallingIdentity(identity);
10167 }
10168 }
10169
10170 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010171 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010172 enforceReadPrivilegedPermission("isApnMetered");
10173
10174 // Now that all security checks passes, perform the operation as ourselves.
10175 final long identity = Binder.clearCallingIdentity();
10176 try {
10177 Phone phone = getPhone(subId);
10178 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010179 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10180 DataUtils.apnTypeToNetworkCapability(apnType),
10181 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010182 } finally {
10183 Binder.restoreCallingIdentity(identity);
10184 }
10185 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010186
10187 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010188 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10189 int subscriptionId, IBooleanConsumer resultCallback) {
10190 enforceModifyPermission();
10191 long token = Binder.clearCallingIdentity();
10192 try {
10193 Phone phone = getPhone(subscriptionId);
10194 if (phone == null) {
10195 try {
10196 if (resultCallback != null) {
10197 resultCallback.accept(false);
10198 }
10199 } catch (RemoteException e) {
10200 // ignore
10201 }
10202 return;
10203 }
10204 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10205 Pair.create(specifiers, (x) -> {
10206 try {
10207 if (resultCallback != null) {
10208 resultCallback.accept(x);
10209 }
10210 } catch (RemoteException e) {
10211 // ignore
10212 }
10213 });
10214 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10215 } finally {
10216 Binder.restoreCallingIdentity(token);
10217 }
10218 }
10219
10220 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010221 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10222 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010223 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010224 mApp, subId, "getSystemSelectionChannels");
10225 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10226 final long identity = Binder.clearCallingIdentity();
10227 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010228 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10229 if (result instanceof IllegalStateException) {
10230 throw (IllegalStateException) result;
10231 }
10232 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010233 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10234 return specifiers;
10235 } finally {
10236 Binder.restoreCallingIdentity(identity);
10237 }
10238 }
10239
10240 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010241 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010242 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010243 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010244 }
10245
10246 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010247 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10248 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010249 if (callingPackage == null) {
10250 callingPackage = getCurrentPackageName();
10251 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010252 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10253 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010254 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10255 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010256 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10257 }
10258 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10259 Intent intent = new Intent();
10260 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10261 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10262 // Bring up choose default SMS subscription dialog right now
10263 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10264 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10265 mApp.startActivity(intent);
10266 }
chen xud5ca2d52019-05-28 15:20:57 -070010267
10268 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010269 public void showSwitchToManagedProfileDialog() {
10270 enforceModifyPermission();
10271
10272 Intent intent = new Intent();
10273 intent.setClass(mApp, ErrorDialogActivity.class);
10274 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10275 mApp.startActivity(intent);
10276 }
10277
10278 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010279 public String getMmsUAProfUrl(int subId) {
10280 //TODO investigate if this API should require proper permission check in R b/133791609
10281 final long identity = Binder.clearCallingIdentity();
10282 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010283 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10284 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10285 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10286 return carrierUAProfUrl;
10287 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010288 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10289 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010290 } finally {
10291 Binder.restoreCallingIdentity(identity);
10292 }
10293 }
10294
10295 @Override
10296 public String getMmsUserAgent(int subId) {
10297 //TODO investigate if this API should require proper permission check in R b/133791609
10298 final long identity = Binder.clearCallingIdentity();
10299 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010300 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10301 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10302 if (!TextUtils.isEmpty(carrierUserAgent)) {
10303 return carrierUserAgent;
10304 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010305 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10306 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010307 } finally {
10308 Binder.restoreCallingIdentity(identity);
10309 }
10310 }
Jack Yub07d4972019-05-28 16:12:25 -070010311
10312 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010313 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10314 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010315
Jack Yub07d4972019-05-28 16:12:25 -070010316 final long identity = Binder.clearCallingIdentity();
10317 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010318 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010319 if (phone == null) return false;
10320
Ling Maf188d502022-09-16 15:22:36 -070010321 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010322 } finally {
10323 Binder.restoreCallingIdentity(identity);
10324 }
10325 }
10326
10327 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010328 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010329 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010330 enforceModifyPermission();
10331
changbettyd5c246e2019-12-24 15:40:37 +080010332 final long identity = Binder.clearCallingIdentity();
10333 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010334 Phone phone = getPhone(subscriptionId);
10335 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010336
Ling Maf188d502022-09-16 15:22:36 -070010337 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010338 } finally {
10339 Binder.restoreCallingIdentity(identity);
10340 }
10341 }
10342
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010343 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010344 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010345 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10346 * otherwise.
10347 */
10348 @Override
10349 public void setCepEnabled(boolean isCepEnabled) {
10350 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10351
10352 final long identity = Binder.clearCallingIdentity();
10353 try {
10354 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10355 for (Phone phone : PhoneFactory.getPhones()) {
10356 Phone defaultPhone = phone.getImsPhone();
10357 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10358 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10359 ImsPhoneCallTracker imsPhoneCallTracker =
10360 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10361 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10362 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10363 + imsPhone.getMsisdn());
10364 }
10365 }
10366 } finally {
10367 Binder.restoreCallingIdentity(identity);
10368 }
10369 }
allenwtsu46dcc572020-01-08 18:24:03 +080010370
10371 /**
10372 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10373 *
10374 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10375 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10376 * before being read.
10377 */
10378 @Override
10379 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10380 isCompressed) {
10381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10382 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010383 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10384 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10385 }
10386 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010387 // ProvisioningManager can not handle ServiceSpecificException.
10388 // Throw the IllegalStateException and annotate ProvisioningManager.
10389 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010390 }
10391
10392 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010393 try {
Hui Wang761a6682020-10-31 05:12:53 +000010394 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10395 } finally {
10396 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010397 }
10398 }
zoey chene02881a2019-12-30 16:11:23 +080010399
10400 @Override
10401 public boolean isIccLockEnabled(int subId) {
10402 enforceReadPrivilegedPermission("isIccLockEnabled");
10403
10404 // Now that all security checks passes, perform the operation as ourselves.
10405 final long identity = Binder.clearCallingIdentity();
10406 try {
10407 Phone phone = getPhone(subId);
10408 if (phone != null && phone.getIccCard() != null) {
10409 return phone.getIccCard().getIccLockEnabled();
10410 } else {
10411 return false;
10412 }
10413 } finally {
10414 Binder.restoreCallingIdentity(identity);
10415 }
10416 }
10417
10418 /**
10419 * Set the ICC pin lock enabled or disabled.
10420 *
10421 * @return an integer representing the status of IccLock enabled or disabled in the following
10422 * three cases:
10423 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10424 * successfully.
10425 * - Positive number and zero for remaining password attempts.
10426 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10427 *
10428 */
10429 @Override
10430 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10431 enforceModifyPermission();
10432
10433 Phone phone = getPhone(subId);
10434 if (phone == null) {
10435 return 0;
10436 }
10437 // Now that all security checks passes, perform the operation as ourselves.
10438 final long identity = Binder.clearCallingIdentity();
10439 try {
10440 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10441 new Pair<Boolean, String>(enabled, password), phone, null);
10442 return attemptsRemaining;
10443
10444 } catch (Exception e) {
10445 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10446 } finally {
10447 Binder.restoreCallingIdentity(identity);
10448 }
10449 return 0;
10450 }
10451
10452 /**
10453 * Change the ICC password used in ICC pin lock.
10454 *
10455 * @return an integer representing the status of IccLock changed in the following three cases:
10456 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10457 * - Positive number and zero for remaining password attempts.
10458 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10459 *
10460 */
10461 @Override
10462 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10463 enforceModifyPermission();
10464
10465 Phone phone = getPhone(subId);
10466 if (phone == null) {
10467 return 0;
10468 }
10469 // Now that all security checks passes, perform the operation as ourselves.
10470 final long identity = Binder.clearCallingIdentity();
10471 try {
10472 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10473 new Pair<String, String>(oldPassword, newPassword), phone, null);
10474 return attemptsRemaining;
10475
10476 } catch (Exception e) {
10477 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10478 } finally {
10479 Binder.restoreCallingIdentity(identity);
10480 }
10481 return 0;
10482 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010483
10484 /**
10485 * Request for receiving user activity notification
10486 */
10487 @Override
10488 public void requestUserActivityNotification() {
10489 if (!mNotifyUserActivity.get()
10490 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10491 mNotifyUserActivity.set(true);
10492 }
10493 }
10494
10495 /**
10496 * Called when userActivity is signalled in the power manager.
10497 * This is safe to call from any thread, with any window manager locks held or not.
10498 */
10499 @Override
10500 public void userActivity() {
10501 // ***************************************
10502 // * Inherited from PhoneWindowManager *
10503 // ***************************************
10504 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10505 // WITH ITS LOCKS HELD.
10506 //
10507 // This code must be VERY careful about the locks
10508 // it acquires.
10509 // In fact, the current code acquires way too many,
10510 // and probably has lurking deadlocks.
10511
10512 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10513 throw new SecurityException("Only the OS may call notifyUserActivity()");
10514 }
10515
10516 if (mNotifyUserActivity.getAndSet(false)) {
10517 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10518 USER_ACTIVITY_NOTIFICATION_DELAY);
10519 }
10520 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010521
10522 @Override
10523 public boolean canConnectTo5GInDsdsMode() {
10524 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10525 }
Jack Yud10cdd42020-09-28 20:28:01 -070010526
10527 @Override
10528 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10529 String callingFeatureId) {
10530 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10531 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10532 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10533 }
10534
10535 Phone phone = getPhone(subId);
10536 if (phone == null) {
10537 throw new RuntimeException("phone is not available");
10538 }
10539 // Now that all security checks passes, perform the operation as ourselves.
10540 final long identity = Binder.clearCallingIdentity();
10541 try {
10542 return phone.getEquivalentHomePlmns();
10543 } finally {
10544 Binder.restoreCallingIdentity(identity);
10545 }
10546 }
Daniel Bright59e67312020-11-13 11:49:37 -080010547
10548 @Override
10549 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010550 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10551 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010552 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010553 if (radioInterfaceCapabilities == null) {
10554 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010555 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010556 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010557 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010558
Hui Wang641e81c2020-10-12 12:14:23 -070010559 @Override
10560 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10561 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010562 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10563 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10564 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10565 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10566 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010567 if (DBG) {
10568 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10569 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10570 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10571 }
10572
10573 if (!SubscriptionManager.isValidSubscriptionId(subId)
10574 || appType < TelephonyManager.APPTYPE_UNKNOWN
10575 || appType > TelephonyManager.APPTYPE_ISIM
10576 || nafUrl == null || securityProtocol == null || callback == null) {
10577 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10578 if (callback != null) {
10579 try {
10580 callback.onAuthenticationFailure(
10581 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10582 } catch (RemoteException exception) {
10583 log("Fail to notify onAuthenticationFailure due to " + exception);
10584 }
10585 return;
10586 }
10587 }
10588
10589 final long token = Binder.clearCallingIdentity();
10590 try {
10591 getGbaManager(subId).bootstrapAuthenticationRequest(
10592 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010593 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070010594 } finally {
10595 Binder.restoreCallingIdentity(token);
10596 }
10597 }
10598
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010599 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010600 * Attempts to set the radio power state for all phones for thermal reason.
10601 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010602 * requested radio power state will actually be set. See {@link
10603 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10604 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010605 * @param enable {@code true} if trying to turn radio on.
10606 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10607 * false}.
10608 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010609 private boolean setRadioPowerForThermal(boolean enable) {
10610 boolean isPhoneAvailable = false;
10611 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10612 Phone phone = PhoneFactory.getPhone(i);
10613 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010614 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010615 isPhoneAvailable = true;
10616 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010617 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010618
10619 // return true if successfully informed the phone object about the thermal radio power
10620 // request.
10621 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010622 }
10623
10624 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010625 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010626 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10627 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10628 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10629 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10630 throw new IllegalArgumentException("modem does not support data throttling");
10631 }
10632
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010633 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10634 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010635 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010636 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10637 }
10638
Sarah Chinecc78c42022-03-31 21:16:48 -070010639 setDataEnabledForReason(
10640 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010641
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010642 if (isDataThrottlingSupported) {
10643 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010644 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010645 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10646 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10647 } else if (thermalMitigationResult
10648 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010649 log("Modem likely does not support data throttling on secondary carrier. Data " +
10650 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10651 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010652 }
10653 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010654 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010655
10656 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010657 }
10658
Jack Nudelman644b91a2021-03-12 14:09:48 -080010659 private static List<String> getThermalMitigationAllowlist(Context context) {
10660 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10661 for (String pckg : context.getResources()
10662 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10663 sThermalMitigationAllowlistedPackages.add(pckg);
10664 }
10665 }
10666
10667 return sThermalMitigationAllowlistedPackages;
10668 }
10669
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010670 private boolean isAnyPhoneInEmergencyState() {
10671 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10672 if (tm.isInEmergencyCall()) {
10673 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10674 return true;
10675 }
10676 for (Phone phone : PhoneFactory.getPhones()) {
10677 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10678 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010679 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10680 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010681 return true;
10682 }
10683 }
10684
10685 return false;
10686 }
10687
Jack Nudelman644b91a2021-03-12 14:09:48 -080010688 /**
10689 * Used by shell commands to add an authorized package name for thermal mitigation.
10690 * @param packageName name of package to be allowlisted
10691 * @param context
10692 */
10693 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10694 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10695 sThermalMitigationAllowlistedPackages.add(packageName);
10696 }
10697
10698 /**
10699 * Used by shell commands to remove an authorized package name for thermal mitigation.
10700 * @param packageName name of package to remove from allowlist
10701 * @param context
10702 */
10703 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10704 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10705 sThermalMitigationAllowlistedPackages.remove(packageName);
10706 }
10707
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010708 /**
10709 * Thermal mitigation request to control functionalities at modem.
10710 *
10711 * @param subId the id of the subscription.
10712 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010713 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010714 *
10715 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10716 */
10717 @Override
10718 @ThermalMitigationResult
10719 public int sendThermalMitigationRequest(
10720 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010721 ThermalMitigationRequest thermalMitigationRequest,
10722 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010723 enforceModifyPermission();
10724
Jack Nudelman644b91a2021-03-12 14:09:48 -080010725 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10726 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10727 .contains(callingPackage)) {
10728 throw new SecurityException("Calling package must be configured in the device config. "
10729 + "calling package: " + callingPackage);
10730 }
10731
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010732 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10733 final long identity = Binder.clearCallingIdentity();
10734
10735 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10736 try {
10737 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10738 switch (thermalMitigationAction) {
10739 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10740 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010741 handleDataThrottlingRequest(subId,
10742 thermalMitigationRequest.getDataThrottlingRequest(),
10743 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010744 break;
10745 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10746 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10747 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10748 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10749 }
10750
10751 // Ensure that radio is on. If not able to power on due to phone being
10752 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010753 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010754 thermalMitigationResult =
10755 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10756 break;
10757 }
10758
10759 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010760 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010761 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10762 break;
10763 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10764 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10765 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10766 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10767 }
10768
10769 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10770 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010771 Phone phone = getPhone(subId);
10772 if (phone == null) {
10773 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010774 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010775 break;
10776 }
10777
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010778 TelephonyConnectionService service =
10779 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010780 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010781 Log.e(LOG_TAG, "An emergency call is pending");
10782 thermalMitigationResult =
10783 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10784 break;
10785 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010786 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010787 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010788 break;
10789 }
10790 } else {
10791 thermalMitigationResult =
10792 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10793 break;
10794 }
10795
10796 // Turn radio off. If not able to power off due to phone being unavailable,
10797 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010798 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010799 thermalMitigationResult =
10800 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10801 break;
10802 }
10803 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010804 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010805 break;
10806 default:
10807 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10808 + "not exist. Requested action: " + thermalMitigationAction);
10809 }
10810 } catch (IllegalArgumentException e) {
10811 throw e;
10812 } catch (Exception e) {
10813 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10814 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10815 } finally {
10816 Binder.restoreCallingIdentity(identity);
10817 }
10818
10819 if (DBG) {
10820 log("thermalMitigationRequest returning with thermalMitigationResult: "
10821 + thermalMitigationResult);
10822 }
10823
10824 return thermalMitigationResult;
10825 }
Hui Wang641e81c2020-10-12 12:14:23 -070010826
10827 /**
10828 * Set the GbaService Package Name that Telephony will bind to.
10829 *
10830 * @param subId The sim that the GbaService is associated with.
10831 * @param packageName The name of the package to be replaced with.
10832 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10833 */
10834 @Override
10835 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10836 enforceModifyPermission();
10837
10838 final long identity = Binder.clearCallingIdentity();
10839 try {
10840 return getGbaManager(subId).overrideServicePackage(packageName);
10841 } finally {
10842 Binder.restoreCallingIdentity(identity);
10843 }
10844 }
10845
10846 /**
10847 * Return the package name of the currently bound GbaService.
10848 *
10849 * @param subId The sim that the GbaService is associated with.
10850 * @return the package name of the GbaService configuration, null if GBA is not supported.
10851 */
10852 @Override
10853 public String getBoundGbaService(int subId) {
10854 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10855
10856 final long identity = Binder.clearCallingIdentity();
10857 try {
10858 return getGbaManager(subId).getServicePackage();
10859 } finally {
10860 Binder.restoreCallingIdentity(identity);
10861 }
10862 }
10863
10864 /**
10865 * Set the release time for telephony to unbind GbaService.
10866 *
10867 * @param subId The sim that the GbaService is associated with.
10868 * @param interval The release time to unbind GbaService by millisecond.
10869 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10870 */
10871 @Override
10872 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10873 enforceModifyPermission();
10874
10875 final long identity = Binder.clearCallingIdentity();
10876 try {
10877 return getGbaManager(subId).overrideReleaseTime(interval);
10878 } finally {
10879 Binder.restoreCallingIdentity(identity);
10880 }
10881 }
10882
10883 /**
10884 * Return the release time for telephony to unbind GbaService.
10885 *
10886 * @param subId The sim that the GbaService is associated with.
10887 * @return The release time to unbind GbaService by millisecond.
10888 */
10889 @Override
10890 public int getGbaReleaseTime(int subId) {
10891 enforceReadPrivilegedPermission("getGbaReleaseTime");
10892
10893 final long identity = Binder.clearCallingIdentity();
10894 try {
10895 return getGbaManager(subId).getReleaseTime();
10896 } finally {
10897 Binder.restoreCallingIdentity(identity);
10898 }
10899 }
10900
10901 private GbaManager getGbaManager(int subId) {
10902 GbaManager instance = GbaManager.getInstance(subId);
10903 if (instance == null) {
10904 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10905 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10906 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10907 }
10908 return instance;
10909 }
Hui Wang761a6682020-10-31 05:12:53 +000010910
10911 /**
10912 * indicate whether the device and the carrier can support
10913 * RCS VoLTE single registration.
10914 */
10915 @Override
10916 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010917 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10918 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10919 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10920 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010921
10922 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10923 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10924 }
10925
10926 final long identity = Binder.clearCallingIdentity();
10927 try {
10928 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10929 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010930 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10931 if (isCapable != null) {
10932 return isCapable;
10933 }
Hui Wang761a6682020-10-31 05:12:53 +000010934 }
Hui Wang67af90e2021-06-04 16:57:15 -070010935 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10936 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010937 } finally {
10938 Binder.restoreCallingIdentity(identity);
10939 }
10940 }
10941
10942 /**
10943 * Register RCS provisioning callback.
10944 */
10945 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010946 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010947 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010948 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010949 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010950 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10951 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010952
10953 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10954 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10955 }
10956 if (!isImsAvailableOnDevice()) {
10957 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10958 "IMS not available on device.");
10959 }
10960
10961 final long identity = Binder.clearCallingIdentity();
10962 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010963 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010964 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010965 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10966 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010967 }
Hui Wang761a6682020-10-31 05:12:53 +000010968 } finally {
10969 Binder.restoreCallingIdentity(identity);
10970 }
10971 }
10972
10973 /**
10974 * Unregister RCS provisioning callback.
10975 */
10976 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010977 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010978 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010979 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010980 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010981 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10982 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010983
10984 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10985 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10986 }
10987 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010988 // operation failed silently
10989 Rlog.w(LOG_TAG, "IMS not available on device.");
10990 return;
Hui Wang761a6682020-10-31 05:12:53 +000010991 }
10992
10993 final long identity = Binder.clearCallingIdentity();
10994 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010995 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010996 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010997 } finally {
10998 Binder.restoreCallingIdentity(identity);
10999 }
11000 }
11001
11002 /**
11003 * trigger RCS reconfiguration.
11004 */
11005 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011006 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11007 "triggerRcsReconfiguration",
11008 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011009
11010 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11011 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11012 }
11013 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011014 // ProvisioningManager can not handle ServiceSpecificException.
11015 // Throw the IllegalStateException and annotate ProvisioningManager.
11016 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000011017 }
11018
11019 final long identity = Binder.clearCallingIdentity();
11020 try {
11021 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11022 } finally {
11023 Binder.restoreCallingIdentity(identity);
11024 }
11025 }
11026
11027 /**
11028 * Provide the client configuration parameters of the RCS application.
11029 */
11030 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011031 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11032 "setRcsClientConfiguration",
11033 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011034
11035 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11036 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11037 }
11038 if (!isImsAvailableOnDevice()) {
11039 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11040 "IMS not available on device.");
11041 }
11042
11043 final long identity = Binder.clearCallingIdentity();
11044
11045 try {
11046 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11047 if (configBinder == null) {
11048 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011049 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11050 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011051 } else {
11052 configBinder.setRcsClientConfiguration(rcc);
11053 }
joonhunshin3e154242021-09-17 06:33:39 +000011054
11055 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11056 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011057 } catch (RemoteException e) {
11058 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011059 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11060 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011061 } finally {
11062 Binder.restoreCallingIdentity(identity);
11063 }
11064 }
11065
11066 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011067 * Enables or disables the test mode for RCS VoLTE single registration.
11068 */
11069 @Override
11070 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11071 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11072 "setRcsSingleRegistrationTestModeEnabled");
11073
11074 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11075 }
11076
11077 /**
11078 * Gets the test mode for RCS VoLTE single registration.
11079 */
11080 @Override
11081 public boolean getRcsSingleRegistrationTestModeEnabled() {
11082 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11083 "getRcsSingleRegistrationTestModeEnabled");
11084
11085 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11086 }
11087
11088 /**
Hui Wang761a6682020-10-31 05:12:53 +000011089 * Overrides the config of RCS VoLTE single registration enabled for the device.
11090 */
11091 @Override
11092 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11093 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11094 "setDeviceSingleRegistrationEnabledOverride");
11095 enforceModifyPermission();
11096
11097 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11098 : Boolean.parseBoolean(enabledStr);
11099 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011100 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011101 }
11102
11103 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011104 * Sends a device to device communication message. Only usable via shell.
11105 * @param message message to send.
11106 * @param value message value.
11107 */
11108 @Override
11109 public void sendDeviceToDeviceMessage(int message, int value) {
11110 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011111 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011112 enforceModifyPermission();
11113
11114 final long identity = Binder.clearCallingIdentity();
11115 try {
11116 TelephonyConnectionService service =
11117 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11118 if (service == null) {
11119 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11120 return;
11121 }
11122 service.sendTestDeviceToDeviceMessage(message, value);
11123 } finally {
11124 Binder.restoreCallingIdentity(identity);
11125 }
11126 }
11127
Tyler Gunnbabbda02021-02-10 11:05:02 -080011128 /**
11129 * Sets the specified device to device transport active.
11130 * @param transport The transport to set active.
11131 */
11132 @Override
11133 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11134 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11135 "setActiveDeviceToDeviceTransport");
11136 enforceModifyPermission();
11137
11138 final long identity = Binder.clearCallingIdentity();
11139 try {
11140 TelephonyConnectionService service =
11141 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11142 if (service == null) {
11143 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11144 return;
11145 }
11146 service.setActiveDeviceToDeviceTransport(transport);
11147 } finally {
11148 Binder.restoreCallingIdentity(identity);
11149 }
11150 }
Tyler Gunn92479152021-01-20 16:30:10 -080011151
Tyler Gunnd4339262021-05-03 14:46:49 -070011152 @Override
11153 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11154 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11155 "setDeviceToDeviceForceEnabled");
11156
11157 final long identity = Binder.clearCallingIdentity();
11158 try {
11159 Arrays.stream(PhoneFactory.getPhones()).forEach(
11160 p -> {
11161 Phone thePhone = p.getImsPhone();
11162 if (thePhone != null && thePhone instanceof ImsPhone) {
11163 ImsPhone imsPhone = (ImsPhone) thePhone;
11164 CallTracker tracker = imsPhone.getCallTracker();
11165 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11166 ImsPhoneCallTracker imsPhoneCallTracker =
11167 (ImsPhoneCallTracker) tracker;
11168 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11169 }
11170 }
11171 }
11172 );
11173 } finally {
11174 Binder.restoreCallingIdentity(identity);
11175 }
11176 }
11177
Tyler Gunn92479152021-01-20 16:30:10 -080011178 /**
Hui Wang761a6682020-10-31 05:12:53 +000011179 * Gets the config of RCS VoLTE single registration enabled for the device.
11180 */
11181 @Override
11182 public boolean getDeviceSingleRegistrationEnabled() {
11183 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11184 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11185 }
11186
11187 /**
11188 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11189 */
11190 @Override
11191 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11192 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11193 "setCarrierSingleRegistrationEnabledOverride");
11194 enforceModifyPermission();
11195
11196 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11197 : Boolean.parseBoolean(enabledStr);
11198 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11199 subId, enabled);
11200 }
11201
11202 /**
11203 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11204 */
11205 @Override
11206 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11207 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11208 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11209 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011210
11211 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011212 * Overrides the ims feature validation result
11213 */
11214 @Override
11215 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11216 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11217 "setImsFeatureValidationOverride");
11218
11219 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11220 : Boolean.parseBoolean(enabledStr);
11221 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11222 subId, enabled);
11223 }
11224
11225 /**
11226 * Gets the ims feature validation override value
11227 */
11228 @Override
11229 public boolean getImsFeatureValidationOverride(int subId) {
11230 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11231 "getImsFeatureValidationOverride");
11232 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11233 }
11234
11235 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011236 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11237 * their mobile plan.
11238 */
11239 @Override
11240 public String getMobileProvisioningUrl() {
11241 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11242 final long identity = Binder.clearCallingIdentity();
11243 try {
11244 return getDefaultPhone().getMobileProvisioningUrl();
11245 } finally {
11246 Binder.restoreCallingIdentity(identity);
11247 }
11248 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011249
James.cf Linbcdf8b32021-01-14 16:44:13 +080011250 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011251 * Get the EAB contact from the EAB database.
11252 */
11253 @Override
11254 public String getContactFromEab(String contact) {
11255 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11256 enforceModifyPermission();
11257 final long identity = Binder.clearCallingIdentity();
11258 try {
11259 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11260 } finally {
11261 Binder.restoreCallingIdentity(identity);
11262 }
11263 }
11264
11265 /**
Calvin Pana1434322021-07-01 19:27:01 +080011266 * Get the EAB capability from the EAB database.
11267 */
11268 @Override
11269 public String getCapabilityFromEab(String contact) {
11270 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11271 enforceModifyPermission();
11272 final long identity = Binder.clearCallingIdentity();
11273 try {
11274 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11275 } finally {
11276 Binder.restoreCallingIdentity(identity);
11277 }
11278 }
11279
11280 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011281 * Remove the EAB contacts from the EAB database.
11282 */
11283 @Override
11284 public int removeContactFromEab(int subId, String contacts) {
11285 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11286 enforceModifyPermission();
11287 final long identity = Binder.clearCallingIdentity();
11288 try {
11289 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11290 } finally {
11291 Binder.restoreCallingIdentity(identity);
11292 }
11293 }
11294
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011295 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011296 public boolean getDeviceUceEnabled() {
11297 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11298 final long identity = Binder.clearCallingIdentity();
11299 try {
11300 return mApp.getDeviceUceEnabled();
11301 } finally {
11302 Binder.restoreCallingIdentity(identity);
11303 }
11304 }
11305
11306 @Override
11307 public void setDeviceUceEnabled(boolean isEnabled) {
11308 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11309 final long identity = Binder.clearCallingIdentity();
11310 try {
11311 mApp.setDeviceUceEnabled(isEnabled);
11312 } finally {
11313 Binder.restoreCallingIdentity(identity);
11314 }
11315 }
11316
Brad Ebinger14d467f2021-02-12 06:18:28 +000011317 /**
11318 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11319 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11320 */
11321 // Used for SHELL command only right now.
11322 @Override
11323 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11324 List<String> featureTags) {
11325 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11326 "addUceRegistrationOverrideShell");
11327 final long identity = Binder.clearCallingIdentity();
11328 try {
11329 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11330 new ArraySet<>(featureTags));
11331 } catch (ImsException e) {
11332 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11333 } finally {
11334 Binder.restoreCallingIdentity(identity);
11335 }
11336 }
11337
11338 /**
11339 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11340 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11341 */
11342 // Used for SHELL command only right now.
11343 @Override
11344 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11345 List<String> featureTags) {
11346 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11347 "removeUceRegistrationOverrideShell");
11348 final long identity = Binder.clearCallingIdentity();
11349 try {
11350 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11351 new ArraySet<>(featureTags));
11352 } catch (ImsException e) {
11353 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11354 } finally {
11355 Binder.restoreCallingIdentity(identity);
11356 }
11357 }
11358
11359 /**
11360 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11361 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11362 */
11363 // Used for SHELL command only right now.
11364 @Override
11365 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11366 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11367 "clearUceRegistrationOverrideShell");
11368 final long identity = Binder.clearCallingIdentity();
11369 try {
11370 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11371 } catch (ImsException e) {
11372 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11373 } finally {
11374 Binder.restoreCallingIdentity(identity);
11375 }
11376 }
11377
11378 /**
11379 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11380 */
11381 // Used for SHELL command only right now.
11382 @Override
11383 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11384 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11385 "getLatestRcsContactUceCapabilityShell");
11386 final long identity = Binder.clearCallingIdentity();
11387 try {
11388 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11389 } catch (ImsException e) {
11390 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11391 } finally {
11392 Binder.restoreCallingIdentity(identity);
11393 }
11394 }
11395
11396 /**
11397 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11398 * device does not have an active PUBLISH.
11399 */
11400 // Used for SHELL command only right now.
11401 @Override
11402 public String getLastUcePidfXmlShell(int subId) {
11403 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11404 final long identity = Binder.clearCallingIdentity();
11405 try {
11406 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11407 } catch (ImsException e) {
11408 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11409 } finally {
11410 Binder.restoreCallingIdentity(identity);
11411 }
11412 }
11413
James.cf Line8713a42021-04-29 16:04:26 +080011414 /**
11415 * Remove UCE requests cannot be sent to the network status.
11416 */
11417 // Used for SHELL command only right now.
11418 @Override
11419 public boolean removeUceRequestDisallowedStatus(int subId) {
11420 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11421 final long identity = Binder.clearCallingIdentity();
11422 try {
11423 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11424 } catch (ImsException e) {
11425 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11426 } finally {
11427 Binder.restoreCallingIdentity(identity);
11428 }
11429 }
11430
James.cf Lin18bb9002021-05-25 01:37:38 +080011431 /**
11432 * Remove UCE requests cannot be sent to the network status.
11433 */
11434 // Used for SHELL command only.
11435 @Override
11436 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11437 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11438 final long identity = Binder.clearCallingIdentity();
11439 try {
11440 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11441 } catch (ImsException e) {
11442 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11443 } finally {
11444 Binder.restoreCallingIdentity(identity);
11445 }
11446 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011447
James.cf Lin4b784aa2021-01-31 03:25:15 +080011448 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011449 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11450 String callingPackage) {
11451 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11452 mApp, subId, "setSignalStrengthUpdateRequest");
11453
11454 final int callingUid = Binder.getCallingUid();
11455 // Verify that tha callingPackage belongs to the calling UID
11456 mApp.getSystemService(AppOpsManager.class)
11457 .checkPackage(callingUid, callingPackage);
11458
Rambo Wang3607f502021-02-01 21:51:40 -080011459 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011460
11461 final long identity = Binder.clearCallingIdentity();
11462 try {
11463 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11464 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11465
11466 if (result instanceof IllegalStateException) {
11467 throw (IllegalStateException) result;
11468 }
11469 } finally {
11470 Binder.restoreCallingIdentity(identity);
11471 }
11472 }
11473
11474 @Override
11475 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11476 String callingPackage) {
11477 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11478 mApp, subId, "clearSignalStrengthUpdateRequest");
11479
11480 final int callingUid = Binder.getCallingUid();
11481 // Verify that tha callingPackage belongs to the calling UID
11482 mApp.getSystemService(AppOpsManager.class)
11483 .checkPackage(callingUid, callingPackage);
11484
11485 final long identity = Binder.clearCallingIdentity();
11486 try {
11487 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11488 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11489
11490 if (result instanceof IllegalStateException) {
11491 throw (IllegalStateException) result;
11492 }
11493 } finally {
11494 Binder.restoreCallingIdentity(identity);
11495 }
11496 }
11497
Rambo Wang3607f502021-02-01 21:51:40 -080011498 private static void validateSignalStrengthUpdateRequest(Context context,
11499 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011500 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11501 // phone/system process do not have further restriction on request
11502 return;
11503 }
11504
11505 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011506 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011507 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011508 context.enforceCallingOrSelfPermission(
11509 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11510 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011511 }
11512
11513 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011514 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011515 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011516 || info.isEnabled()) {
11517 throw new IllegalArgumentException(
11518 "Only system can set hide fields in SignalThresholdInfo");
11519 }
11520
11521 // Thresholds length for each RAN need in range. This has been validated in
11522 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11523 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11524 final int[] thresholds = info.getThresholds();
11525 Objects.requireNonNull(thresholds);
11526 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11527 || thresholds.length
11528 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11529 throw new IllegalArgumentException(
11530 "thresholds length is out of range: " + thresholds.length);
11531 }
11532 }
11533 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011534
11535 /**
11536 * Gets the current phone capability.
11537 *
11538 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11539 * @return the PhoneCapability which describes the data connection capability of modem.
11540 * It's used to evaluate possible phone config change, for example from single
11541 * SIM device to multi-SIM device.
11542 */
11543 @Override
11544 public PhoneCapability getPhoneCapability() {
11545 enforceReadPrivilegedPermission("getPhoneCapability");
11546 final long identity = Binder.clearCallingIdentity();
11547 try {
11548 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11549 } finally {
11550 Binder.restoreCallingIdentity(identity);
11551 }
11552 }
Michele Berionne5e411512020-11-13 02:36:59 +000011553
11554 /**
11555 * Prepare TelephonyManager for an unattended reboot. The reboot is
11556 * required to be done shortly after the API is invoked.
11557 */
11558 @Override
11559 @TelephonyManager.PrepareUnattendedRebootResult
11560 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011561 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011562 enforceRebootPermission();
11563
11564 final long identity = Binder.clearCallingIdentity();
11565 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011566 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011567 } finally {
11568 Binder.restoreCallingIdentity(identity);
11569 }
11570 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011571
11572 /**
11573 * Request to get the current slicing configuration including URSP rules and
11574 * NSSAIs (configured, allowed and rejected).
11575 *
11576 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11577 */
11578 @Override
11579 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011580 TelephonyPermissions
11581 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11582 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011583
11584 final long identity = Binder.clearCallingIdentity();
11585 try {
11586 Phone phone = getDefaultPhone();
11587 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11588 } finally {
11589 Binder.restoreCallingIdentity(identity);
11590 }
11591 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011592
11593 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011594 * Check whether the given premium capability is available for purchase from the carrier.
11595 *
11596 * @param capability The premium capability to check.
11597 * @param subId The subId to check the premium capability for.
11598 *
11599 * @return Whether the given premium capability is available to purchase.
11600 */
11601 @Override
11602 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11603 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11604 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11605 log("Premium capability "
11606 + TelephonyManager.convertPremiumCapabilityToString(capability)
11607 + " is not available for purchase due to missing permissions.");
11608 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11609 + "permission READ_BASIC_PHONE_STATE.");
11610 }
11611
11612 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011613 if (phone == null) {
11614 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11615 return false;
11616 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011617 final long identity = Binder.clearCallingIdentity();
11618 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011619 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011620 .isPremiumCapabilityAvailableForPurchase(capability);
11621 } finally {
11622 Binder.restoreCallingIdentity(identity);
11623 }
11624 }
11625
11626 /**
11627 * Purchase the given premium capability from the carrier.
11628 *
11629 * @param capability The premium capability to purchase.
11630 * @param callback The result of the purchase request.
11631 * @param subId The subId to purchase the premium capability for.
11632 */
11633 @Override
11634 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11635 log("purchasePremiumCapability: capability="
11636 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11637 + getCurrentPackageName());
11638
11639 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11640 mApp, "purchasePremiumCapability")) {
11641 log("purchasePremiumCapability "
11642 + TelephonyManager.convertPremiumCapabilityToString(capability)
11643 + " failed due to missing permissions.");
11644 throw new SecurityException("purchasePremiumCapability requires permission "
11645 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011646 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
11647 mApp, "purchasePremiumCapability")) {
11648 log("purchasePremiumCapability "
11649 + TelephonyManager.convertPremiumCapabilityToString(capability)
11650 + " failed due to missing permissions.");
11651 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070011652 }
11653
11654 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011655 if (phone == null) {
11656 try {
11657 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11658 callback.accept(result);
11659 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11660 } catch (RemoteException e) {
11661 String logStr = "Purchase premium capability "
11662 + TelephonyManager.convertPremiumCapabilityToString(capability)
11663 + " failed due to RemoteException handling null phone: " + e;
11664 if (DBG) log(logStr);
11665 AnomalyReporter.reportAnomaly(
11666 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11667 }
11668 return;
11669 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011670
11671 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070011672 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011673 callingProcess = mApp.getPackageManager().getApplicationInfo(
11674 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070011675 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011676 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070011677 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011678
11679 boolean isVisible = false;
11680 ActivityManager am = mApp.getSystemService(ActivityManager.class);
11681 if (am != null) {
11682 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
11683 if (processes != null) {
11684 for (ActivityManager.RunningAppProcessInfo process : processes) {
11685 log("purchasePremiumCapability: process " + process.processName
11686 + "has importance " + process.importance);
11687 if (process.processName.equals(callingProcess) && process.importance
11688 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
11689 isVisible = true;
11690 break;
11691 }
11692 }
11693 }
11694 }
11695
11696 if (!isVisible) {
11697 try {
11698 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
11699 callback.accept(result);
11700 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
11701 } catch (RemoteException e) {
11702 String logStr = "Purchase premium capability "
11703 + TelephonyManager.convertPremiumCapabilityToString(capability)
11704 + " failed due to RemoteException handling background application: " + e;
11705 if (DBG) log(logStr);
11706 AnomalyReporter.reportAnomaly(
11707 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11708 }
11709 return;
11710 }
11711
Sarah Chin71b3a852022-09-28 15:54:19 -070011712 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080011713 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011714 }
11715
11716 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011717 * Register an IMS connection state callback
11718 */
11719 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011720 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11721 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011722 if (feature == ImsFeature.FEATURE_MMTEL) {
11723 // ImsMmTelManager
11724 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11725 TelephonyPermissions
11726 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11727 mApp, subId, "registerImsStateCallback");
11728 } else if (feature == ImsFeature.FEATURE_RCS) {
11729 // ImsRcsManager or SipDelegateManager
11730 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11731 Binder.getCallingUid(), "registerImsStateCallback",
11732 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11733 Manifest.permission.READ_PRECISE_PHONE_STATE,
11734 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11735 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11736 }
11737
11738 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11739 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11740 "IMS not available on device.");
11741 }
11742
11743 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11744 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11745 }
11746
11747 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11748 if (controller == null) {
11749 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11750 "IMS not available on device.");
11751 }
11752
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011753 if (callingPackage == null) {
11754 callingPackage = getCurrentPackageName();
11755 }
11756
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011757 final long token = Binder.clearCallingIdentity();
11758 try {
11759 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011760 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011761 } catch (ImsException e) {
11762 throw new ServiceSpecificException(e.getCode());
11763 } finally {
11764 Binder.restoreCallingIdentity(token);
11765 }
11766 }
11767
11768 /**
11769 * Unregister an IMS connection state callback
11770 */
11771 @Override
11772 public void unregisterImsStateCallback(IImsStateCallback cb) {
11773 final long token = Binder.clearCallingIdentity();
11774 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11775 if (controller == null) {
11776 return;
11777 }
11778 try {
11779 controller.unregisterImsStateCallback(cb);
11780 } finally {
11781 Binder.restoreCallingIdentity(token);
11782 }
11783 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011784
11785 /**
11786 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11787 *
11788 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11789 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11790 * SecurityException.
11791 * If there is current registered network this value will be same as the registered cell
11792 * identity. If the device goes out of service the previous cell identity is cached and
11793 * will be returned. If the cache age of the Cell identity is more than 24 hours
11794 * it will be cleared and null will be returned.
11795 *
11796 */
11797 @Override
11798 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11799 String callingFeatureId) {
11800 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11801 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11802 LocationAccessPolicy.checkLocationPermission(mApp,
11803 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11804 .setCallingPackage(callingPackage)
11805 .setCallingFeatureId(callingFeatureId)
11806 .setCallingPid(Binder.getCallingPid())
11807 .setCallingUid(Binder.getCallingUid())
11808 .setMethod("getLastKnownCellIdentity")
11809 .setLogAsInfo(true)
11810 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11811 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11812 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11813 .build());
11814
11815 boolean hasFinePermission =
11816 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11817 if (!hasFinePermission
11818 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11819 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011820 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011821 }
11822
11823 final long identity = Binder.clearCallingIdentity();
11824 try {
Ling Mac28f0212023-03-24 16:07:15 -070011825 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011826 if (sst == null) return null;
11827 return sst.getLastKnownCellIdentity();
11828 } finally {
11829 Binder.restoreCallingIdentity(identity);
11830 }
11831 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011832
jimsun3b9ccac2021-10-26 15:01:23 +080011833 /**
11834 * Sets the modem service class Name that Telephony will bind to.
11835 *
11836 * @param serviceName The class name of the modem service.
11837 * @return true if the operation is succeed, otherwise false.
11838 */
11839 public boolean setModemService(String serviceName) {
11840 Log.d(LOG_TAG, "setModemService - " + serviceName);
11841 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11842 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011843 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11844 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080011845 return mPhoneConfigurationManager.setModemService(serviceName);
11846 }
11847
11848 /**
11849 * Return the class name of the currently bounded modem service.
11850 *
11851 * @return the class name of the modem service.
11852 */
11853 public String getModemService() {
11854 String result;
11855 Log.d(LOG_TAG, "getModemService");
11856 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11857 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011858 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080011859 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11860 "getModemService");
11861 result = mPhoneConfigurationManager.getModemService();
11862 Log.d(LOG_TAG, "result = " + result);
11863 return result;
11864 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011865
11866 @Override
11867 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11868 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11869 mApp.enforceCallingOrSelfPermission(
11870 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11871 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11872
11873 final long identity = Binder.clearCallingIdentity();
11874 try {
11875 Phone phone = getPhone(subId);
11876 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080011877 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
11878 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011879 phone.setVoiceServiceStateOverride(hasService);
11880 } finally {
11881 Binder.restoreCallingIdentity(identity);
11882 }
11883 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011884
11885 /**
11886 * set removable eSIM as default eUICC.
11887 *
11888 * @hide
11889 */
11890 @Override
11891 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11892 enforceModifyPermission();
11893 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11894
11895 final long identity = Binder.clearCallingIdentity();
11896 try {
11897 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11898 } finally {
11899 Binder.restoreCallingIdentity(identity);
11900 }
11901 }
11902
11903 /**
11904 * Returns whether the removable eSIM is default eUICC or not.
11905 *
11906 * @hide
11907 */
11908 @Override
11909 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11910 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11911 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11912
11913 final long identity = Binder.clearCallingIdentity();
11914 try {
11915 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11916 } finally {
11917 Binder.restoreCallingIdentity(identity);
11918 }
11919 }
11920
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011921 /**
11922 * Get the component name of the default app to direct respond-via-message intent for the
11923 * user associated with this subscription, update the cache if there is no respond-via-message
11924 * application currently configured for this user.
11925 * @return component name of the app and class to direct Respond Via Message intent to, or
11926 * {@code null} if the functionality is not supported.
11927 * @hide
11928 */
11929 @Override
11930 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11931 boolean updateIfNeeded) {
11932 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011933
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000011934 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
11935
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011936 UserHandle userHandle = null;
11937 final long identity = Binder.clearCallingIdentity();
11938 try {
11939 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11940 } finally {
11941 Binder.restoreCallingIdentity(identity);
11942 }
11943 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11944 updateIfNeeded, userHandle);
11945 }
Jack Yuf5badd92022-12-08 00:50:53 -080011946
11947 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011948 * Set whether the device is able to connect with null ciphering or integrity
11949 * algorithms. This is a global setting and will apply to all active subscriptions
11950 * and all new subscriptions after this.
11951 *
11952 * @param enabled when true, null cipher and integrity algorithms are allowed.
11953 * @hide
11954 */
11955 @Override
11956 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11957 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11958 enforceModifyPermission();
11959 checkForNullCipherAndIntegritySupport();
11960
11961 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11962 // for listening to these preference changes and applying them immediately.
11963 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11964 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11965 editor.apply();
11966
11967 for (Phone phone: PhoneFactory.getPhones()) {
11968 phone.handleNullCipherEnabledChange();
11969 }
11970 }
11971
11972
11973 /**
11974 * Get whether the device is able to connect with null ciphering or integrity
11975 * algorithms. Note that this retrieves the phone-global preference and not
11976 * the state of the radio.
11977 *
11978 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11979 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11980 * version for this feature.
11981 * @hide
11982 */
11983 @Override
11984 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11985 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11986 enforceReadPermission();
11987 checkForNullCipherAndIntegritySupport();
11988 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11989 }
11990
11991 private void checkForNullCipherAndIntegritySupport() {
11992 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11993 throw new UnsupportedOperationException(
11994 "Null cipher and integrity operations require HAL 2.1 or above");
11995 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000011996 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
11997 throw new UnsupportedOperationException(
11998 "Null cipher and integrity operations unsupported by modem");
11999 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012000 }
12001
12002 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012003 * Get the SIM state for the slot index.
12004 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12005 *
12006 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12007 */
12008 @Override
12009 @SimState
12010 public int getSimStateForSlotIndex(int slotIndex) {
12011 IccCardConstants.State simState;
12012 if (slotIndex < 0) {
12013 simState = IccCardConstants.State.UNKNOWN;
12014 } else {
12015 Phone phone = null;
12016 try {
12017 phone = PhoneFactory.getPhone(slotIndex);
12018 } catch (IllegalStateException e) {
12019 // ignore
12020 }
12021 if (phone == null) {
12022 simState = IccCardConstants.State.UNKNOWN;
12023 } else {
12024 IccCard icc = phone.getIccCard();
12025 if (icc == null) {
12026 simState = IccCardConstants.State.UNKNOWN;
12027 } else {
12028 simState = icc.getState();
12029 }
12030 }
12031 }
12032 return simState.ordinal();
12033 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012034
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012035 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12036 boolean enableLogcat,
12037 long logcatStartTimestampMillis, boolean enableTelecomDump,
12038 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012039 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
12040 TelephonyManager.EmergencyCallDiagnosticParams edp =
12041 new TelephonyManager.EmergencyCallDiagnosticParams();
12042 edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis);
12043 edp.setTelephonyDumpSysCollection(enableTelephonyDump);
12044 edp.setTelecomDumpSysCollection(enableTelecomDump);
12045 Log.d(LOG_TAG, "persisting with Params " + edp.toString());
12046 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12047 Executors.newCachedThreadPool(), db,
12048 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
12049 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012050 }
12051
12052 /**
12053 * Request telephony to persist state for debugging emergency call failures.
12054 *
12055 * @param dropBoxTag Tag to use when persisting data to dropbox service.
12056 * @param enableLogcat whether to collect logcat output
12057 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12058 * @param enableTelecomDump whether to collect telecom dumpsys
12059 * @param enableTelephonyDump whether to collect telephony dumpsys
12060 */
12061 @Override
12062 @RequiresPermission(android.Manifest.permission.DUMP)
12063 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12064 long logcatStartTimestampMillis, boolean enableTelecomDump,
12065 boolean enableTelephonyDump) {
12066 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12067 "persistEmergencyCallDiagnosticData");
12068 final long identity = Binder.clearCallingIdentity();
12069 try {
12070 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12071 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12072
12073 } finally {
12074 Binder.restoreCallingIdentity(identity);
12075 }
12076 }
12077
Hui Wang9b5793a2022-12-05 14:38:06 -060012078 /**
12079 * Get current cell broadcast ranges.
12080 */
12081 @Override
12082 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12083 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12084 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12085 "getCellBroadcastIdRanges");
12086 final long identity = Binder.clearCallingIdentity();
12087 try {
12088 return getPhone(subId).getCellBroadcastIdRanges();
12089 } finally {
12090 Binder.restoreCallingIdentity(identity);
12091 }
12092 }
12093
12094 /**
12095 * Set reception of cell broadcast messages with the list of the given ranges
12096 *
12097 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12098 */
12099 @Override
12100 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12101 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12102 @Nullable IIntegerConsumer callback) {
12103 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12104 "setCellBroadcastIdRanges");
12105 final long identity = Binder.clearCallingIdentity();
12106 try {
12107 Phone phone = getPhoneFromSubId(subId);
12108 if (DBG) {
12109 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12110 }
12111 phone.setCellBroadcastIdRanges(ranges, result -> {
12112 if (callback != null) {
12113 try {
12114 callback.accept(result);
12115 } catch (RemoteException e) {
12116 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12117 }
12118 }
12119 });
12120 } finally {
12121 Binder.restoreCallingIdentity(identity);
12122 }
12123 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012124
12125 /**
12126 * Returns whether the device supports the domain selection service.
12127 *
12128 * @return {@code true} if the device supports the domain selection service.
12129 */
12130 @Override
12131 public boolean isDomainSelectionSupported() {
12132 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12133 "isDomainSelectionSupported");
12134
12135 final long identity = Binder.clearCallingIdentity();
12136 try {
12137 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12138 } finally {
12139 Binder.restoreCallingIdentity(identity);
12140 }
12141 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012142
12143 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012144 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12145 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12146 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012147 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012148 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012149 * @param enableSatellite {@code true} to enable the satellite modem and
12150 * {@code false} to disable.
12151 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
12152 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012153 *
12154 * @throws SecurityException if the caller doesn't have the required permission.
12155 */
12156 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012157 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
12158 @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012159 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Sarah Chinabf081b2023-03-09 23:00:57 -080012160 mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode,
12161 callback);
Sarah Chin503828c2023-02-01 23:54:20 -080012162 }
12163
12164 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012165 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012166 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012167 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012168 * @param result The result receiver that returns whether the satellite modem is enabled
12169 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012170 *
12171 * @throws SecurityException if the caller doesn't have the required permission.
12172 */
12173 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012174 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12175 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012176 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012177 }
12178
12179 /**
Sarah Chin43457982023-02-15 17:50:38 -080012180 * Request to get whether the satellite service demo mode is enabled.
12181 *
12182 * @param subId The subId of the subscription to check whether the satellite demo mode
12183 * is enabled for.
12184 * @param result The result receiver that returns whether the satellite demo mode is enabled
12185 * if the request is successful or an error code if the request failed.
12186 *
12187 * @throws SecurityException if the caller doesn't have the required permission.
12188 */
12189 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012190 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
12191 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
12192 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080012193 }
12194
12195 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012196 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012197 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012198 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012199 * @param result The result receiver that returns whether the satellite service is supported on
12200 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012201 */
12202 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012203 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012204 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012205 }
12206
12207 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012208 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012209 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012210 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012211 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12212 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012213 *
12214 * @throws SecurityException if the caller doesn't have required permission.
12215 */
12216 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012217 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12218 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012219 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012220 }
12221
12222 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012223 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012224 * This can be called by the pointing UI when the user starts pointing to the satellite.
12225 * Modem should continue to report the pointing input as the device or satellite moves.
12226 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012227 * @param subId The subId of the subscription to start satellite transmission updates for.
12228 * @param resultCallback The callback to get the result of the request.
12229 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080012230 *
12231 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012232 */
12233 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012234 public void startSatelliteTransmissionUpdates(int subId,
12235 @NonNull IIntegerConsumer resultCallback,
12236 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12237 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
12238 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080012239 }
12240
12241 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012242 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012243 * This can be called by the pointing UI when the user stops pointing to the satellite.
12244 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012245 * @param subId The subId of the subscription to stop satellite transmission updates for.
12246 * @param resultCallback The callback to get the result of the request.
12247 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
12248 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080012249 *
12250 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012251 */
12252 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012253 public void stopSatelliteTransmissionUpdates(int subId,
12254 @NonNull IIntegerConsumer resultCallback,
12255 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12256 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
12257 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012258 }
12259
12260 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012261 * Register the subscription with a satellite provider.
12262 * This is needed to register the subscription if the provider allows dynamic registration.
12263 *
12264 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012265 * @param token The token to be used as a unique identifier for provisioning with satellite
12266 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012267 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080012268 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012269 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012270 * @return The signal transport used by the caller to cancel the provision request,
12271 * or {@code null} if the request failed.
12272 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012273 * @throws SecurityException if the caller doesn't have the required permission.
12274 */
12275 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012276 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012277 @NonNull String token, @NonNull byte[] provisionData,
12278 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012279 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012280 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
12281 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012282 }
12283
12284 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012285 * Unregister the device/subscription with the satellite provider.
12286 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012287 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012288 * should report as deprovisioned.
12289 *
12290 * @param subId The subId of the subscription to be deprovisioned.
12291 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080012292 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012293 *
12294 * @throws SecurityException if the caller doesn't have the required permission.
12295 */
12296 @Override
12297 public void deprovisionSatelliteService(int subId,
12298 @NonNull String token, @NonNull IIntegerConsumer callback) {
12299 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012300 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012301 }
12302
12303 /**
Sarah Chin43457982023-02-15 17:50:38 -080012304 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012305 *
Sarah Chin43457982023-02-15 17:50:38 -080012306 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012307 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012308 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012309 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12310 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012311 * @throws SecurityException if the caller doesn't have the required permission.
12312 */
12313 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080012314 @SatelliteManager.SatelliteError public int registerForSatelliteProvisionStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012315 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012316 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012317 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012318 }
12319
12320 /**
Sarah Chin43457982023-02-15 17:50:38 -080012321 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012322 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012323 *
Sarah Chin43457982023-02-15 17:50:38 -080012324 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012325 * @param callback The callback that was passed to
12326 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012327 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012328 * @throws SecurityException if the caller doesn't have the required permission.
12329 */
12330 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012331 public void unregisterForSatelliteProvisionStateChanged(
12332 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012333 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012334 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012335 }
12336
12337 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012338 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012339 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012340 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012341 * @param result The result receiver that returns whether the device is provisioned with a
12342 * satellite provider if the request is successful or an error code if the
12343 * request failed.
12344 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012345 * @throws SecurityException if the caller doesn't have the required permission.
12346 */
12347 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012348 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
12349 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012350 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012351 }
12352
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012353 /**
Sarah Chin43457982023-02-15 17:50:38 -080012354 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012355 *
Sarah Chin43457982023-02-15 17:50:38 -080012356 * @param subId The subId of the subscription to register for satellite modem state changed.
12357 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080012358 *
12359 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12360 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012361 * @throws SecurityException if the caller doesn't have the required permission.
12362 */
12363 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012364 @SatelliteManager.SatelliteError public int registerForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012365 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012366 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012367 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012368 }
12369
12370 /**
Sarah Chin43457982023-02-15 17:50:38 -080012371 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012372 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012373 *
Sarah Chin43457982023-02-15 17:50:38 -080012374 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080012375 * @param callback The callback that was passed to
Sarah Chin43457982023-02-15 17:50:38 -080012376 * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012377 *
12378 * @throws SecurityException if the caller doesn't have the required permission.
12379 */
12380 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012381 public void unregisterForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012382 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012383 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012384 mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012385 }
12386
12387 /**
12388 * Register to receive incoming datagrams over satellite.
12389 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012390 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080012391 * @param callback The callback to handle incoming datagrams over satellite.
12392 *
12393 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12394 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012395 * @throws SecurityException if the caller doesn't have the required permission.
12396 */
12397 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080012398 @SatelliteManager.SatelliteError public int registerForSatelliteDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012399 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012400 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
Sarah Chinabf081b2023-03-09 23:00:57 -080012401 return mSatelliteController.registerForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012402 }
12403
12404 /**
12405 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012406 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012407 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012408 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
12409 * @param callback The callback that was passed to
Sarah Chinabf081b2023-03-09 23:00:57 -080012410 * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012411 *
12412 * @throws SecurityException if the caller doesn't have the required permission.
12413 */
12414 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012415 public void unregisterForSatelliteDatagram(int subId,
12416 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012417 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012418 mSatelliteController.unregisterForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012419 }
12420
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012421 /**
12422 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012423 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012424 * This method requests modem to check if there are any pending datagrams to be received over
12425 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000012426 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080012427 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012428 * @param subId The subId of the subscription used for receiving datagrams.
12429 * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012430 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012431 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012432 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012433 @Override
12434 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012435 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012436 mSatelliteController.pollPendingSatelliteDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012437 }
12438
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012439 /**
12440 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012441 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012442 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
12443 * input to this method. Datagram received here will be passed down to modem without any
12444 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080012445 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012446 * @param subId The subId of the subscription to send satellite datagrams for.
12447 * @param datagramType datagram type indicating whether the datagram is of type
12448 * SOS_SMS or LOCATION_SHARING.
12449 * @param datagram encoded gateway datagram which is encrypted by the caller.
12450 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000012451 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
12452 * full screen mode.
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012453 * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012454 *
12455 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012456 */
12457 @Override
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012458 public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
12459 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
12460 @NonNull IIntegerConsumer callback) {
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012461 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012462 mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram,
12463 needFullScreenPointingUI, callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012464 }
12465
Sarah Chindf715ec2023-02-13 13:46:24 -080012466 /**
12467 * Request to get whether satellite communication is allowed for the current location.
12468 *
12469 * @param subId The subId of the subscription to check whether satellite communication is
12470 * allowed for the current location for.
12471 * @param result The result receiver that returns whether satellite communication is allowed
12472 * for the current location if the request is successful or an error code
12473 * if the request failed.
12474 *
12475 * @throws SecurityException if the caller doesn't have the required permission.
12476 */
12477 @Override
12478 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
12479 @NonNull ResultReceiver result) {
12480 enforceSatelliteCommunicationPermission(
12481 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012482 mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId,
12483 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080012484 }
12485
12486 /**
Sarah Chin5f57c582023-02-14 04:16:10 -080012487 * Request to get the time after which the satellite will be visible
Sarah Chindf715ec2023-02-13 13:46:24 -080012488 *
Sarah Chin5f57c582023-02-14 04:16:10 -080012489 * @param subId The subId to get the time after which the satellite will be visible for.
12490 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080012491 * be visible if the request is successful or an error code if the request failed.
12492 *
12493 * @throws SecurityException if the caller doesn't have the required permission.
12494 */
12495 @Override
12496 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
12497 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012498 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012499 }
12500
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012501 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070012502 * This API can be used by only CTS to update satellite vendor service package name.
12503 *
12504 * @param servicePackageName The package name of the satellite vendor service.
12505 * @return {@code true} if the satellite vendor service is set successfully,
12506 * {@code false} otherwise.
12507 */
12508 public boolean setSatelliteServicePackageName(String servicePackageName) {
12509 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
12510 TelephonyPermissions.enforceShellOnly(
12511 Binder.getCallingUid(), "setSatelliteServicePackageName");
12512 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12513 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12514 "setSatelliteServicePackageName");
12515 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
12516 }
12517
12518 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070012519 * This API can be used by only CTS to update satellite gateway service package name.
12520 *
12521 * @param servicePackageName The package name of the satellite gateway service.
12522 * @return {@code true} if the satellite gateway service is set successfully,
12523 * {@code false} otherwise.
12524 */
12525 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
12526 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
12527 TelephonyPermissions.enforceShellOnly(
12528 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
12529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12530 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12531 "setSatelliteGatewayServicePackageName");
12532 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
12533 }
12534
12535 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070012536 * This API can be used by only CTS to update the timeout duration in milliseconds that
12537 * satellite should stay at listening mode to wait for the next incoming page before disabling
12538 * listening mode.
12539 *
12540 * @param timeoutMillis The timeout duration in millisecond.
12541 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12542 */
12543 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
12544 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
12545 TelephonyPermissions.enforceShellOnly(
12546 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
12547 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12548 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12549 "setSatelliteListeningTimeoutDuration");
12550 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
12551 }
12552
12553 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000012554 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
12555 *
12556 * <p>This method behaves in one of the following ways:
12557 * <ul>
12558 * <li>return true : if the calling package has the appop permission {@link
12559 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
12560 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
12561 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
12562 * Owner device identifier access check, or the calling package has carrier privileges</>
12563 * <li>throw SecurityException: if the caller does not meet any of the requirements.
12564 * </ul>
12565 */
12566 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
12567 String callingPackage, @Nullable String callingFeatureId, String message) {
12568 for (Phone phone : PhoneFactory.getPhones()) {
12569 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
12570 phone.getSubId(), callingPackage, callingFeatureId, message)) {
12571 return true;
12572 }
12573 }
12574 return false;
12575 }
arunvoddud7401012022-12-15 16:08:12 +000012576
12577 /**
Jack Yufa8ed012023-02-11 15:42:28 -080012578 * @return The subscription manager service instance.
12579 */
12580 public SubscriptionManagerService getSubscriptionManagerService() {
12581 return SubscriptionManagerService.getInstance();
12582 }
12583
12584 /**
arunvoddud7401012022-12-15 16:08:12 +000012585 * Class binds the consumer[callback] and carrierId.
12586 */
12587 private static class CallerCallbackInfo {
12588 private final Consumer<Integer> mConsumer;
12589 private final int mCarrierId;
12590
12591 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
12592 mConsumer = consumer;
12593 mCarrierId = carrierId;
12594 }
12595
12596 public Consumer<Integer> getConsumer() {
12597 return mConsumer;
12598 }
12599
12600 public int getCarrierId() {
12601 return mCarrierId;
12602 }
12603 }
Jack Yufa8ed012023-02-11 15:42:28 -080012604}