blob: b49ff4e8511b19a56eaaca1de04c1c6a53101d8c [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;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080054import android.os.CancellationSignal;
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;
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +0000149import android.telephony.satellite.ISatelliteDatagramReceiverAck;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800150import android.telephony.satellite.ISatellitePositionUpdateCallback;
151import android.telephony.satellite.ISatelliteProvisionStateCallback;
152import android.telephony.satellite.ISatelliteStateCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800153import android.telephony.satellite.PointingInfo;
Sarah Chin503828c2023-02-01 23:54:20 -0800154import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000155import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800156import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800157import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800158import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800160import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700161import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800163import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800164
Andrew Lee312e8172014-10-23 17:01:36 -0700165import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800166import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800167import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800168import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800169import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700170import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700171import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700172import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800173import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800174import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700175import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700176import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800177import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700178import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800179import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800180import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800181import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700182import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000183import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700184import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800185import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800187import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800188import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800189import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700190import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700191import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700192import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700194import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800195import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700196import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700197import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700198import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700199import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800200import com.android.internal.telephony.RILConstants;
Sarah Chineccfbd12023-01-20 19:00:35 -0800201import com.android.internal.telephony.RILUtils;
Daniel Bright94f43662021-03-01 14:43:40 -0800202import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700203import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000204import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700205import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700206import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800207import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800208import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800209import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700210import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000211import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800212import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700213import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800214import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700215import com.android.internal.telephony.imsphone.ImsPhone;
216import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000217import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800218import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000219import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800220import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
221import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700222import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700223import com.android.internal.telephony.uicc.IccIoResult;
224import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800225import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700226import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800227import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700228import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000229import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800230import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000231import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800232import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000233import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700234import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700235import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800236import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800237import com.android.phone.callcomposer.CallComposerPictureManager;
238import com.android.phone.callcomposer.CallComposerPictureTransfer;
239import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700240import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700241import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000242import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700243import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800244import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700245import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700246import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800247import com.android.services.telephony.TelecomAccountRegistry;
248import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800249import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800250
Hall Liu82694d52020-12-11 18:22:04 -0800251import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700252import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800253import java.io.IOException;
254import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700255import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700256import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800257import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000258import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800259import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800260import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800261import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800262import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100263import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800264import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700265import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800266import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800267import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700268import java.util.UUID;
Sarah Chineccfbd12023-01-20 19:00:35 -0800269import java.util.concurrent.ConcurrentHashMap;
Hall Liu82694d52020-12-11 18:22:04 -0800270import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800271import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800272import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700273
274/**
275 * Implementation of the ITelephony interface.
276 */
Santos Cordon117fee72014-05-16 17:56:12 -0700277public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700278 private static final String LOG_TAG = "PhoneInterfaceManager";
279 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
280 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800281 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700282
283 // Message codes used with mMainThreadHandler
284 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700285 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
286 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700287 private static final int CMD_OPEN_CHANNEL = 9;
288 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
289 private static final int CMD_CLOSE_CHANNEL = 11;
290 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800291 private static final int CMD_NV_READ_ITEM = 13;
292 private static final int EVENT_NV_READ_ITEM_DONE = 14;
293 private static final int CMD_NV_WRITE_ITEM = 15;
294 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
295 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
296 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700297 private static final int CMD_RESET_MODEM_CONFIG = 19;
298 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800299 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
300 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800301 private static final int CMD_SEND_ENVELOPE = 25;
302 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000303 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
304 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700305 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
306 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
307 private static final int CMD_EXCHANGE_SIM_IO = 31;
308 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800309 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
310 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700311 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
312 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700313 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
314 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700315 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
316 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
317 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
318 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700319 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
320 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
321 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
322 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700323 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800324 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
325 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000326 private static final int CMD_SWITCH_SLOTS = 50;
327 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700328 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
329 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
330 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
331 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
332 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
333 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
334 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
335 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700336 private static final int CMD_GET_ALL_CELL_INFO = 60;
337 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
338 private static final int CMD_GET_CELL_LOCATION = 62;
339 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700340 private static final int CMD_MODEM_REBOOT = 64;
341 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700342 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
343 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800344 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
345 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700346 private static final int CMD_GET_MODEM_STATUS = 70;
347 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700348 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
349 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700350 private static final int CMD_ERASE_MODEM_CONFIG = 74;
351 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800352 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
353 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
354 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
355 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800356 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
357 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800358 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800359 private static final int CMD_GET_CALL_FORWARDING = 83;
360 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
361 private static final int CMD_SET_CALL_FORWARDING = 85;
362 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
363 private static final int CMD_GET_CALL_WAITING = 87;
364 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
365 private static final int CMD_SET_CALL_WAITING = 89;
366 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700367 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
368 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
369 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
370 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700371 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
372 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800373 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
374 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800375 private static final int CMD_SET_DATA_THROTTLING = 99;
376 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800377 private static final int CMD_SET_SIM_POWER = 101;
378 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800379 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
380 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
381 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
382 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800383 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
384 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000385 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800386 private static final int CMD_GET_SLICING_CONFIG = 110;
387 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800388 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700389 private static final int CMD_ENABLE_VONR = 113;
390 private static final int EVENT_ENABLE_VONR_DONE = 114;
391 private static final int CMD_IS_VONR_ENABLED = 115;
392 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700393 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
394 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000395
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800396 // Parameters of select command.
397 private static final int SELECT_COMMAND = 0xA4;
398 private static final int SELECT_P1 = 0x04;
399 private static final int SELECT_P2 = 0;
400 private static final int SELECT_P3 = 0x10;
401
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000402 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
403 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
404
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700405 /** The singleton instance. */
406 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800407 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700408
Sarah Chin4beb2b72023-02-14 14:47:54 -0800409 private final PhoneGlobals mApp;
410 private final CallManager mCM;
411 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000412
413 private final SatelliteController mSatelliteController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800414 private final UserManager mUserManager;
415 private final AppOpsManager mAppOps;
416 private final MainThreadHandler mMainThreadHandler;
Jack Yue37dd262022-12-16 11:53:37 -0800417 private final SubscriptionController mSubscriptionController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800418 private final SharedPreferences mTelephonySharedPreferences;
419 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800420 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700421
Peter Wangdafb9ac2020-01-15 14:13:38 -0800422 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800423 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800424 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
425
Sarah Chin4beb2b72023-02-14 14:47:54 -0800426 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800427
Derek Tan97ebb422014-09-05 16:55:38 -0700428 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
429 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800430 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800431 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700432
Michelecea4cf22018-12-21 15:00:11 -0800433 // String to store multi SIM allowed
434 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
435
Derek Tan740e1672017-06-27 14:56:27 -0700436 // The AID of ISD-R.
437 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
438
yinxub1bed742017-04-17 11:45:04 -0700439 private NetworkScanRequestTracker mNetworkScanRequestTracker;
440
David Kelly5e06a7f2018-03-12 14:10:59 +0000441 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
442 private static final int MANUFACTURER_CODE_LENGTH = 8;
443
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800444 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800445 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800446
Sarah Chin2ec39f62022-08-31 17:03:26 -0700447 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
448 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
449
Derek Tan89e89d42014-07-08 17:00:10 -0700450 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700451 * Experiment flag to enable erase modem config on reset network, default value is false
452 */
453 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
454 "reset_network_erase_modem_config_enabled";
455
Rambo Wang0f050d82021-02-12 11:43:36 -0800456 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800457
Gary Jian76280a42022-12-07 16:18:33 +0800458 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
459
sandeepjsb6c87872021-09-27 15:34:44 +0000460 /**
461 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
462 * one ICCID active at the same time.
463 * Apps should use below API signatures if targeting SDK is T and beyond.
464 *
465 * @hide
466 */
467 @ChangeId
468 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
469 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800470
Naina Nallurid63128d2019-09-17 14:10:30 -0700471 /**
Chen Xu540470b2021-12-14 17:15:47 -0800472 * Apps targeting on Android T and beyond will get exception whenever icc close channel
473 * operation fails.
474 */
475 @ChangeId
476 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
477 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
478
479 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700480 * A request object to use for transmitting data to an ICC.
481 */
482 private static final class IccAPDUArgument {
483 public int channel, cla, command, p1, p2, p3;
484 public String data;
485
486 public IccAPDUArgument(int channel, int cla, int command,
487 int p1, int p2, int p3, String data) {
488 this.channel = channel;
489 this.cla = cla;
490 this.command = command;
491 this.p1 = p1;
492 this.p2 = p2;
493 this.p3 = p3;
494 this.data = data;
495 }
496 }
497
498 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700499 * A request object to use for transmitting data to an ICC.
500 */
501 private static final class ManualNetworkSelectionArgument {
502 public OperatorInfo operatorInfo;
503 public boolean persistSelection;
504
505 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
506 this.operatorInfo = operatorInfo;
507 this.persistSelection = persistSelection;
508 }
509 }
510
Sarah Chin71b3a852022-09-28 15:54:19 -0700511 private static final class PurchasePremiumCapabilityArgument {
512 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700513 public @NonNull IIntegerConsumer callback;
514
515 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800516 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700517 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700518 this.callback = callback;
519 }
520 }
521
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700522 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700523 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
524 * request after sending. The main thread will notify the request when it is complete.
525 */
526 private static final class MainThreadRequest {
527 /** The argument to use for the request */
528 public Object argument;
529 /** The result of the request that is run on the main thread */
530 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800531 // The subscriber id that this request applies to. Defaults to
532 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
533 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700534
Nathan Harold92bed182018-10-12 18:16:49 -0700535 // In cases where subId is unavailable, the caller needs to specify the phone.
536 public Phone phone;
537
vagdeviaf9a5b92018-08-15 16:01:53 -0700538 public WorkSource workSource;
539
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700540 public MainThreadRequest(Object argument) {
541 this.argument = argument;
542 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800543
Nathan Harold92bed182018-10-12 18:16:49 -0700544 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
545 this.argument = argument;
546 if (phone != null) {
547 this.phone = phone;
548 }
549 this.workSource = workSource;
550 }
551
vagdeviaf9a5b92018-08-15 16:01:53 -0700552 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800553 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800554 if (subId != null) {
555 this.subId = subId;
556 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700557 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800558 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700559 }
560
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800561 private static final class IncomingThirdPartyCallArgs {
562 public final ComponentName component;
563 public final String callId;
564 public final String callerDisplayName;
565
566 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
567 String callerDisplayName) {
568 this.component = component;
569 this.callId = callId;
570 this.callerDisplayName = callerDisplayName;
571 }
572 }
573
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700574 /**
575 * A handler that processes messages on the main thread in the phone process. Since many
576 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
577 * inbound binder threads to the main thread in the phone process. The Binder thread
578 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
579 * on, which will be notified when the operation completes and will contain the result of the
580 * request.
581 *
582 * <p>If a MainThreadRequest object is provided in the msg.obj field,
583 * note that request.result must be set to something non-null for the calling thread to
584 * unblock.
585 */
586 private final class MainThreadHandler extends Handler {
587 @Override
588 public void handleMessage(Message msg) {
589 MainThreadRequest request;
590 Message onCompleted;
591 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000592 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700593 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800594 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700595
596 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700597 case CMD_HANDLE_USSD_REQUEST: {
598 request = (MainThreadRequest) msg.obj;
599 final Phone phone = getPhoneFromRequest(request);
600 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800601 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700602 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700603
Pengquan Menga1bb6272018-09-06 09:59:22 -0700604 if (!isUssdApiAllowed(request.subId)) {
605 // Carrier does not support use of this API, return failure.
606 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
607 UssdResponse response = new UssdResponse(ussdRequest, null);
608 Bundle returnData = new Bundle();
609 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
610 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700611
Pengquan Menga1bb6272018-09-06 09:59:22 -0700612 request.result = true;
613 notifyRequester(request);
614 return;
615 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700616
Pengquan Menga1bb6272018-09-06 09:59:22 -0700617 try {
618 request.result = phone != null
619 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
620 } catch (CallStateException cse) {
621 request.result = false;
622 }
623 // Wake up the requesting thread
624 notifyRequester(request);
625 break;
pkanwar32d516d2016-10-14 19:37:38 -0700626 }
627
Yorke Lee716f67e2015-06-17 15:39:16 -0700628 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700629 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700630 final Phone phone = getPhoneFromRequest(request);
631 request.result = phone != null ?
632 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
633 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700634 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700635 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700636 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700637 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700638
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700641 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000642 uiccPort = getUiccPortFromRequest(request);
643 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700644 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800645 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700646 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700647 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700648 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800649 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000650 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800651 iccArgument.channel, iccArgument.cla, iccArgument.command,
652 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
653 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700654 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 break;
656
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700658 ar = (AsyncResult) msg.obj;
659 request = (MainThreadRequest) ar.userObj;
660 if (ar.exception == null && ar.result != null) {
661 request.result = ar.result;
662 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800663 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 if (ar.result == null) {
665 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800666 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700667 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800668 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700669 } else {
670 loge("iccTransmitApduLogicalChannel: Unknown exception");
671 }
672 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700673 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 break;
675
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700676 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
677 request = (MainThreadRequest) msg.obj;
678 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000679 uiccPort = getUiccPortFromRequest(request);
680 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700681 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800682 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700683 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700684 } else {
685 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800686 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000687 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800688 iccArgument.cla, iccArgument.command, iccArgument.p1,
689 iccArgument.p2,
690 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700691 }
692 break;
693
694 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
695 ar = (AsyncResult) msg.obj;
696 request = (MainThreadRequest) ar.userObj;
697 if (ar.exception == null && ar.result != null) {
698 request.result = ar.result;
699 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800700 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700701 if (ar.result == null) {
702 loge("iccTransmitApduBasicChannel: Empty response");
703 } else if (ar.exception instanceof CommandException) {
704 loge("iccTransmitApduBasicChannel: CommandException: " +
705 ar.exception);
706 } else {
707 loge("iccTransmitApduBasicChannel: Unknown exception");
708 }
709 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700710 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700711 break;
712
713 case CMD_EXCHANGE_SIM_IO:
714 request = (MainThreadRequest) msg.obj;
715 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000716 uiccPort = getUiccPortFromRequest(request);
717 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700718 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800719 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700720 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700721 } else {
722 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
723 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000724 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700725 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
726 iccArgument.data, onCompleted);
727 }
728 break;
729
730 case EVENT_EXCHANGE_SIM_IO_DONE:
731 ar = (AsyncResult) msg.obj;
732 request = (MainThreadRequest) ar.userObj;
733 if (ar.exception == null && ar.result != null) {
734 request.result = ar.result;
735 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800736 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700737 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700738 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700739 break;
740
Derek Tan4d5e5c12014-02-04 11:54:58 -0800741 case CMD_SEND_ENVELOPE:
742 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000743 uiccPort = getUiccPortFromRequest(request);
744 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700745 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800746 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700747 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700748 } else {
749 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800750 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700751 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800752 break;
753
754 case EVENT_SEND_ENVELOPE_DONE:
755 ar = (AsyncResult) msg.obj;
756 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700757 if (ar.exception == null && ar.result != null) {
758 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800759 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800760 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700761 if (ar.result == null) {
762 loge("sendEnvelopeWithStatus: Empty response");
763 } else if (ar.exception instanceof CommandException) {
764 loge("sendEnvelopeWithStatus: CommandException: " +
765 ar.exception);
766 } else {
767 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
768 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800769 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700770 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800771 break;
772
Shishir Agrawal566b7612013-10-28 14:41:00 -0700773 case CMD_OPEN_CHANNEL:
774 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000775 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800776 IccLogicalChannelRequest openChannelRequest =
777 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000778 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700779 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800780 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800781 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700782 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700783 } else {
784 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800785 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
786 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700787 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700788 break;
789
790 case EVENT_OPEN_CHANNEL_DONE:
791 ar = (AsyncResult) msg.obj;
792 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700793 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700794 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700795 int[] result = (int[]) ar.result;
796 int channelId = result[0];
797 byte[] selectResponse = null;
798 if (result.length > 1) {
799 selectResponse = new byte[result.length - 1];
800 for (int i = 1; i < result.length; ++i) {
801 selectResponse[i - 1] = (byte) result[i];
802 }
803 }
804 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800805 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800806
807 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700808 if (uiccPort == null) {
809 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
810 } else {
811 IccLogicalChannelRequest channelRequest =
812 (IccLogicalChannelRequest) request.argument;
813 channelRequest.channel = channelId;
814 uiccPort.onLogicalChannelOpened(channelRequest);
815 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700816 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700817 if (ar.result == null) {
818 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700819 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700820 if (ar.exception != null) {
821 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
822 }
823
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700824 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700825 if (ar.exception instanceof CommandException) {
826 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800827 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700828 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700829 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700830 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700831 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700832 }
833 }
834 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800835 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700836 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700837 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700838 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700839 break;
840
841 case CMD_CLOSE_CHANNEL:
842 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000843 uiccPort = getUiccPortFromRequest(request);
844 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700845 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800846 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800847 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800848 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700849 } else {
850 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000851 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700852 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700853 break;
854
855 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800856 ar = (AsyncResult) msg.obj;
857 request = (MainThreadRequest) ar.userObj;
858 if (ar.exception == null) {
859 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800860 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700861 if (uiccPort == null) {
862 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
863 } else {
864 final int channelId = (Integer) request.argument;
865 uiccPort.onLogicalChannelClosed(channelId);
866 }
Chen Xu540470b2021-12-14 17:15:47 -0800867 } else {
868 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800869 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800870 if (ar.exception instanceof CommandException) {
871 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
872 CommandException.Error error =
873 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800874 if (error == CommandException.Error.INVALID_ARGUMENTS) {
875 // should only throw exceptions from the binder threads.
876 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800877 "iccCloseLogicalChannel: invalid argument ");
878 }
879 } else {
880 loge("iccCloseLogicalChannel: Unknown exception");
881 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800882 request.result = (exception != null) ? exception :
883 new IllegalStateException(
884 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800885 }
886 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800887 break;
888
889 case CMD_NV_READ_ITEM:
890 request = (MainThreadRequest) msg.obj;
891 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800892 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
893 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800894 break;
895
896 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700897 ar = (AsyncResult) msg.obj;
898 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800899 if (ar.exception == null && ar.result != null) {
900 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700901 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800902 request.result = "";
903 if (ar.result == null) {
904 loge("nvReadItem: Empty response");
905 } else if (ar.exception instanceof CommandException) {
906 loge("nvReadItem: CommandException: " +
907 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700908 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800909 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700910 }
911 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700912 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700913 break;
914
Jake Hambye994d462014-02-03 13:10:13 -0800915 case CMD_NV_WRITE_ITEM:
916 request = (MainThreadRequest) msg.obj;
917 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
918 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800919 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700920 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800921 break;
922
923 case EVENT_NV_WRITE_ITEM_DONE:
924 handleNullReturnEvent(msg, "nvWriteItem");
925 break;
926
927 case CMD_NV_WRITE_CDMA_PRL:
928 request = (MainThreadRequest) msg.obj;
929 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800930 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800931 break;
932
933 case EVENT_NV_WRITE_CDMA_PRL_DONE:
934 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
935 break;
936
chen xu6dac5ab2018-10-26 17:39:23 -0700937 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800938 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700939 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800940 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800941 break;
942
chen xu6dac5ab2018-10-26 17:39:23 -0700943 case EVENT_RESET_MODEM_CONFIG_DONE:
944 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800945 break;
946
Sooraj Sasindran37444802020-08-11 10:40:43 -0700947 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
948 request = (MainThreadRequest) msg.obj;
949 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
950 request);
951 Phone phone = getPhoneFromRequest(request);
952 if (phone != null) {
953 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
954 } else {
955 loge("isNRDualConnectivityEnabled: No phone object");
956 request.result = false;
957 notifyRequester(request);
958 }
959 break;
960 }
961
962 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
963 ar = (AsyncResult) msg.obj;
964 request = (MainThreadRequest) ar.userObj;
965 if (ar.exception == null && ar.result != null) {
966 request.result = ar.result;
967 } else {
968 // request.result must be set to something non-null
969 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700970 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700971 request.result = ar.result;
972 } else {
973 request.result = false;
974 }
975 if (ar.result == null) {
976 loge("isNRDualConnectivityEnabled: Empty response");
977 } else if (ar.exception instanceof CommandException) {
978 loge("isNRDualConnectivityEnabled: CommandException: "
979 + ar.exception);
980 } else {
981 loge("isNRDualConnectivityEnabled: Unknown exception");
982 }
983 }
984 notifyRequester(request);
985 break;
986
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700987 case CMD_IS_VONR_ENABLED: {
988 request = (MainThreadRequest) msg.obj;
989 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
990 request);
991 Phone phone = getPhoneFromRequest(request);
992 if (phone != null) {
993 phone.isVoNrEnabled(onCompleted, request.workSource);
994 } else {
995 loge("isVoNrEnabled: No phone object");
996 request.result = false;
997 notifyRequester(request);
998 }
999 break;
1000 }
1001
1002 case EVENT_IS_VONR_ENABLED_DONE:
1003 ar = (AsyncResult) msg.obj;
1004 request = (MainThreadRequest) ar.userObj;
1005 if (ar.exception == null && ar.result != null) {
1006 request.result = ar.result;
1007 } else {
1008 // request.result must be set to something non-null
1009 // for the calling thread to unblock
1010 if (ar.result != null) {
1011 request.result = ar.result;
1012 } else {
1013 request.result = false;
1014 }
1015 if (ar.result == null) {
1016 loge("isVoNrEnabled: Empty response");
1017 } else if (ar.exception instanceof CommandException) {
1018 loge("isVoNrEnabled: CommandException: "
1019 + ar.exception);
1020 } else {
1021 loge("isVoNrEnabled: Unknown exception");
1022 }
1023 }
1024 notifyRequester(request);
1025 break;
1026
Sooraj Sasindran37444802020-08-11 10:40:43 -07001027 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1028 request = (MainThreadRequest) msg.obj;
1029 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1030 Phone phone = getPhoneFromRequest(request);
1031 if (phone != null) {
1032 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1033 request.workSource);
1034 } else {
1035 loge("enableNrDualConnectivity: No phone object");
1036 request.result =
1037 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1038 notifyRequester(request);
1039 }
1040 break;
1041 }
1042
1043 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1044 ar = (AsyncResult) msg.obj;
1045 request = (MainThreadRequest) ar.userObj;
1046 if (ar.exception == null) {
1047 request.result =
1048 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1049 } else {
1050 request.result =
1051 TelephonyManager
1052 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1053 if (ar.exception instanceof CommandException) {
1054 CommandException.Error error =
1055 ((CommandException) (ar.exception)).getCommandError();
1056 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1057 request.result =
1058 TelephonyManager
1059 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001060 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1061 request.result =
1062 TelephonyManager
1063 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001064 }
1065 loge("enableNrDualConnectivity" + ": CommandException: "
1066 + ar.exception);
1067 } else {
1068 loge("enableNrDualConnectivity" + ": Unknown exception");
1069 }
1070 }
1071 notifyRequester(request);
1072 break;
1073 }
1074
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001075 case CMD_ENABLE_VONR: {
1076 request = (MainThreadRequest) msg.obj;
1077 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1078 Phone phone = getPhoneFromRequest(request);
1079 if (phone != null) {
1080 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1081 request.workSource);
1082 } else {
1083 loge("setVoNrEnabled: No phone object");
1084 request.result =
1085 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1086 notifyRequester(request);
1087 }
1088 break;
1089 }
1090
1091 case EVENT_ENABLE_VONR_DONE: {
1092 ar = (AsyncResult) msg.obj;
1093 request = (MainThreadRequest) ar.userObj;
1094 if (ar.exception == null) {
1095 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1096 } else {
1097 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1098 if (ar.exception instanceof CommandException) {
1099 CommandException.Error error =
1100 ((CommandException) (ar.exception)).getCommandError();
1101 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1102 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1103 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1104 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1105 } else {
1106 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1107 }
1108 loge("setVoNrEnabled" + ": CommandException: "
1109 + ar.exception);
1110 } else {
1111 loge("setVoNrEnabled" + ": Unknown exception");
1112 }
1113 }
1114 notifyRequester(request);
1115 break;
1116 }
1117
SongFerngWang3ef3e072020-12-21 16:41:52 +08001118 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001119 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001120 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1121 request);
1122 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001123 break;
1124
SongFerngWang3ef3e072020-12-21 16:41:52 +08001125 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001126 ar = (AsyncResult) msg.obj;
1127 request = (MainThreadRequest) ar.userObj;
1128 if (ar.exception == null && ar.result != null) {
1129 request.result = ar.result; // Integer
1130 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301131 // request.result must be set to something non-null
1132 // for the calling thread to unblock
1133 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001134 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001135 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001136 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001137 loge("getAllowedNetworkTypesBitmask: CommandException: "
1138 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001139 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001140 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001141 }
1142 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001143 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001144 break;
1145
SongFerngWang3ef3e072020-12-21 16:41:52 +08001146 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001147 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001148 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1149 request);
1150 Pair<Integer, Long> reasonWithNetworkTypes =
1151 (Pair<Integer, Long>) request.argument;
1152 getPhoneFromRequest(request).setAllowedNetworkTypes(
1153 reasonWithNetworkTypes.first,
1154 reasonWithNetworkTypes.second,
1155 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001156 break;
1157
SongFerngWang3ef3e072020-12-21 16:41:52 +08001158 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1159 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001160 break;
1161
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001162 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1163 request = (MainThreadRequest)msg.obj;
1164 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001165 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001166 break;
1167
1168 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1169 ar = (AsyncResult)msg.obj;
1170 request = (MainThreadRequest)ar.userObj;
1171 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001172 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001173 break;
1174
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001175 case CMD_SET_VOICEMAIL_NUMBER:
1176 request = (MainThreadRequest) msg.obj;
1177 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1178 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001179 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1180 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001181 break;
1182
1183 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1184 handleNullReturnEvent(msg, "setVoicemailNumber");
1185 break;
1186
Stuart Scott54788802015-03-30 13:18:01 -07001187 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1188 request = (MainThreadRequest) msg.obj;
1189 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1190 request);
1191 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1192 break;
1193
1194 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1195 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1196 break;
1197
Shishir Agrawal302c8692015-06-19 13:49:39 -07001198 case CMD_PERFORM_NETWORK_SCAN:
1199 request = (MainThreadRequest) msg.obj;
1200 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1201 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1202 break;
1203
Hall Liu27d24262020-09-18 19:04:59 -07001204 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001205 request = (MainThreadRequest) msg.obj;
1206 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001207 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1208 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1209 request.argument;
1210 int callForwardingReason = args.first;
1211 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001212 break;
Hall Liu27d24262020-09-18 19:04:59 -07001213 }
1214 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001215 ar = (AsyncResult) msg.obj;
1216 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001217 TelephonyManager.CallForwardingInfoCallback callback =
1218 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1219 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001220 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001221 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001222 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1223 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1224 // Service Class is a bit mask per 3gpp 27.007. Search for
1225 // any service for voice call.
1226 if ((callForwardInfo.serviceClass
1227 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001228 callForwardingInfo = new CallForwardingInfo(
1229 callForwardInfo.status
1230 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001231 callForwardInfo.reason,
1232 callForwardInfo.number,
1233 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001234 break;
1235 }
1236 }
1237 // Didn't find a call forward info for voice call.
1238 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001239 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1240 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001241 }
Hall Liu27d24262020-09-18 19:04:59 -07001242 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001243 } else {
1244 if (ar.result == null) {
1245 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1246 }
1247 if (ar.exception != null) {
1248 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1249 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001250 int errorCode = TelephonyManager
1251 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001252 if (ar.exception instanceof CommandException) {
1253 CommandException.Error error =
1254 ((CommandException) (ar.exception)).getCommandError();
1255 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001256 errorCode = TelephonyManager
1257 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001258 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001259 errorCode = TelephonyManager
1260 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001261 }
1262 }
Hall Liu27d24262020-09-18 19:04:59 -07001263 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001264 }
Shuo Qian4a594052020-01-23 11:59:30 -08001265 break;
Hall Liu27d24262020-09-18 19:04:59 -07001266 }
Shuo Qian4a594052020-01-23 11:59:30 -08001267
Hall Liu27d24262020-09-18 19:04:59 -07001268 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001269 request = (MainThreadRequest) msg.obj;
1270 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001271 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001272 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001273 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1274 request.argument).first;
1275 request.phone.setCallForwardingOption(
1276 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001277 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001278 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001279 callForwardingInfoToSet.getReason(),
1280 callForwardingInfoToSet.getNumber(),
1281 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1282 break;
Hall Liu27d24262020-09-18 19:04:59 -07001283 }
Shuo Qian4a594052020-01-23 11:59:30 -08001284
Hall Liu27d24262020-09-18 19:04:59 -07001285 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001286 ar = (AsyncResult) msg.obj;
1287 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001288 Consumer<Integer> callback =
1289 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1290 request.argument).second;
1291 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001292 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001293 int errorCode = TelephonyManager.CallForwardingInfoCallback
1294 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001295 if (ar.exception instanceof CommandException) {
1296 CommandException.Error error =
1297 ((CommandException) (ar.exception)).getCommandError();
1298 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001299 errorCode = TelephonyManager.CallForwardingInfoCallback
1300 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001301 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001302 errorCode = TelephonyManager.CallForwardingInfoCallback
1303 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001304 }
1305 }
1306 callback.accept(errorCode);
1307 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001308 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001309 }
Shuo Qian4a594052020-01-23 11:59:30 -08001310 break;
Hall Liu27d24262020-09-18 19:04:59 -07001311 }
Shuo Qian4a594052020-01-23 11:59:30 -08001312
Hall Liu27d24262020-09-18 19:04:59 -07001313 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001314 request = (MainThreadRequest) msg.obj;
1315 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1316 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1317 break;
Hall Liu27d24262020-09-18 19:04:59 -07001318 }
Shuo Qian4a594052020-01-23 11:59:30 -08001319
Hall Liu27d24262020-09-18 19:04:59 -07001320 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001321 ar = (AsyncResult) msg.obj;
1322 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001323 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001324 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001325 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001326 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001327 // Service Class is a bit mask per 3gpp 27.007.
1328 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001329 if (callForwardResults.length > 1
1330 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001331 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001332 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001333 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1334 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001335 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001336 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001337 }
1338 } else {
1339 if (ar.result == null) {
1340 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1341 }
1342 if (ar.exception != null) {
1343 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1344 }
1345 if (ar.exception instanceof CommandException) {
1346 CommandException.Error error =
1347 ((CommandException) (ar.exception)).getCommandError();
1348 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001349 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001350 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001351 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1352 callWaitingStatus =
1353 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001354 }
1355 }
1356 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001357 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001358 break;
Hall Liu27d24262020-09-18 19:04:59 -07001359 }
Shuo Qian4a594052020-01-23 11:59:30 -08001360
Hall Liu27d24262020-09-18 19:04:59 -07001361 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001362 request = (MainThreadRequest) msg.obj;
1363 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001364 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1365 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001366 break;
Hall Liu27d24262020-09-18 19:04:59 -07001367 }
Shuo Qian4a594052020-01-23 11:59:30 -08001368
Hall Liu27d24262020-09-18 19:04:59 -07001369 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001370 ar = (AsyncResult) msg.obj;
1371 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001372 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1373 Consumer<Integer> callback =
1374 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1375 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001376 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001377 if (ar.exception instanceof CommandException) {
1378 CommandException.Error error =
1379 ((CommandException) (ar.exception)).getCommandError();
1380 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1381 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001382 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1383 callback.accept(
1384 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001385 } else {
1386 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1387 }
1388 } else {
1389 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1390 }
1391 } else {
1392 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1393 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001394 }
Shuo Qian4a594052020-01-23 11:59:30 -08001395 break;
Hall Liu27d24262020-09-18 19:04:59 -07001396 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001397 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1398 ar = (AsyncResult) msg.obj;
1399 request = (MainThreadRequest) ar.userObj;
1400 CellNetworkScanResult cellScanResult;
1401 if (ar.exception == null && ar.result != null) {
1402 cellScanResult = new CellNetworkScanResult(
1403 CellNetworkScanResult.STATUS_SUCCESS,
1404 (List<OperatorInfo>) ar.result);
1405 } else {
1406 if (ar.result == null) {
1407 loge("getCellNetworkScanResults: Empty response");
1408 }
1409 if (ar.exception != null) {
1410 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1411 }
1412 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1413 if (ar.exception instanceof CommandException) {
1414 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001415 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001416 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1417 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1418 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1419 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1420 }
1421 }
1422 cellScanResult = new CellNetworkScanResult(errorCode, null);
1423 }
1424 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001425 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001426 break;
1427
1428 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1429 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001430 ManualNetworkSelectionArgument selArg =
1431 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001432 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1433 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001434 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1435 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001436 break;
1437
1438 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001439 ar = (AsyncResult) msg.obj;
1440 request = (MainThreadRequest) ar.userObj;
1441 if (ar.exception == null) {
1442 request.result = true;
1443 } else {
1444 request.result = false;
1445 loge("setNetworkSelectionModeManual " + ar.exception);
1446 }
1447 notifyRequester(request);
1448 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001449 break;
1450
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001451 case CMD_GET_MODEM_ACTIVITY_INFO:
1452 request = (MainThreadRequest) msg.obj;
1453 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001454 if (defaultPhone != null) {
1455 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001456 } else {
1457 ResultReceiver result = (ResultReceiver) request.argument;
1458 Bundle bundle = new Bundle();
1459 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001460 new ModemActivityInfo(0, 0, 0,
1461 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001462 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001463 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001464 break;
1465
Hall Liud0f208c2020-10-14 16:54:44 -07001466 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001467 ar = (AsyncResult) msg.obj;
1468 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001469 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001470 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001471 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001472 if (mLastModemActivityInfo == null) {
1473 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1474 mLastModemActivitySpecificInfo[0] =
1475 new ActivityStatsTechSpecificInfo(
1476 0,
1477 0,
1478 new int[ModemActivityInfo.getNumTxPowerLevels()],
1479 0);
1480 mLastModemActivityInfo =
1481 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1482 }
1483
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001484 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001485 // Update the last modem activity info and the result of the request.
1486 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1487 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001488 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001489 } else {
1490 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001491 }
Kai Shi917fdc62022-11-28 14:01:02 -08001492 // This is needed to decouple ret from mLastModemActivityInfo
1493 // We don't want to return mLastModemActivityInfo which is updated
1494 // inside mergeModemActivityInfo()
1495 ret = new ModemActivityInfo(
1496 mLastModemActivityInfo.getTimestampMillis(),
1497 mLastModemActivityInfo.getSleepTimeMillis(),
1498 mLastModemActivityInfo.getIdleTimeMillis(),
1499 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001500
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001501 } else {
1502 if (ar.result == null) {
1503 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001504 error = TelephonyManager.ModemActivityInfoException
1505 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001506 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001507 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001508 error = TelephonyManager.ModemActivityInfoException
1509 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001510 } else {
1511 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001512 error = TelephonyManager.ModemActivityInfoException
1513 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001514 }
1515 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001516 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001517 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001518 bundle.putParcelable(
1519 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001520 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001521 } else {
1522 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1523 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001524 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001525 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001526 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001527 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001528
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001529 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001530 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001531 CarrierRestrictionRules argument =
1532 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001533 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001534 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001535 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001536 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001537
1538 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1539 ar = (AsyncResult) msg.obj;
1540 request = (MainThreadRequest) ar.userObj;
1541 if (ar.exception == null && ar.result != null) {
1542 request.result = ar.result;
1543 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001544 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1545 if (ar.exception instanceof CommandException) {
1546 loge("setAllowedCarriers: CommandException: " + ar.exception);
1547 CommandException.Error error =
1548 ((CommandException) (ar.exception)).getCommandError();
1549 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1550 request.result =
1551 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1552 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001553 } else {
1554 loge("setAllowedCarriers: Unknown exception");
1555 }
1556 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001557 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001558 break;
1559
1560 case CMD_GET_ALLOWED_CARRIERS:
1561 request = (MainThreadRequest) msg.obj;
1562 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001563 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001564 break;
1565
1566 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1567 ar = (AsyncResult) msg.obj;
1568 request = (MainThreadRequest) ar.userObj;
1569 if (ar.exception == null && ar.result != null) {
1570 request.result = ar.result;
1571 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001572 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001573 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001574 if (ar.result == null) {
1575 loge("getAllowedCarriers: Empty response");
1576 } else if (ar.exception instanceof CommandException) {
1577 loge("getAllowedCarriers: CommandException: " +
1578 ar.exception);
1579 } else {
1580 loge("getAllowedCarriers: Unknown exception");
1581 }
1582 }
arunvoddud7401012022-12-15 16:08:12 +00001583 if (request.argument != null) {
1584 // This is for the implementation of carrierRestrictionStatus.
1585 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1586 Consumer<Integer> callback = callbackInfo.getConsumer();
1587 int callerCarrierId = callbackInfo.getCarrierId();
1588 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1589 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1590 CarrierRestrictionRules carrierRestrictionRules =
1591 (CarrierRestrictionRules) ar.result;
1592 int carrierId = -1;
1593 try {
1594 CarrierIdentifier carrierIdentifier =
1595 carrierRestrictionRules.getAllowedCarriers().get(0);
1596 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1597 carrierIdentifier);
1598 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1599 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1600 }
1601 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1602 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1603 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001604 lockStatus = TelephonyManager
1605 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001606 }
1607 } else {
1608 Rlog.e(LOG_TAG,
1609 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1610 }
1611 callback.accept(lockStatus);
1612 } else {
1613 // This is for the implementation of getAllowedCarriers.
1614 notifyRequester(request);
1615 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001616 break;
1617
Nathan Haroldb3014052017-01-25 15:57:32 -08001618 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1619 ar = (AsyncResult) msg.obj;
1620 request = (MainThreadRequest) ar.userObj;
1621 if (ar.exception == null && ar.result != null) {
1622 request.result = ar.result;
1623 } else {
1624 request.result = new IllegalArgumentException(
1625 "Failed to retrieve Forbidden Plmns");
1626 if (ar.result == null) {
1627 loge("getForbiddenPlmns: Empty response");
1628 } else {
1629 loge("getForbiddenPlmns: Unknown exception");
1630 }
1631 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001632 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001633 break;
1634
1635 case CMD_GET_FORBIDDEN_PLMNS:
1636 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001637 uiccPort = getUiccPortFromRequest(request);
1638 if (uiccPort == null) {
1639 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001640 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001641 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001642 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001643 break;
1644 }
1645 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001646 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001647 if (uiccApp == null) {
1648 loge("getForbiddenPlmns() no app with specified type -- "
1649 + appType);
1650 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001651 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001652 break;
1653 } else {
1654 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1655 + " specified type -- " + appType);
1656 }
1657 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1658 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001659 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001660 break;
1661
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001662 case CMD_SWITCH_SLOTS:
1663 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001664 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001665 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001666 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001667 break;
1668
1669 case EVENT_SWITCH_SLOTS_DONE:
1670 ar = (AsyncResult) msg.obj;
1671 request = (MainThreadRequest) ar.userObj;
1672 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001673 notifyRequester(request);
1674 break;
1675 case CMD_GET_NETWORK_SELECTION_MODE:
1676 request = (MainThreadRequest) msg.obj;
1677 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1678 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1679 break;
1680
1681 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1682 ar = (AsyncResult) msg.obj;
1683 request = (MainThreadRequest) ar.userObj;
1684 if (ar.exception != null) {
1685 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1686 } else {
1687 int mode = ((int[]) ar.result)[0];
1688 if (mode == 0) {
1689 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1690 } else {
1691 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1692 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001693 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001694 notifyRequester(request);
1695 break;
1696 case CMD_GET_CDMA_ROAMING_MODE:
1697 request = (MainThreadRequest) msg.obj;
1698 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1699 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1700 break;
1701 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1702 ar = (AsyncResult) msg.obj;
1703 request = (MainThreadRequest) ar.userObj;
1704 if (ar.exception != null) {
1705 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1706 } else {
1707 request.result = ((int[]) ar.result)[0];
1708 }
1709 notifyRequester(request);
1710 break;
1711 case CMD_SET_CDMA_ROAMING_MODE:
1712 request = (MainThreadRequest) msg.obj;
1713 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1714 int mode = (int) request.argument;
1715 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1716 break;
1717 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1718 ar = (AsyncResult) msg.obj;
1719 request = (MainThreadRequest) ar.userObj;
1720 request.result = ar.exception == null;
1721 notifyRequester(request);
1722 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001723 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1724 request = (MainThreadRequest) msg.obj;
1725 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1726 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1727 break;
1728 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1729 ar = (AsyncResult) msg.obj;
1730 request = (MainThreadRequest) ar.userObj;
1731 if (ar.exception != null) {
1732 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1733 } else {
1734 request.result = ((int[]) ar.result)[0];
1735 }
1736 notifyRequester(request);
1737 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001738 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1739 request = (MainThreadRequest) msg.obj;
1740 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1741 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001742 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1743 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001744 break;
1745 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1746 ar = (AsyncResult) msg.obj;
1747 request = (MainThreadRequest) ar.userObj;
1748 request.result = ar.exception == null;
1749 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001750 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001751 case CMD_GET_ALL_CELL_INFO:
1752 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001753 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001754 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001755 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001756 case EVENT_GET_ALL_CELL_INFO_DONE:
1757 ar = (AsyncResult) msg.obj;
1758 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001759 // If a timeout occurs, the response will be null
1760 request.result = (ar.exception == null && ar.result != null)
1761 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001762 synchronized (request) {
1763 request.notifyAll();
1764 }
1765 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001766 case CMD_REQUEST_CELL_INFO_UPDATE:
1767 request = (MainThreadRequest) msg.obj;
1768 request.phone.requestCellInfoUpdate(request.workSource,
1769 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1770 break;
1771 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1772 ar = (AsyncResult) msg.obj;
1773 request = (MainThreadRequest) ar.userObj;
1774 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1775 try {
1776 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001777 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001778 cb.onError(
1779 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1780 ar.exception.getClass().getName(),
1781 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001782 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001783 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001784 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001785 } else {
1786 // use the result as returned
1787 cb.onCellInfo((List<CellInfo>) ar.result);
1788 }
1789 } catch (RemoteException re) {
1790 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1791 }
1792 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001793 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001794 request = (MainThreadRequest) msg.obj;
1795 WorkSource ws = (WorkSource) request.argument;
1796 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001797 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001798 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001799 }
1800 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001801 ar = (AsyncResult) msg.obj;
1802 request = (MainThreadRequest) ar.userObj;
1803 if (ar.exception == null) {
1804 request.result = ar.result;
1805 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001806 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001807 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001808 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001809 }
1810
1811 synchronized (request) {
1812 request.notifyAll();
1813 }
1814 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001815 }
chen xu6dac5ab2018-10-26 17:39:23 -07001816 case CMD_MODEM_REBOOT:
1817 request = (MainThreadRequest) msg.obj;
1818 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001819 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001820 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001821 case EVENT_CMD_MODEM_REBOOT_DONE:
1822 handleNullReturnEvent(msg, "rebootModem");
1823 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001824 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001825 request = (MainThreadRequest) msg.obj;
1826 boolean enable = (boolean) request.argument;
1827 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001828 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001829 PhoneConfigurationManager.getInstance()
1830 .enablePhone(request.phone, enable, onCompleted);
1831 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001832 }
Michele Berionne5e411512020-11-13 02:36:59 +00001833 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001834 ar = (AsyncResult) msg.obj;
1835 request = (MainThreadRequest) ar.userObj;
1836 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001837 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001838 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001839 if ((boolean) request.result) {
1840 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1841 updateModemStateMetrics();
1842 } else {
1843 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1844 + ar.exception);
1845 }
1846 notifyRequester(request);
1847 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001848 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001849 case CMD_GET_MODEM_STATUS:
1850 request = (MainThreadRequest) msg.obj;
1851 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1852 PhoneConfigurationManager.getInstance()
1853 .getPhoneStatusFromModem(request.phone, onCompleted);
1854 break;
1855 case EVENT_GET_MODEM_STATUS_DONE:
1856 ar = (AsyncResult) msg.obj;
1857 request = (MainThreadRequest) ar.userObj;
1858 int id = request.phone.getPhoneId();
1859 if (ar.exception == null && ar.result != null) {
1860 request.result = ar.result;
1861 //update the cache as modem status has changed
1862 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1863 (boolean) request.result);
1864 } else {
1865 // Return true if modem status cannot be retrieved. For most cases,
1866 // modem status is on. And for older version modems, GET_MODEM_STATUS
1867 // and disable modem are not supported. Modem is always on.
1868 // TODO: this should be fixed in R to support a third
1869 // status UNKNOWN b/131631629
1870 request.result = true;
1871 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1872 + ar.exception);
1873 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001874 notifyRequester(request);
1875 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001876 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1877 request = (MainThreadRequest) msg.obj;
1878 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1879 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1880 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1881 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1882 break;
1883 }
1884 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1885 ar = (AsyncResult) msg.obj;
1886 request = (MainThreadRequest) ar.userObj;
1887 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1888 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1889 args.second.accept(ar.exception == null);
1890 notifyRequester(request);
1891 break;
1892 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001893 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1894 request = (MainThreadRequest) msg.obj;
1895 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1896 Phone phone = getPhoneFromRequest(request);
1897 if (phone != null) {
1898 phone.getSystemSelectionChannels(onCompleted);
1899 } else {
1900 loge("getSystemSelectionChannels: No phone object");
1901 request.result = new ArrayList<RadioAccessSpecifier>();
1902 notifyRequester(request);
1903 }
1904 break;
1905 }
1906 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1907 ar = (AsyncResult) msg.obj;
1908 request = (MainThreadRequest) ar.userObj;
1909 if (ar.exception == null && ar.result != null) {
1910 request.result = ar.result;
1911 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001912 request.result = new IllegalStateException(
1913 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001914 if (ar.result == null) {
1915 loge("getSystemSelectionChannels: Empty response");
1916 } else {
1917 loge("getSystemSelectionChannels: Unknown exception");
1918 }
1919 }
1920 notifyRequester(request);
1921 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001922 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1923 ar = (AsyncResult) msg.obj;
1924 request = (MainThreadRequest) ar.userObj;
1925 if (ar.exception == null && ar.result != null) {
1926 request.result = ar.result;
1927 } else {
1928 request.result = -1;
1929 loge("Failed to set Forbidden Plmns");
1930 if (ar.result == null) {
1931 loge("setForbidenPlmns: Empty response");
1932 } else if (ar.exception != null) {
1933 loge("setForbiddenPlmns: Exception: " + ar.exception);
1934 request.result = -1;
1935 } else {
1936 loge("setForbiddenPlmns: Unknown exception");
1937 }
1938 }
1939 notifyRequester(request);
1940 break;
1941 case CMD_SET_FORBIDDEN_PLMNS:
1942 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001943 uiccPort = getUiccPortFromRequest(request);
1944 if (uiccPort == null) {
1945 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001946 request.result = -1;
1947 notifyRequester(request);
1948 break;
1949 }
1950 Pair<Integer, List<String>> setFplmnsArgs =
1951 (Pair<Integer, List<String>>) request.argument;
1952 appType = setFplmnsArgs.first;
1953 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001954 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001955 if (uiccApp == null) {
1956 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1957 request.result = -1;
1958 loge("Failed to get UICC App");
1959 notifyRequester(request);
1960 } else {
1961 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1962 ((SIMRecords) uiccApp.getIccRecords())
1963 .setForbiddenPlmns(onCompleted, fplmns);
1964 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001965 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001966 case CMD_ERASE_MODEM_CONFIG:
1967 request = (MainThreadRequest) msg.obj;
1968 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1969 defaultPhone.eraseModemConfig(onCompleted);
1970 break;
1971 case EVENT_ERASE_MODEM_CONFIG_DONE:
1972 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001973 break;
zoey chene02881a2019-12-30 16:11:23 +08001974
Kai Shif70f46f2021-03-03 13:59:46 -08001975 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1976 request = (MainThreadRequest) msg.obj;
1977 request.result = defaultPhone.eraseDataInSharedPreferences();
1978 notifyRequester(request);
1979 break;
1980
zoey chene02881a2019-12-30 16:11:23 +08001981 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1982 request = (MainThreadRequest) msg.obj;
1983 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1984 Pair<String, String> changed = (Pair<String, String>) request.argument;
1985 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1986 changed.first, changed.second, onCompleted);
1987 break;
1988 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1989 ar = (AsyncResult) msg.obj;
1990 request = (MainThreadRequest) ar.userObj;
1991 if (ar.exception == null) {
1992 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001993 // If the operation is successful, update the PIN storage
1994 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1995 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001996 UiccController.getInstance().getPinStorage()
1997 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001998 } else {
1999 request.result = msg.arg1;
2000 }
2001 notifyRequester(request);
2002 break;
2003
Michele Berionne5e411512020-11-13 02:36:59 +00002004 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002005 request = (MainThreadRequest) msg.obj;
2006 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2007 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2008 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2009 enabled.first, enabled.second, onCompleted);
2010 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002011 }
zoey chene02881a2019-12-30 16:11:23 +08002012 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2013 ar = (AsyncResult) msg.obj;
2014 request = (MainThreadRequest) ar.userObj;
2015 if (ar.exception == null) {
2016 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002017 // If the operation is successful, update the PIN storage
2018 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2019 int phoneId = getPhoneFromRequest(request).getPhoneId();
2020 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002021 UiccController.getInstance().getPinStorage()
2022 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002023 } else {
2024 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2025 }
zoey chene02881a2019-12-30 16:11:23 +08002026 } else {
2027 request.result = msg.arg1;
2028 }
Michele Berionne5e411512020-11-13 02:36:59 +00002029
2030
zoey chene02881a2019-12-30 16:11:23 +08002031 notifyRequester(request);
2032 break;
2033
Peter Wangdafb9ac2020-01-15 14:13:38 -08002034 case MSG_NOTIFY_USER_ACTIVITY:
2035 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002036 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002037 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2038 getDefaultPhone().getContext().sendBroadcastAsUser(
2039 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2040 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002041
2042 case CMD_SET_DATA_THROTTLING: {
2043 request = (MainThreadRequest) msg.obj;
2044 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2045 DataThrottlingRequest dataThrottlingRequest =
2046 (DataThrottlingRequest) request.argument;
2047 Phone phone = getPhoneFromRequest(request);
2048 if (phone != null) {
2049 phone.setDataThrottling(onCompleted,
2050 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2051 dataThrottlingRequest.getCompletionDurationMillis());
2052 } else {
2053 loge("setDataThrottling: No phone object");
2054 request.result =
2055 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2056 notifyRequester(request);
2057 }
2058
2059 break;
2060 }
2061 case EVENT_SET_DATA_THROTTLING_DONE:
2062 ar = (AsyncResult) msg.obj;
2063 request = (MainThreadRequest) ar.userObj;
2064
2065 if (ar.exception == null) {
2066 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2067 } else if (ar.exception instanceof CommandException) {
2068 loge("setDataThrottling: CommandException: " + ar.exception);
2069 CommandException.Error error =
2070 ((CommandException) (ar.exception)).getCommandError();
2071
2072 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2073 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002074 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002075 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2076 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002077 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2078 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002079 } else {
2080 request.result =
2081 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2082 }
2083 } else {
2084 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2085 }
2086 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2087 notifyRequester(request);
2088 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002089
2090 case CMD_SET_SIM_POWER: {
2091 request = (MainThreadRequest) msg.obj;
2092 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2093 request = (MainThreadRequest) msg.obj;
2094 int stateToSet =
2095 ((Pair<Integer, IIntegerConsumer>)
2096 request.argument).first;
2097 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2098 break;
2099 }
2100 case EVENT_SET_SIM_POWER_DONE: {
2101 ar = (AsyncResult) msg.obj;
2102 request = (MainThreadRequest) ar.userObj;
2103 IIntegerConsumer callback =
2104 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2105 if (ar.exception != null) {
2106 loge("setSimPower exception: " + ar.exception);
2107 int errorCode = TelephonyManager.CallForwardingInfoCallback
2108 .RESULT_ERROR_UNKNOWN;
2109 if (ar.exception instanceof CommandException) {
2110 CommandException.Error error =
2111 ((CommandException) (ar.exception)).getCommandError();
2112 if (error == CommandException.Error.SIM_ERR) {
2113 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2114 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2115 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2116 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2117 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2118 } else {
2119 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2120 }
2121 }
2122 try {
2123 callback.accept(errorCode);
2124 } catch (RemoteException e) {
2125 // Ignore if the remote process is no longer available to call back.
2126 Log.w(LOG_TAG, "setSimPower: callback not available.");
2127 }
2128 } else {
2129 try {
2130 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2131 } catch (RemoteException e) {
2132 // Ignore if the remote process is no longer available to call back.
2133 Log.w(LOG_TAG, "setSimPower: callback not available.");
2134 }
2135 }
2136 break;
2137 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002138 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2139 request = (MainThreadRequest) msg.obj;
2140
2141 final Phone phone = getPhoneFromRequest(request);
2142 if (phone == null || phone.getServiceStateTracker() == null) {
2143 request.result = new IllegalStateException("Phone or SST is null");
2144 notifyRequester(request);
2145 break;
2146 }
2147
2148 Pair<Integer, SignalStrengthUpdateRequest> pair =
2149 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2150 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2151 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002152 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002153 request.subId, pair.first /*callingUid*/,
2154 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002155 break;
2156 }
2157 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2158 ar = (AsyncResult) msg.obj;
2159 request = (MainThreadRequest) ar.userObj;
2160 // request.result will be the exception of ar if present, true otherwise.
2161 // Be cautious not to leave result null which will wait() forever
2162 request.result = ar.exception != null ? ar.exception : true;
2163 notifyRequester(request);
2164 break;
2165 }
2166 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2167 request = (MainThreadRequest) msg.obj;
2168
2169 Phone phone = getPhoneFromRequest(request);
2170 if (phone == null || phone.getServiceStateTracker() == null) {
2171 request.result = new IllegalStateException("Phone or SST is null");
2172 notifyRequester(request);
2173 break;
2174 }
2175
2176 Pair<Integer, SignalStrengthUpdateRequest> pair =
2177 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2178 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2179 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002180 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002181 request.subId, pair.first /*callingUid*/,
2182 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002183 break;
2184 }
2185 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2186 ar = (AsyncResult) msg.obj;
2187 request = (MainThreadRequest) ar.userObj;
2188 request.result = ar.exception != null ? ar.exception : true;
2189 notifyRequester(request);
2190 break;
2191 }
Jordan Liu109698e2020-11-24 14:50:34 -08002192
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002193 case CMD_GET_SLICING_CONFIG: {
2194 request = (MainThreadRequest) msg.obj;
2195 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2196 request.phone.getSlicingConfig(onCompleted);
2197 break;
2198 }
2199 case EVENT_GET_SLICING_CONFIG_DONE: {
2200 ar = (AsyncResult) msg.obj;
2201 request = (MainThreadRequest) ar.userObj;
2202 ResultReceiver result = (ResultReceiver) request.argument;
2203
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002204 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002205 Bundle bundle = new Bundle();
2206 int resultCode = 0;
2207 if (ar.exception != null) {
2208 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2209 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002210 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002211 } else if (ar.result == null) {
2212 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002213 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002214 } else {
2215 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002216 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2217 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002218 }
2219
2220 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002221 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002222 }
2223 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2224 result.send(resultCode, bundle);
2225 notifyRequester(request);
2226 break;
2227 }
2228
Sarah Chin71b3a852022-09-28 15:54:19 -07002229 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002230 request = (MainThreadRequest) msg.obj;
2231 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002232 PurchasePremiumCapabilityArgument arg =
2233 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002234 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chinb8218c22023-01-04 13:35:29 -08002235 arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002236 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002237 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002238
Sarah Chin71b3a852022-09-28 15:54:19 -07002239 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002240 ar = (AsyncResult) msg.obj;
2241 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002242 PurchasePremiumCapabilityArgument arg =
2243 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002244 try {
2245 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002246 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002247 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002248 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002249 + ", result= "
2250 + TelephonyManager.convertPurchaseResultToString(result));
2251 } catch (RemoteException e) {
2252 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002253 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002254 + " failed: " + e;
2255 if (DBG) log(logStr);
2256 AnomalyReporter.reportAnomaly(
2257 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2258 }
2259 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002260 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002261
Michele Berionne5e411512020-11-13 02:36:59 +00002262 case CMD_PREPARE_UNATTENDED_REBOOT:
2263 request = (MainThreadRequest) msg.obj;
2264 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002265 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002266 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002267 notifyRequester(request);
2268 break;
2269
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270 default:
2271 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2272 break;
2273 }
2274 }
Jake Hambye994d462014-02-03 13:10:13 -08002275
Pengquan Menga1bb6272018-09-06 09:59:22 -07002276 private void notifyRequester(MainThreadRequest request) {
2277 synchronized (request) {
2278 request.notifyAll();
2279 }
2280 }
2281
Jake Hambye994d462014-02-03 13:10:13 -08002282 private void handleNullReturnEvent(Message msg, String command) {
2283 AsyncResult ar = (AsyncResult) msg.obj;
2284 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2285 if (ar.exception == null) {
2286 request.result = true;
2287 } else {
2288 request.result = false;
2289 if (ar.exception instanceof CommandException) {
2290 loge(command + ": CommandException: " + ar.exception);
2291 } else {
2292 loge(command + ": Unknown exception");
2293 }
2294 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002295 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002297 }
2298
2299 /**
2300 * Posts the specified command to be executed on the main thread,
2301 * waits for the request to complete, and returns the result.
2302 * @see #sendRequestAsync
2303 */
2304 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002305 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2306 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002307 }
2308
2309 /**
2310 * Posts the specified command to be executed on the main thread,
2311 * waits for the request to complete, and returns the result.
2312 * @see #sendRequestAsync
2313 */
2314 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2315 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002316 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002317 }
2318
2319 /**
2320 * Posts the specified command to be executed on the main thread,
2321 * waits for the request to complete, and returns the result.
2322 * @see #sendRequestAsync
2323 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002324 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002325 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2326 }
2327
2328 /**
2329 * Posts the specified command to be executed on the main thread,
2330 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2331 * if not timeout or null otherwise.
2332 * @see #sendRequestAsync
2333 */
2334 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2335 long timeoutInMs) {
2336 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002337 }
2338
2339 /**
2340 * Posts the specified command to be executed on the main thread,
2341 * waits for the request to complete, and returns the result.
2342 * @see #sendRequestAsync
2343 */
Nathan Harold92bed182018-10-12 18:16:49 -07002344 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002345 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002346 }
2347
2348 /**
2349 * Posts the specified command to be executed on the main thread,
2350 * waits for the request to complete, and returns the result.
2351 * @see #sendRequestAsync
2352 */
2353 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002354 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2355 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002356 }
2357
2358 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002359 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2360 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2361 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002362 * @see #sendRequestAsync
2363 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002364 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2365 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2367 throw new RuntimeException("This method will deadlock if called from the main thread.");
2368 }
2369
Nathan Harold92bed182018-10-12 18:16:49 -07002370 MainThreadRequest request = null;
2371 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2372 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2373 } else if (phone != null) {
2374 request = new MainThreadRequest(argument, phone, workSource);
2375 } else {
2376 request = new MainThreadRequest(argument, subId, workSource);
2377 }
2378
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379 Message msg = mMainThreadHandler.obtainMessage(command, request);
2380 msg.sendToTarget();
2381
Rambo Wang0f050d82021-02-12 11:43:36 -08002382
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002383 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002384 if (timeoutInMs >= 0) {
2385 // Wait for at least timeoutInMs before returning null request result
2386 long now = SystemClock.elapsedRealtime();
2387 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002388 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002389 try {
2390 request.wait(deadline - now);
2391 } catch (InterruptedException e) {
2392 // Do nothing, go back and check if request is completed or timeout
2393 } finally {
2394 now = SystemClock.elapsedRealtime();
2395 }
2396 }
2397 } else {
2398 // Wait for the request to complete
2399 while (request.result == null) {
2400 try {
2401 request.wait();
2402 } catch (InterruptedException e) {
2403 // Do nothing, go back and wait until the request is complete
2404 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405 }
2406 }
2407 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002408 if (request.result == null) {
2409 Log.wtf(LOG_TAG,
2410 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2411 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002412 return request.result;
2413 }
2414
2415 /**
2416 * Asynchronous ("fire and forget") version of sendRequest():
2417 * Posts the specified command to be executed on the main thread, and
2418 * returns immediately.
2419 * @see #sendRequest
2420 */
2421 private void sendRequestAsync(int command) {
2422 mMainThreadHandler.sendEmptyMessage(command);
2423 }
2424
2425 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002426 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002427 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002428 */
2429 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002430 sendRequestAsync(command, argument, null, null);
2431 }
2432
2433 /**
2434 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2435 * @see {@link #sendRequest(int,Object)}
2436 */
2437 private void sendRequestAsync(
2438 int command, Object argument, Phone phone, WorkSource workSource) {
2439 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002440 Message msg = mMainThreadHandler.obtainMessage(command, request);
2441 msg.sendToTarget();
2442 }
2443
2444 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 * Initialize the singleton PhoneInterfaceManager instance.
2446 * This is only done once, at startup, from PhoneApp.onCreate().
2447 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002448 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 synchronized (PhoneInterfaceManager.class) {
2450 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002451 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002452 } else {
2453 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2454 }
2455 return sInstance;
2456 }
2457 }
2458
2459 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002460 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002461 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002463 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002464 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002465 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2467 mMainThreadHandler = new MainThreadHandler();
Jack Yue37dd262022-12-16 11:53:37 -08002468 if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) {
2469 mSubscriptionController = SubscriptionController.getInstance();
2470 } else {
2471 mSubscriptionController = null;
2472 }
Sarah Chin4beb2b72023-02-14 14:47:54 -08002473 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002474 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002475 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002476 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002477 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002478 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 publish();
arunvoddud7401012022-12-15 16:08:12 +00002480 CarrierAllowListInfo.loadInstance(mApp);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481 }
2482
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002483 @VisibleForTesting
2484 public SharedPreferences getSharedPreferences() {
2485 return mTelephonySharedPreferences;
2486 }
2487
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002488 /**
2489 * Get the default phone for this device.
2490 */
2491 @VisibleForTesting
2492 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002493 Phone thePhone = getPhone(getDefaultSubscription());
2494 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2495 }
2496
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497 private void publish() {
2498 if (DBG) log("publish: " + this);
2499
Peter Wangc035ce42020-01-08 21:00:22 -08002500 TelephonyFrameworkInitializer
2501 .getTelephonyServiceManager()
2502 .getTelephonyServiceRegisterer()
2503 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002504 }
2505
Stuart Scott584921c2015-01-15 17:10:34 -08002506 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002507 if (request.phone != null) {
2508 return request.phone;
2509 } else {
2510 return getPhoneFromSubId(request.subId);
2511 }
2512 }
2513
2514 private Phone getPhoneFromSubId(int subId) {
2515 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2516 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002517 }
2518
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002519 /**
2520 * Get phone object associated with a subscription.
2521 * Return default phone if phone object associated with subscription is null
2522 * @param subId - subscriptionId
2523 * @return phone object associated with a subscription or default phone if null.
2524 */
2525 private Phone getPhoneFromSubIdOrDefault(int subId) {
2526 Phone phone = getPhoneFromSubId(subId);
2527 if (phone == null) {
2528 phone = getDefaultPhone();
2529 }
2530 return phone;
2531 }
2532
Rambo Wange53e07d2022-05-10 13:01:13 -07002533 @Nullable
2534 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002535 Phone phone = getPhoneFromRequest(request);
2536 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002537 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002538 }
2539
Wink Saville36469e72014-06-11 15:17:00 -07002540 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002541 private Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002542 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002543 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002544
Kai Shif70f46f2021-03-03 13:59:46 -08002545 private void sendEraseModemConfig(@NonNull Phone phone) {
2546 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2547 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2548 }
2549
2550 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2551 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2552 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002553 }
2554
Peter Wang44b186e2020-01-13 23:33:09 -08002555 private boolean isImsAvailableOnDevice() {
2556 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2557 if (pm == null) {
2558 // For some reason package manger is not available.. This will fail internally anyway,
2559 // so do not throw error and allow.
2560 return true;
2561 }
2562 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2563 }
2564
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002565 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002566 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002567 }
2568
Wink Savilleb564aae2014-10-23 10:18:09 -07002569 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002570 if (DBG) log("dial: " + number);
2571 // No permission check needed here: This is just a wrapper around the
2572 // ACTION_DIAL intent, which is available to any app since it puts up
2573 // the UI before it does anything.
2574
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002575 final long identity = Binder.clearCallingIdentity();
2576 try {
2577 String url = createTelUrl(number);
2578 if (url == null) {
2579 return;
2580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002581
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002582 // PENDING: should we just silently fail if phone is offhook or ringing?
2583 PhoneConstants.State state = mCM.getState(subId);
2584 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2585 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2586 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2587 mApp.startActivity(intent);
2588 }
2589 } finally {
2590 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002591 }
2592 }
2593
2594 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002595 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002596 }
2597
Wink Savilleb564aae2014-10-23 10:18:09 -07002598 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002599 if (DBG) log("call: " + number);
2600
2601 // This is just a wrapper around the ACTION_CALL intent, but we still
2602 // need to do a permission check since we're calling startActivity()
2603 // from the context of the phone app.
2604 enforceCallPermission();
2605
Jordan Liu1617b712019-07-10 15:06:26 -07002606 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002607 != AppOpsManager.MODE_ALLOWED) {
2608 return;
2609 }
2610
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002611 final long identity = Binder.clearCallingIdentity();
2612 try {
2613 String url = createTelUrl(number);
2614 if (url == null) {
2615 return;
2616 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002617
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002618 boolean isValid = false;
2619 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2620 if (slist != null) {
2621 for (SubscriptionInfo subInfoRecord : slist) {
2622 if (subInfoRecord.getSubscriptionId() == subId) {
2623 isValid = true;
2624 break;
2625 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002626 }
Wink Saville08874612014-08-31 19:19:58 -07002627 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002628 if (!isValid) {
2629 return;
2630 }
Wink Saville08874612014-08-31 19:19:58 -07002631
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002632 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2633 intent.putExtra(SUBSCRIPTION_KEY, subId);
2634 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2635 mApp.startActivity(intent);
2636 } finally {
2637 Binder.restoreCallingIdentity(identity);
2638 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002639 }
2640
Wink Savilleb564aae2014-10-23 10:18:09 -07002641 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002642 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002643 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2644 }
2645
Wink Savilleb564aae2014-10-23 10:18:09 -07002646 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002647 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002648 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2649 }
2650
Wink Savilleb564aae2014-10-23 10:18:09 -07002651 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002652 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002653
2654 final long identity = Binder.clearCallingIdentity();
2655 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002656 Phone phone = getPhone(subId);
2657 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002658 checkSimPin.start();
2659 return checkSimPin.unlockSim(null, pin);
2660 } finally {
2661 Binder.restoreCallingIdentity(identity);
2662 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002663 }
2664
Wink Savilleb564aae2014-10-23 10:18:09 -07002665 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002666 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002667
2668 final long identity = Binder.clearCallingIdentity();
2669 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002670 Phone phone = getPhone(subId);
2671 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002672 checkSimPuk.start();
2673 return checkSimPuk.unlockSim(puk, pin);
2674 } finally {
2675 Binder.restoreCallingIdentity(identity);
2676 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002677 }
2678
2679 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002680 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002681 * a synchronous one.
2682 */
2683 private static class UnlockSim extends Thread {
2684
2685 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002686 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002687
2688 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002689 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2690 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002691
2692 // For replies from SimCard interface
2693 private Handler mHandler;
2694
2695 // For async handler to identify request type
2696 private static final int SUPPLY_PIN_COMPLETE = 100;
2697
Michele Berionne5e411512020-11-13 02:36:59 +00002698 UnlockSim(int phoneId, IccCard simCard) {
2699 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002700 mSimCard = simCard;
2701 }
2702
2703 @Override
2704 public void run() {
2705 Looper.prepare();
2706 synchronized (UnlockSim.this) {
2707 mHandler = new Handler() {
2708 @Override
2709 public void handleMessage(Message msg) {
2710 AsyncResult ar = (AsyncResult) msg.obj;
2711 switch (msg.what) {
2712 case SUPPLY_PIN_COMPLETE:
2713 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2714 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002715 mRetryCount = msg.arg1;
2716 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002717 CommandException.Error error = null;
2718 if (ar.exception instanceof CommandException) {
2719 error = ((CommandException) (ar.exception))
2720 .getCommandError();
2721 }
2722 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002723 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002724 } else if (error == CommandException.Error.ABORTED) {
2725 /* When UiccCardApp dispose, handle message and return
2726 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002727 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002728 } else {
2729 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2730 }
2731 } else {
2732 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2733 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002734 mDone = true;
2735 UnlockSim.this.notifyAll();
2736 }
2737 break;
2738 }
2739 }
2740 };
2741 UnlockSim.this.notifyAll();
2742 }
2743 Looper.loop();
2744 }
2745
2746 /*
2747 * Use PIN or PUK to unlock SIM card
2748 *
2749 * If PUK is null, unlock SIM card with PIN
2750 *
2751 * If PUK is not null, unlock SIM card with PUK and set PIN code
2752 */
Wink Saville9de0f752013-10-22 19:04:03 -07002753 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002754
2755 while (mHandler == null) {
2756 try {
2757 wait();
2758 } catch (InterruptedException e) {
2759 Thread.currentThread().interrupt();
2760 }
2761 }
2762 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2763
2764 if (puk == null) {
2765 mSimCard.supplyPin(pin, callback);
2766 } else {
2767 mSimCard.supplyPuk(puk, pin, callback);
2768 }
2769
2770 while (!mDone) {
2771 try {
2772 Log.d(LOG_TAG, "wait for done");
2773 wait();
2774 } catch (InterruptedException e) {
2775 // Restore the interrupted status
2776 Thread.currentThread().interrupt();
2777 }
2778 }
2779 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002780 int[] resultArray = new int[2];
2781 resultArray[0] = mResult;
2782 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002783
2784 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002785 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002786 }
2787
Wink Saville9de0f752013-10-22 19:04:03 -07002788 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002789 }
2790 }
2791
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002792 /**
2793 * This method has been removed due to privacy and stability concerns.
2794 */
2795 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002796 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002797 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2798 return;
Wink Saville36469e72014-06-11 15:17:00 -07002799 }
2800
Nathan Harold1f889d82020-06-04 17:05:26 -07002801 @Override
2802 public void updateServiceLocationWithPackageName(String callingPackage) {
2803 mApp.getSystemService(AppOpsManager.class)
2804 .checkPackage(Binder.getCallingUid(), callingPackage);
2805
Nathan Haroldf096d982020-11-18 17:18:06 -08002806 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002807 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2808 // Callers targeting S have no business invoking this method.
2809 return;
2810 }
2811
2812 LocationAccessPolicy.LocationPermissionResult locationResult =
2813 LocationAccessPolicy.checkLocationPermission(mApp,
2814 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2815 .setCallingPackage(callingPackage)
2816 .setCallingFeatureId(null)
2817 .setCallingPid(Binder.getCallingPid())
2818 .setCallingUid(Binder.getCallingUid())
2819 .setMethod("updateServiceLocation")
2820 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2821 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2822 .build());
2823 // Apps that lack location permission have no business calling this method;
2824 // however, because no permission was declared in the public API, denials must
2825 // all be "soft".
2826 switch (locationResult) {
2827 case DENIED_HARD: /* fall through */
2828 case DENIED_SOFT:
2829 return;
2830 }
2831
2832 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002833 final long identity = Binder.clearCallingIdentity();
2834 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002835 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002836 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002837 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002838 }
2839 } finally {
2840 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002841 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002842 }
2843
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002844 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002845 @Override
2846 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002847 return isRadioOnWithFeature(callingPackage, null);
2848 }
2849
2850
2851 @Override
2852 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2853 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2854 callingFeatureId);
2855 }
2856
2857 @Deprecated
2858 @Override
2859 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2860 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002861 }
2862
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002863 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002864 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2865 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002866 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002867 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002868 return false;
2869 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002870
2871 final long identity = Binder.clearCallingIdentity();
2872 try {
2873 return isRadioOnForSubscriber(subId);
2874 } finally {
2875 Binder.restoreCallingIdentity(identity);
2876 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002877 }
2878
2879 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880 final long identity = Binder.clearCallingIdentity();
2881 try {
2882 final Phone phone = getPhone(subId);
2883 if (phone != null) {
2884 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2885 } else {
2886 return false;
2887 }
2888 } finally {
2889 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002890 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002891 }
2892
2893 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002894 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002895 }
Wink Saville36469e72014-06-11 15:17:00 -07002896
Wink Savilleb564aae2014-10-23 10:18:09 -07002897 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002898 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002899
2900 final long identity = Binder.clearCallingIdentity();
2901 try {
2902 final Phone phone = getPhone(subId);
2903 if (phone != null) {
2904 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2905 }
2906 } finally {
2907 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002908 }
Wink Saville36469e72014-06-11 15:17:00 -07002909 }
2910
2911 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002912 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002913 }
2914
Wink Savilleb564aae2014-10-23 10:18:09 -07002915 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002916 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002917
2918 final long identity = Binder.clearCallingIdentity();
2919 try {
2920 final Phone phone = getPhone(subId);
2921 if (phone == null) {
2922 return false;
2923 }
2924 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2925 toggleRadioOnOffForSubscriber(subId);
2926 }
2927 return true;
2928 } finally {
2929 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002930 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002931 }
Wink Saville36469e72014-06-11 15:17:00 -07002932
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002933 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002934 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002935 /*
2936 * If any of the Radios are available, it will need to be
2937 * shutdown. So return true if any Radio is available.
2938 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002939 final long identity = Binder.clearCallingIdentity();
2940 try {
2941 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2942 Phone phone = PhoneFactory.getPhone(i);
2943 if (phone != null && phone.isRadioAvailable()) return true;
2944 }
2945 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2946 return false;
2947 } finally {
2948 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002949 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002950 }
2951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002952 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002953 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002954 enforceModifyPermission();
2955
2956 final long identity = Binder.clearCallingIdentity();
2957 try {
2958 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2959 logv("Shutting down Phone " + i);
2960 shutdownRadioUsingPhoneId(i);
2961 }
2962 } finally {
2963 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002964 }
2965 }
2966
2967 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002968 Phone phone = PhoneFactory.getPhone(phoneId);
2969 if (phone != null && phone.isRadioAvailable()) {
2970 phone.shutdownRadio();
2971 }
2972 }
2973
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002974 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002975 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002976
Ling Ma83dc5ea2023-01-12 15:06:04 -08002977 if (!turnOn) {
2978 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
2979 }
2980
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002981 final long identity = Binder.clearCallingIdentity();
2982 try {
2983 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2984 if (defaultPhone != null) {
2985 defaultPhone.setRadioPower(turnOn);
2986 return true;
2987 } else {
2988 loge("There's no default phone.");
2989 return false;
2990 }
2991 } finally {
2992 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002993 }
Wink Saville36469e72014-06-11 15:17:00 -07002994 }
2995
Wink Savilleb564aae2014-10-23 10:18:09 -07002996 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002997 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002998
Ling Ma83dc5ea2023-01-12 15:06:04 -08002999 if (!turnOn) {
3000 log("setRadioPowerForSubscriber off: subId=" + subId
3001 + ",callingPackage=" + getCurrentPackageName());
3002 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003003 final long identity = Binder.clearCallingIdentity();
3004 try {
3005 final Phone phone = getPhone(subId);
3006 if (phone != null) {
3007 phone.setRadioPower(turnOn);
3008 return true;
3009 } else {
3010 return false;
3011 }
3012 } finally {
3013 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003014 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003015 }
3016
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003017 /**
3018 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3019 * no reason to power it off. When any of the voters want to power it off, it will be turned
3020 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3021 * powering it off, and these radio off votes will be cleared.
3022 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3023 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3024 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3025 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3026 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3027 * check its vote.
3028 *
3029 * @param subId The subscription ID.
3030 * @param reason The reason for powering off radio.
3031 * @return true on success and false on failure.
3032 */
3033 public boolean requestRadioPowerOffForReason(int subId,
3034 @TelephonyManager.RadioPowerReason int reason) {
3035 enforceModifyPermission();
3036
Ling Ma83dc5ea2023-01-12 15:06:04 -08003037 log("requestRadioPowerOffForReason: subId=" + subId
3038 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003039 final long identity = Binder.clearCallingIdentity();
3040 try {
3041 final Phone phone = getPhone(subId);
3042 if (phone != null) {
3043 phone.setRadioPowerForReason(false, reason);
3044 return true;
3045 } else {
3046 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 {
3067 final Phone phone = getPhone(subId);
3068 if (phone != null) {
3069 phone.setRadioPowerForReason(true, reason);
3070 return true;
3071 } else {
3072 return false;
3073 }
3074 } finally {
3075 Binder.restoreCallingIdentity(identity);
3076 }
3077 }
3078
3079 /**
3080 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3081 *
3082 * @param subId The subscription ID.
3083 * @param callingPackage The package making the call.
3084 * @param callingFeatureId The feature in the package.
3085 * @return List of reasons for powering off radio.
3086 */
3087 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3088 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3089
3090 final long identity = Binder.clearCallingIdentity();
3091 List result = new ArrayList();
3092 try {
3093 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3094 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3095 return result;
3096 }
3097
3098 final Phone phone = getPhone(subId);
3099 if (phone != null) {
3100 result.addAll(phone.getRadioPowerOffReasons());
3101 }
3102 } finally {
3103 Binder.restoreCallingIdentity(identity);
3104 }
3105 return result;
3106 }
3107
Wink Saville36469e72014-06-11 15:17:00 -07003108 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003109 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003110 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003111 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003112
3113 final long identity = Binder.clearCallingIdentity();
3114 try {
Jack Yu285100e2022-12-02 22:48:35 -08003115 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003116 final Phone phone = getPhone(subId);
3117 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003118 phone.getDataSettingsManager().setDataEnabled(
3119 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003120 return true;
3121 } else {
3122 return false;
3123 }
3124 } finally {
3125 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003126 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003127 }
3128
Wink Saville36469e72014-06-11 15:17:00 -07003129 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003130 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003131 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003132 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003133
3134 final long identity = Binder.clearCallingIdentity();
3135 try {
Jack Yu285100e2022-12-02 22:48:35 -08003136 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003137 final Phone phone = getPhone(subId);
3138 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003139 phone.getDataSettingsManager().setDataEnabled(
3140 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003141 return true;
3142 } else {
3143 return false;
3144 }
3145 } finally {
3146 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003147 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003148 }
3149
Sanket Padawe356d7632015-06-22 14:03:32 -07003150 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003151 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003152 final long identity = Binder.clearCallingIdentity();
3153 try {
3154 final Phone phone = getPhone(subId);
3155 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003156 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003157 } else {
3158 return false;
3159 }
3160 } finally {
3161 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003162 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003163 }
3164
3165 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003166 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003167 }
3168
pkanwarae03a6b2016-11-06 20:37:09 -08003169 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003170 enforceCallPermission();
3171
3172 final long identity = Binder.clearCallingIdentity();
3173 try {
3174 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3175 return;
3176 }
3177 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3178 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3179 } finally {
3180 Binder.restoreCallingIdentity(identity);
3181 }
pkanwar32d516d2016-10-14 19:37:38 -07003182 };
3183
Wink Savilleb564aae2014-10-23 10:18:09 -07003184 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003185 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003186
3187 final long identity = Binder.clearCallingIdentity();
3188 try {
3189 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3190 return false;
3191 }
3192 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3193 } finally {
3194 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003195 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003196 }
3197
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003198 /**
3199 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3200 * tag on getCallState Binder call.
3201 */
3202 @Deprecated
3203 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003204 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003205 if (CompatChanges.isChangeEnabled(
3206 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3207 Binder.getCallingUid())) {
3208 // Do not allow this API to be called on API version 31+, it should only be
3209 // called on old apps using this Binder call directly.
3210 throw new SecurityException("This method can only be used for applications "
3211 + "targeting API version 30 or less.");
3212 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003213 final long identity = Binder.clearCallingIdentity();
3214 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003215 Phone phone = getPhone(getDefaultSubscription());
3216 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3217 PhoneConstantConversions.convertCallState(phone.getState());
3218 } finally {
3219 Binder.restoreCallingIdentity(identity);
3220 }
3221 }
3222
3223 @Override
3224 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3225 if (CompatChanges.isChangeEnabled(
3226 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3227 Binder.getCallingUid())) {
3228 // Check READ_PHONE_STATE for API version 31+
3229 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3230 featureId, "getCallStateForSubscription")) {
3231 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3232 + "targeting API level 31+.");
3233 }
3234 }
3235 final long identity = Binder.clearCallingIdentity();
3236 try {
3237 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003238 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3239 PhoneConstantConversions.convertCallState(phone.getState());
3240 } finally {
3241 Binder.restoreCallingIdentity(identity);
3242 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003243 }
3244
Sanket Padawe356d7632015-06-22 14:03:32 -07003245 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003246 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003247 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003248 }
3249
3250 @Override
3251 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003252 final long identity = Binder.clearCallingIdentity();
3253 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003254 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003255 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003256 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003257 } else {
3258 return PhoneConstantConversions.convertDataState(
3259 PhoneConstants.DataState.DISCONNECTED);
3260 }
3261 } finally {
3262 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003263 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003264 }
3265
Sanket Padawe356d7632015-06-22 14:03:32 -07003266 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003267 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003268 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003269 }
3270
3271 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003272 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003273 final long identity = Binder.clearCallingIdentity();
3274 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003275 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003276 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003277 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003278 } else {
3279 return TelephonyManager.DATA_ACTIVITY_NONE;
3280 }
3281 } finally {
3282 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003284 }
3285
3286 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003287 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003288 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003289 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003290
3291 LocationAccessPolicy.LocationPermissionResult locationResult =
3292 LocationAccessPolicy.checkLocationPermission(mApp,
3293 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3294 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003295 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003296 .setCallingPid(Binder.getCallingPid())
3297 .setCallingUid(Binder.getCallingUid())
3298 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003299 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003300 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3301 .build());
3302 switch (locationResult) {
3303 case DENIED_HARD:
3304 throw new SecurityException("Not allowed to access cell location");
3305 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003306 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3307 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003308 }
3309
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003310 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003311 final long identity = Binder.clearCallingIdentity();
3312 try {
3313 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003314 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003315 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003316 } finally {
3317 Binder.restoreCallingIdentity(identity);
3318 }
Svetoslav64fad262015-04-14 14:35:21 -07003319 }
3320
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003321 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003322 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003323 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3324 // registered cell info, so return a NULL country instead.
3325 final long identity = Binder.clearCallingIdentity();
3326 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003327 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3328 // Get default phone in this case.
3329 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3330 }
Jack Yu285100e2022-12-02 22:48:35 -08003331 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003332 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003333 if (phone == null) return "";
3334 ServiceStateTracker sst = phone.getServiceStateTracker();
3335 if (sst == null) return "";
3336 LocaleTracker lt = sst.getLocaleTracker();
3337 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003338 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003339 } finally {
3340 Binder.restoreCallingIdentity(identity);
3341 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003342 }
3343
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003344 /**
3345 * This method was removed due to potential issues caused by performing partial
3346 * updates of service state, and lack of a credible use case.
3347 *
3348 * This has the ability to break the telephony implementation by disabling notification of
3349 * changes in device connectivity. DO NOT USE THIS!
3350 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003351 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003352 public void enableLocationUpdates() {
3353 mApp.enforceCallingOrSelfPermission(
3354 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003355 }
3356
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003357 /**
3358 * This method was removed due to potential issues caused by performing partial
3359 * updates of service state, and lack of a credible use case.
3360 *
3361 * This has the ability to break the telephony implementation by disabling notification of
3362 * changes in device connectivity. DO NOT USE THIS!
3363 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003364 @Override
3365 public void disableLocationUpdates() {
3366 mApp.enforceCallingOrSelfPermission(
3367 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003368 }
3369
3370 @Override
3371 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003372 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3373 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003374 try {
3375 mApp.getSystemService(AppOpsManager.class)
3376 .checkPackage(Binder.getCallingUid(), callingPackage);
3377 } catch (SecurityException e) {
3378 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3379 throw e;
3380 }
3381
Nathan Haroldf096d982020-11-18 17:18:06 -08003382 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003383 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3384 throw new SecurityException(
3385 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3386 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003387
Jordan Liu1617b712019-07-10 15:06:26 -07003388 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003389 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3390 return null;
3391 }
Svetoslav64fad262015-04-14 14:35:21 -07003392
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003393 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003394
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003395 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003396 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003397
Nathan Haroldf180aac2018-06-01 18:43:55 -07003398 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3399 for (CellInfo ci : info) {
3400 if (ci instanceof CellInfoGsm) {
3401 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3402 } else if (ci instanceof CellInfoWcdma) {
3403 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3404 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003405 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003406 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003407 }
3408
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003409 private List<CellInfo> getCachedCellInfo() {
3410 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3411 for (Phone phone : PhoneFactory.getPhones()) {
3412 List<CellInfo> info = phone.getAllCellInfo();
3413 if (info != null) cellInfos.addAll(info);
3414 }
3415 return cellInfos;
3416 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003417
3418 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003419 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003420 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003421 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003422
3423 LocationAccessPolicy.LocationPermissionResult locationResult =
3424 LocationAccessPolicy.checkLocationPermission(mApp,
3425 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3426 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003427 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003428 .setCallingPid(Binder.getCallingPid())
3429 .setCallingUid(Binder.getCallingUid())
3430 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003431 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003432 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3433 .build());
3434 switch (locationResult) {
3435 case DENIED_HARD:
3436 throw new SecurityException("Not allowed to access cell info");
3437 case DENIED_SOFT:
3438 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003439 }
3440
Nathan Haroldf096d982020-11-18 17:18:06 -08003441 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003442 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3443 return getCachedCellInfo();
3444 }
3445
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003446 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003447 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003448 final long identity = Binder.clearCallingIdentity();
3449 try {
3450 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3451 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003452 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003453 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003454 if (info != null) cellInfos.addAll(info);
3455 }
3456 return cellInfos;
3457 } finally {
3458 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003459 }
3460 }
3461
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003462 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003463 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3464 String callingFeatureId) {
3465 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3466 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003467 }
3468
3469 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003470 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3471 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003472 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003473 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003474 }
3475
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003476 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3477 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003478 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003479 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003480
3481 LocationAccessPolicy.LocationPermissionResult locationResult =
3482 LocationAccessPolicy.checkLocationPermission(mApp,
3483 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3484 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003485 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003486 .setCallingPid(Binder.getCallingPid())
3487 .setCallingUid(Binder.getCallingUid())
3488 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003489 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3490 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003491 .build());
3492 switch (locationResult) {
3493 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003494 if (TelephonyPermissions
3495 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003496 // Safetynet logging for b/154934934
3497 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3498 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003499 throw new SecurityException("Not allowed to access cell info");
3500 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003501 if (TelephonyPermissions
3502 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003503 // Safetynet logging for b/154934934
3504 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3505 }
Nathan Harold5320c422019-05-09 10:26:08 -07003506 try {
3507 cb.onCellInfo(new ArrayList<CellInfo>());
3508 } catch (RemoteException re) {
3509 // Drop without consequences
3510 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003511 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003512 }
3513
Nathan Harolda939a962019-05-09 10:13:47 -07003514
3515 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003516 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3517
3518 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3519 }
3520
3521 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003522 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003523 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003524 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003525
3526 final long identity = Binder.clearCallingIdentity();
3527 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003528 Phone phone = getPhone(subId);
3529 if (phone == null) {
3530 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3531 } else {
3532 phone.setCellInfoListRate(rateInMillis, workSource);
3533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003534 } finally {
3535 Binder.restoreCallingIdentity(identity);
3536 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003537 }
3538
Shishir Agrawala9f32182016-04-12 12:00:16 -07003539 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003540 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003541 Phone phone = PhoneFactory.getPhone(slotIndex);
3542 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003543 return null;
3544 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003545 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003546 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003547 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003548 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003549 return null;
3550 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003551
3552 final long identity = Binder.clearCallingIdentity();
3553 try {
3554 return phone.getImei();
3555 } finally {
3556 Binder.restoreCallingIdentity(identity);
3557 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003558 }
3559
3560 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003561 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3562 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3563 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3564 callingFeatureId, "getPrimaryImei")) {
3565 throw new SecurityException("Caller does not have permission");
3566 }
3567 final long identity = Binder.clearCallingIdentity();
3568 try {
3569 for (Phone phone : PhoneFactory.getPhones()) {
3570 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3571 return phone.getImei();
3572 }
3573 }
3574 throw new UnsupportedOperationException("Operation not supported");
3575 } finally {
3576 Binder.restoreCallingIdentity(identity);
3577 }
3578 }
3579
3580 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003581 public String getTypeAllocationCodeForSlot(int slotIndex) {
3582 Phone phone = PhoneFactory.getPhone(slotIndex);
3583 String tac = null;
3584 if (phone != null) {
3585 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003586 try {
3587 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3588 } catch (IndexOutOfBoundsException e) {
3589 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3590 return null;
3591 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003592 }
3593 return tac;
3594 }
3595
3596 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003597 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003598 try {
3599 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3600 } catch (SecurityException se) {
3601 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3602 throw new SecurityException("Package " + callingPackage + " does not belong to "
3603 + Binder.getCallingUid());
3604 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003605 Phone phone = PhoneFactory.getPhone(slotIndex);
3606 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003607 return null;
3608 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003609
Jeff Davidson913390f2018-02-23 17:11:49 -08003610 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003611 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003612 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003613 return null;
3614 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003615
3616 final long identity = Binder.clearCallingIdentity();
3617 try {
3618 return phone.getMeid();
3619 } finally {
3620 Binder.restoreCallingIdentity(identity);
3621 }
Jack Yu2af8d712017-03-15 17:14:14 -07003622 }
3623
3624 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003625 public String getManufacturerCodeForSlot(int slotIndex) {
3626 Phone phone = PhoneFactory.getPhone(slotIndex);
3627 String manufacturerCode = null;
3628 if (phone != null) {
3629 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003630 try {
3631 manufacturerCode =
3632 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3633 } catch (IndexOutOfBoundsException e) {
3634 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3635 return null;
3636 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003637 }
3638 return manufacturerCode;
3639 }
3640
3641 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003642 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3643 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003644 Phone phone = PhoneFactory.getPhone(slotIndex);
3645 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003646 return null;
3647 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003648 int subId = phone.getSubId();
3649 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003650 mApp, subId, callingPackage, callingFeatureId,
3651 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003652 return null;
3653 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003654
3655 final long identity = Binder.clearCallingIdentity();
3656 try {
3657 return phone.getDeviceSvn();
3658 } finally {
3659 Binder.restoreCallingIdentity(identity);
3660 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003661 }
3662
fionaxu43304da2017-11-27 22:51:16 -08003663 @Override
3664 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003665 final long identity = Binder.clearCallingIdentity();
3666 try {
3667 final Phone phone = getPhone(subId);
3668 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3669 } finally {
3670 Binder.restoreCallingIdentity(identity);
3671 }
fionaxu43304da2017-11-27 22:51:16 -08003672 }
3673
3674 @Override
3675 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003676 final long identity = Binder.clearCallingIdentity();
3677 try {
3678 final Phone phone = getPhone(subId);
3679 return phone == null ? null : phone.getCarrierName();
3680 } finally {
3681 Binder.restoreCallingIdentity(identity);
3682 }
fionaxu43304da2017-11-27 22:51:16 -08003683 }
3684
calvinpanffe225e2018-11-01 19:43:06 +08003685 @Override
chen xu0026ca62019-03-06 15:28:50 -08003686 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003687 final long identity = Binder.clearCallingIdentity();
3688 try {
3689 final Phone phone = getPhone(subId);
3690 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003691 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003692 } finally {
3693 Binder.restoreCallingIdentity(identity);
3694 }
3695 }
3696
3697 @Override
chen xu0026ca62019-03-06 15:28:50 -08003698 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003699 final long identity = Binder.clearCallingIdentity();
3700 try {
3701 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003702 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003703 } finally {
3704 Binder.restoreCallingIdentity(identity);
3705 }
3706 }
3707
chen xu651eec72018-11-11 19:03:44 -08003708 @Override
chen xu864e11c2018-12-06 22:10:03 -08003709 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3710 if (!isSubscriptionMccMnc) {
3711 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3712 }
chen xu651eec72018-11-11 19:03:44 -08003713 final Phone phone = PhoneFactory.getPhone(slotIndex);
3714 if (phone == null) {
3715 return TelephonyManager.UNKNOWN_CARRIER_ID;
3716 }
3717 final long identity = Binder.clearCallingIdentity();
3718 try {
3719 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3720 } finally {
3721 Binder.restoreCallingIdentity(identity);
3722 }
3723 }
3724
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003725 //
3726 // Internal helper methods.
3727 //
3728
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003729 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003730 * Make sure the caller is the calling package itself
3731 *
3732 * @throws SecurityException if the caller is not the calling package
3733 */
3734 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3735 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003736 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3737 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003738 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003739 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003740 } catch (PackageManager.NameNotFoundException e) {
3741 // packageUid is -1
3742 }
3743 if (packageUid != callingUid) {
3744 throw new SecurityException(message + ": Package " + callingPackage
3745 + " does not belong to " + callingUid);
3746 }
3747 }
3748
3749 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003750 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3751 *
3752 * @throws SecurityException if the caller does not have the required permission
3753 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003754 @VisibleForTesting
3755 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003756 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3757 }
3758
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003759 /**
arunvoddud7401012022-12-15 16:08:12 +00003760 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003761 *
3762 * @throws SecurityException if the caller does not have the required permission
3763 */
3764 @VisibleForTesting
3765 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003766 enforceReadPermission(null);
3767 }
3768
3769 /**
3770 * Make sure the caller has the READ_PHONE_STATE permissions.
3771 *
3772 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3773 */
3774 @VisibleForTesting
3775 public void enforceReadPermission(String msg) {
3776 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003777 }
3778
Shuo Qian3b6ee772019-11-13 17:43:31 -08003779 private void enforceActiveEmergencySessionPermission() {
3780 mApp.enforceCallingOrSelfPermission(
3781 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3782 }
3783
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003784 /**
3785 * Make sure the caller has the CALL_PHONE permission.
3786 *
3787 * @throws SecurityException if the caller does not have the required permission
3788 */
3789 private void enforceCallPermission() {
3790 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3791 }
3792
paulhu5a773602019-08-23 19:17:33 +08003793 private void enforceSettingsPermission() {
3794 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003795 }
3796
Michele Berionne5e411512020-11-13 02:36:59 +00003797 private void enforceRebootPermission() {
3798 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3799 }
3800
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003801 /**
3802 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3803 * @param message - log message to print.
3804 * @throws SecurityException if the caller does not have the required permission
3805 */
3806 private void enforceSatelliteCommunicationPermission(String message) {
3807 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3808 }
3809
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003810 private String createTelUrl(String number) {
3811 if (TextUtils.isEmpty(number)) {
3812 return null;
3813 }
3814
Jake Hambye994d462014-02-03 13:10:13 -08003815 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003816 }
3817
Ihab Awadf9e92732013-12-05 18:02:52 -08003818 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003819 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003820 }
3821
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003822 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003823 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003824 }
3825
Ihab Awadf9e92732013-12-05 18:02:52 -08003826 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003827 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003828 }
3829
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003830 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003831 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003832 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003833 }
3834
Sanket Padawe356d7632015-06-22 14:03:32 -07003835 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003836 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003837 final long identity = Binder.clearCallingIdentity();
3838 try {
3839 final Phone phone = PhoneFactory.getPhone(slotIndex);
3840 if (phone == null) {
3841 return PhoneConstants.PHONE_TYPE_NONE;
3842 } else {
3843 return phone.getPhoneType();
3844 }
3845 } finally {
3846 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003847 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003848 }
3849
3850 /**
3851 * Returns the CDMA ERI icon index to display
3852 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003853 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003854 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3855 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3856 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003857 }
3858
Sanket Padawe356d7632015-06-22 14:03:32 -07003859 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003860 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3861 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003862 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003863 mApp, subId, callingPackage, callingFeatureId,
3864 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003865 return -1;
3866 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003867
3868 final long identity = Binder.clearCallingIdentity();
3869 try {
3870 final Phone phone = getPhone(subId);
3871 if (phone != null) {
3872 return phone.getCdmaEriIconIndex();
3873 } else {
3874 return -1;
3875 }
3876 } finally {
3877 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003878 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003879 }
3880
3881 /**
3882 * Returns the CDMA ERI icon mode,
3883 * 0 - ON
3884 * 1 - FLASHING
3885 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003886 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003887 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3888 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3889 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003890 }
3891
Sanket Padawe356d7632015-06-22 14:03:32 -07003892 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003893 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3894 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003895 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003896 mApp, subId, callingPackage, callingFeatureId,
3897 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003898 return -1;
3899 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003900
3901 final long identity = Binder.clearCallingIdentity();
3902 try {
3903 final Phone phone = getPhone(subId);
3904 if (phone != null) {
3905 return phone.getCdmaEriIconMode();
3906 } else {
3907 return -1;
3908 }
3909 } finally {
3910 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003911 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003912 }
3913
3914 /**
3915 * Returns the CDMA ERI text,
3916 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003917 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003918 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3919 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3920 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003921 }
3922
Sanket Padawe356d7632015-06-22 14:03:32 -07003923 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003924 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3925 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003926 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003927 mApp, subId, callingPackage, callingFeatureId,
3928 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003929 return null;
3930 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003931
3932 final long identity = Binder.clearCallingIdentity();
3933 try {
3934 final Phone phone = getPhone(subId);
3935 if (phone != null) {
3936 return phone.getCdmaEriText();
3937 } else {
3938 return null;
3939 }
3940 } finally {
3941 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003942 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003943 }
3944
3945 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003946 * Returns the CDMA MDN.
3947 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003948 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003949 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3951 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003952
3953 final long identity = Binder.clearCallingIdentity();
3954 try {
3955 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003956 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003957 return phone.getLine1Number();
3958 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003959 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003960 return null;
3961 }
3962 } finally {
3963 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003964 }
3965 }
3966
3967 /**
3968 * Returns the CDMA MIN.
3969 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003970 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003971 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003972 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3973 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003974
3975 final long identity = Binder.clearCallingIdentity();
3976 try {
3977 final Phone phone = getPhone(subId);
3978 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3979 return phone.getCdmaMin();
3980 } else {
3981 return null;
3982 }
3983 } finally {
3984 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003985 }
3986 }
3987
Hall Liud892bec2018-11-30 14:51:45 -08003988 @Override
3989 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3990 INumberVerificationCallback callback, String callingPackage) {
3991 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3992 != PERMISSION_GRANTED) {
3993 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3994 }
3995 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3996
3997 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3998 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003999 throw new SecurityException("Calling package must be configured in the device config: "
4000 + "calling package: " + callingPackage
4001 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004002 }
4003
4004 if (range == null) {
4005 throw new NullPointerException("Range must be non-null");
4006 }
4007
4008 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004009 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004010
4011 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4012 }
4013
Junda Liuca05d5d2014-08-14 22:36:34 -07004014 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004015 * Returns true if CDMA provisioning needs to run.
4016 */
4017 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004018 final long identity = Binder.clearCallingIdentity();
4019 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004020 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004021 } finally {
4022 Binder.restoreCallingIdentity(identity);
4023 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004024 }
4025
4026 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004027 * Sets the voice mail number of a given subId.
4028 */
4029 @Override
4030 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004031 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4032 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004033
4034 final long identity = Binder.clearCallingIdentity();
4035 try {
4036 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4037 new Pair<String, String>(alphaTag, number), new Integer(subId));
4038 return success;
4039 } finally {
4040 Binder.restoreCallingIdentity(identity);
4041 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004042 }
4043
Ta-wei Yen87c49842016-05-13 21:19:52 -07004044 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004045 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4046 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004047 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4048 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004049 if (!TextUtils.equals(callingPackage, systemDialer)) {
4050 throw new SecurityException("caller must be system dialer");
4051 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004052
4053 final long identity = Binder.clearCallingIdentity();
4054 try {
4055 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4056 if (phoneAccountHandle == null) {
4057 return null;
4058 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004059 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004060 } finally {
4061 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004062 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004063 }
4064
4065 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004066 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4067 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004068 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004069 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004070 mApp, subId, callingPackage, callingFeatureId,
4071 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004072 return null;
4073 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004074
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004075 final long identity = Binder.clearCallingIdentity();
4076 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004077 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004078 } finally {
4079 Binder.restoreCallingIdentity(identity);
4080 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004081 }
4082
4083 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004084 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4085 VisualVoicemailSmsFilterSettings settings) {
4086 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004087
4088 final long identity = Binder.clearCallingIdentity();
4089 try {
4090 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004091 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004092 } finally {
4093 Binder.restoreCallingIdentity(identity);
4094 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004095 }
4096
4097 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004098 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4099 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004100
4101 final long identity = Binder.clearCallingIdentity();
4102 try {
4103 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004104 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004105 } finally {
4106 Binder.restoreCallingIdentity(identity);
4107 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004108 }
4109
4110 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004111 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4112 String callingPackage, int subId) {
4113 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004114
4115 final long identity = Binder.clearCallingIdentity();
4116 try {
4117 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004118 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004119 } finally {
4120 Binder.restoreCallingIdentity(identity);
4121 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004122 }
4123
4124 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004125 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004126 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004127
4128 final long identity = Binder.clearCallingIdentity();
4129 try {
4130 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004131 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004132 } finally {
4133 Binder.restoreCallingIdentity(identity);
4134 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004135 }
4136
4137 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004138 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4139 String callingAttributionTag, int subId, String number, int port, String text,
4140 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004141 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004142 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004143 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004144 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004145 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4146 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004147 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004148
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004149 /**
fionaxu0152e512016-11-14 13:36:14 -08004150 * Sets the voice activation state of a given subId.
4151 */
4152 @Override
4153 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4155 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004156
4157 final long identity = Binder.clearCallingIdentity();
4158 try {
4159 final Phone phone = getPhone(subId);
4160 if (phone != null) {
4161 phone.setVoiceActivationState(activationState);
4162 } else {
4163 loge("setVoiceActivationState fails with invalid subId: " + subId);
4164 }
4165 } finally {
4166 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004167 }
4168 }
4169
4170 /**
4171 * Sets the data activation state of a given subId.
4172 */
4173 @Override
4174 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004175 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4176 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004177
4178 final long identity = Binder.clearCallingIdentity();
4179 try {
4180 final Phone phone = getPhone(subId);
4181 if (phone != null) {
4182 phone.setDataActivationState(activationState);
4183 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004184 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004185 }
4186 } finally {
4187 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004188 }
4189 }
4190
4191 /**
4192 * Returns the voice activation state of a given subId.
4193 */
4194 @Override
4195 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004196 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004197
fionaxu0152e512016-11-14 13:36:14 -08004198 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004199 final long identity = Binder.clearCallingIdentity();
4200 try {
4201 if (phone != null) {
4202 return phone.getVoiceActivationState();
4203 } else {
4204 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4205 }
4206 } finally {
4207 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004208 }
4209 }
4210
4211 /**
4212 * Returns the data activation state of a given subId.
4213 */
4214 @Override
4215 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004216 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004217
fionaxu0152e512016-11-14 13:36:14 -08004218 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004219 final long identity = Binder.clearCallingIdentity();
4220 try {
4221 if (phone != null) {
4222 return phone.getDataActivationState();
4223 } else {
4224 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4225 }
4226 } finally {
4227 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004228 }
4229 }
4230
4231 /**
Wink Saville36469e72014-06-11 15:17:00 -07004232 * Returns the unread count of voicemails for a subId
4233 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004234 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004235 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4236 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004237 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004238 mApp, subId, callingPackage, callingFeatureId,
4239 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004240 return 0;
4241 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004242 final long identity = Binder.clearCallingIdentity();
4243 try {
4244 final Phone phone = getPhone(subId);
4245 if (phone != null) {
4246 return phone.getVoiceMessageCount();
4247 } else {
4248 return 0;
4249 }
4250 } finally {
4251 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004253 }
4254
4255 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004256 * returns true, if the device is in a state where both voice and data
4257 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004258 */
4259 @Override
4260 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004261 final long identity = Binder.clearCallingIdentity();
4262 try {
4263 final Phone phone = getPhone(subId);
4264 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4265 } finally {
4266 Binder.restoreCallingIdentity(identity);
4267 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004268 }
4269
4270 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004271 * Send the dialer code if called from the current default dialer or the caller has
4272 * carrier privilege.
4273 * @param inputCode The dialer code to send
4274 */
4275 @Override
4276 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004277 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004278 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004279 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4280 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004281 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004282 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004283 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004284 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004285
4286 final long identity = Binder.clearCallingIdentity();
4287 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004288 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004289 } finally {
4290 Binder.restoreCallingIdentity(identity);
4291 }
fionaxu235cc5e2017-03-06 22:25:57 -08004292 }
4293
Pengquan Menga1bb6272018-09-06 09:59:22 -07004294 @Override
4295 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004296 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004297 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4298 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08004299 final long identity = Binder.clearCallingIdentity();
4300 try {
4301 if (!isActiveSubscription(subId)) {
4302 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4303 }
4304 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4305 } finally {
4306 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004307 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004308 }
4309
Brad Ebinger35c841c2018-10-01 10:40:55 -07004310 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004311 public boolean isInEmergencySmsMode() {
4312 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4313 final long identity = Binder.clearCallingIdentity();
4314 try {
4315 for (Phone phone : PhoneFactory.getPhones()) {
4316 if (phone.isInEmergencySmsMode()) {
4317 return true;
4318 }
4319 }
4320 } finally {
4321 Binder.restoreCallingIdentity(identity);
4322 }
4323 return false;
4324 }
4325
shilu366312e2019-12-17 09:28:10 -08004326 /**
4327 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4328 * @param subId The subscription to use to check the configuration.
4329 * @param c The callback that will be used to send the result.
4330 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004331 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004332 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4333 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004334 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004335 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004336
4337 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4338 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4339 "IMS not available on device.");
4340 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004341 final long token = Binder.clearCallingIdentity();
4342 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004343 int slotId = getSlotIndexOrException(subId);
4344 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004345
4346 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4347 if (controller != null) {
4348 ImsManager imsManager = controller.getImsManager(subId);
4349 if (imsManager != null) {
4350 imsManager.addRegistrationCallbackForSubscription(c, subId);
4351 } else {
4352 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4353 }
4354 } else {
4355 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4356 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004357 } catch (ImsException e) {
4358 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004359 } finally {
4360 Binder.restoreCallingIdentity(token);
4361 }
4362 }
4363
shilu366312e2019-12-17 09:28:10 -08004364 /**
4365 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4366 * @param subId The subscription to use to check the configuration.
4367 * @param c The callback that will be used to send the result.
4368 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004369 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004370 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004371 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004372 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004373 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4374 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4375 }
Meng Wangafbc5852019-09-19 17:37:13 -07004376 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004377
Meng Wangafbc5852019-09-19 17:37:13 -07004378 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004379 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4380 if (controller != null) {
4381 ImsManager imsManager = controller.getImsManager(subId);
4382 if (imsManager != null) {
4383 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4384 } else {
4385 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4386 + "is inactive, ignoring unregister.");
4387 // If the ImsManager is not valid, just return, since the callback
4388 // will already have been removed internally.
4389 }
4390 }
Meng Wangafbc5852019-09-19 17:37:13 -07004391 } finally {
4392 Binder.restoreCallingIdentity(token);
4393 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004394 }
4395
Brad Ebingera34a6c22019-10-22 17:36:18 -07004396 /**
4397 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4398 */
4399 @Override
4400 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4401 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4402 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4403 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4404 "IMS not available on device.");
4405 }
4406 final long token = Binder.clearCallingIdentity();
4407 try {
4408 Phone phone = getPhone(subId);
4409 if (phone == null) {
4410 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4411 + subId + "'");
4412 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4413 }
4414 phone.getImsRegistrationState(regState -> {
4415 try {
4416 consumer.accept((regState == null)
4417 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4418 } catch (RemoteException e) {
4419 // Ignore if the remote process is no longer available to call back.
4420 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4421 }
4422 });
4423 } finally {
4424 Binder.restoreCallingIdentity(token);
4425 }
4426 }
4427
4428 /**
4429 * Get the transport type for the IMS service registration state.
4430 */
4431 @Override
4432 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004433 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004434 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004435 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4436 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4437 "IMS not available on device.");
4438 }
4439 final long token = Binder.clearCallingIdentity();
4440 try {
4441 Phone phone = getPhone(subId);
4442 if (phone == null) {
4443 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4444 + subId + "'");
4445 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4446 }
4447 phone.getImsRegistrationTech(regTech -> {
4448 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4449 int regTechConverted = (regTech == null)
4450 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4451 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4452 regTechConverted);
4453 try {
4454 consumer.accept(regTechConverted);
4455 } catch (RemoteException e) {
4456 // Ignore if the remote process is no longer available to call back.
4457 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4458 }
4459 });
4460 } finally {
4461 Binder.restoreCallingIdentity(token);
4462 }
4463 }
4464
shilu366312e2019-12-17 09:28:10 -08004465 /**
4466 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4467 * @param subId The subscription to use to check the configuration.
4468 * @param c The callback that will be used to send the result.
4469 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004470 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004471 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4472 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004473 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004474 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004475 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4476 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4477 "IMS not available on device.");
4478 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004479 final long token = Binder.clearCallingIdentity();
4480 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004481 int slotId = getSlotIndexOrException(subId);
4482 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004483
4484 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4485 if (controller != null) {
4486 ImsManager imsManager = controller.getImsManager(subId);
4487 if (imsManager != null) {
4488 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4489 } else {
4490 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4491 }
4492 } else {
4493 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4494 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004495 } catch (ImsException e) {
4496 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004497 } finally {
4498 Binder.restoreCallingIdentity(token);
4499 }
4500 }
4501
shilu366312e2019-12-17 09:28:10 -08004502 /**
4503 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4504 * @param subId The subscription to use to check the configuration.
4505 * @param c The callback that will be used to send the result.
4506 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004507 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004508 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004509 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004510 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004511 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4512 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4513 }
Meng Wangafbc5852019-09-19 17:37:13 -07004514
4515 final long token = Binder.clearCallingIdentity();
4516 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004517 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4518 if (controller != null) {
4519 ImsManager imsManager = controller.getImsManager(subId);
4520 if (imsManager != null) {
4521 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4522 } else {
4523 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4524 + " is inactive, ignoring unregister.");
4525 // If the ImsManager is not valid, just return, since the callback
4526 // will already have been removed internally.
4527 }
4528 }
Meng Wangafbc5852019-09-19 17:37:13 -07004529 } finally {
4530 Binder.restoreCallingIdentity(token);
4531 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004532 }
4533
4534 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004535 public boolean isCapable(int subId, int capability, int regTech) {
4536 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004537 final long token = Binder.clearCallingIdentity();
4538 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004539 int slotId = getSlotIndexOrException(subId);
4540 verifyImsMmTelConfiguredOrThrow(slotId);
4541 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4542 } catch (com.android.ims.ImsException e) {
4543 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4544 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004545 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004546 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4547 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004548 } finally {
4549 Binder.restoreCallingIdentity(token);
4550 }
4551 }
4552
4553 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004554 public boolean isAvailable(int subId, int capability, int regTech) {
4555 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004556 final long token = Binder.clearCallingIdentity();
4557 try {
4558 Phone phone = getPhone(subId);
4559 if (phone == null) return false;
4560 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004561 } catch (com.android.ims.ImsException e) {
4562 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4563 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004564 } finally {
4565 Binder.restoreCallingIdentity(token);
4566 }
4567 }
4568
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004569 /**
4570 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4571 * subscription.
4572 * @param subId The subscription to use to check the configuration.
4573 * @param callback The callback that will be used to send the result.
4574 * @param capability The MmTelFeature capability that will be used to send the result.
4575 * @param transportType The transport type of the MmTelFeature capability.
4576 */
4577 @Override
4578 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4579 int transportType) {
4580 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004581 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4582 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4583 "IMS not available on device.");
4584 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004585 final long token = Binder.clearCallingIdentity();
4586 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004587 int slotId = getSlotIndex(subId);
4588 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4589 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4590 + subId + "'");
4591 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4592 }
4593 verifyImsMmTelConfiguredOrThrow(slotId);
4594 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4595 transportType, aBoolean -> {
4596 try {
4597 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4598 } catch (RemoteException e) {
4599 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4600 + "running. Ignore");
4601 }
4602 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004603 } catch (ImsException e) {
4604 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004605 } finally {
4606 Binder.restoreCallingIdentity(token);
4607 }
4608 }
4609
shilu366312e2019-12-17 09:28:10 -08004610 /**
4611 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4612 * @param subId The subscription to use to check the configuration.
4613 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004614 @Override
4615 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004616 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004617 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004618
Brad Ebinger35c841c2018-10-01 10:40:55 -07004619 final long token = Binder.clearCallingIdentity();
4620 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004621 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004622 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004623 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004624 } catch (ImsException e) {
4625 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004626 } finally {
4627 Binder.restoreCallingIdentity(token);
4628 }
4629 }
4630
4631 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004632 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004634 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004635 final long identity = Binder.clearCallingIdentity();
4636 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004637 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004638 // This setting doesn't require an active ImsService connection, so do not verify. The
4639 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004640 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004641 } catch (ImsException e) {
4642 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004643 } finally {
4644 Binder.restoreCallingIdentity(identity);
4645 }
4646 }
4647
shilu366312e2019-12-17 09:28:10 -08004648 /**
4649 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4650 * @param subId The subscription to use to check the configuration.
4651 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004652 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004653 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004654 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004655 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004656 final long identity = Binder.clearCallingIdentity();
4657 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004658 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004659 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004660 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004661 } catch (ImsException e) {
4662 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004663 } finally {
4664 Binder.restoreCallingIdentity(identity);
4665 }
4666 }
4667
4668 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004669 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004671 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004672 final long identity = Binder.clearCallingIdentity();
4673 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004674 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004675 // This setting doesn't require an active ImsService connection, so do not verify. The
4676 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004677 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004678 } catch (ImsException e) {
4679 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004680 } finally {
4681 Binder.restoreCallingIdentity(identity);
4682 }
4683 }
4684
shilu366312e2019-12-17 09:28:10 -08004685 /**
4686 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4687 * @param subId The subscription to use to check the configuration.
4688 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004689 @Override
4690 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004691 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004692 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004693 final long identity = Binder.clearCallingIdentity();
4694 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004695 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004696 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004697 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004698 } catch (ImsException e) {
4699 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004700 } finally {
4701 Binder.restoreCallingIdentity(identity);
4702 }
4703 }
4704
4705 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004706 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004707 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004708 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004709 final long identity = Binder.clearCallingIdentity();
4710 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004711 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004712 // This setting doesn't require an active ImsService connection, so do not verify. The
4713 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004714 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004715 } catch (ImsException e) {
4716 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004717 } finally {
4718 Binder.restoreCallingIdentity(identity);
4719 }
4720 }
4721
shilu366312e2019-12-17 09:28:10 -08004722 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004723 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4724 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4725 * @param subId The subscription to use to check the configuration.
4726 */
4727 @Override
4728 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004729 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004730 mApp, subId, "isCrossSimCallingEnabledByUser");
4731 final long identity = Binder.clearCallingIdentity();
4732 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004733 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004734 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004735 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004736 } catch (ImsException e) {
4737 throw new ServiceSpecificException(e.getCode());
4738 } finally {
4739 Binder.restoreCallingIdentity(identity);
4740 }
4741 }
4742
4743 /**
4744 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4745 * Requires MODIFY_PHONE_STATE permission.
4746 * @param subId The subscription to use to check the configuration.
4747 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4748 * false otherwise
4749 */
4750 @Override
4751 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4752 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4753 "setCrossSimCallingEnabled");
4754 final long identity = Binder.clearCallingIdentity();
4755 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004756 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004757 // This setting doesn't require an active ImsService connection, so do not verify. The
4758 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004759 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004760 } catch (ImsException e) {
4761 throw new ServiceSpecificException(e.getCode());
4762 } finally {
4763 Binder.restoreCallingIdentity(identity);
4764 }
4765 }
4766
4767 /**
shilu366312e2019-12-17 09:28:10 -08004768 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4769 * @param subId The subscription to use to check the configuration.
4770 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004771 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004772
Brad Ebinger35c841c2018-10-01 10:40:55 -07004773 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004774 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004775 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004776 final long identity = Binder.clearCallingIdentity();
4777 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004778 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004779 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004780 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004781 } catch (ImsException e) {
4782 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004783 } finally {
4784 Binder.restoreCallingIdentity(identity);
4785 }
4786 }
4787
4788 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004789 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004791 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004792 final long identity = Binder.clearCallingIdentity();
4793 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004794 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004795 // This setting doesn't require an active ImsService connection, so do not verify. The
4796 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004797 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004798 } catch (ImsException e) {
4799 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004800 } finally {
4801 Binder.restoreCallingIdentity(identity);
4802 }
4803 }
4804
4805 @Override
4806 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4807 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4808 "setVoWiFiNonPersistent");
4809 final long identity = Binder.clearCallingIdentity();
4810 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004811 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004812 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004813 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004814 } catch (ImsException e) {
4815 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004816 } finally {
4817 Binder.restoreCallingIdentity(identity);
4818 }
4819 }
4820
shilu366312e2019-12-17 09:28:10 -08004821 /**
4822 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4823 * @param subId The subscription to use to check the configuration.
4824 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004825 @Override
4826 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004827 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004828 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004829 final long identity = Binder.clearCallingIdentity();
4830 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004831 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004832 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004833 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004834 } catch (ImsException e) {
4835 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004836 } finally {
4837 Binder.restoreCallingIdentity(identity);
4838 }
4839 }
4840
4841 @Override
4842 public void setVoWiFiModeSetting(int subId, int mode) {
4843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4844 "setVoWiFiModeSetting");
4845 final long identity = Binder.clearCallingIdentity();
4846 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004847 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004848 // This setting doesn't require an active ImsService connection, so do not verify. The
4849 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004850 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004851 } catch (ImsException e) {
4852 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004853 } finally {
4854 Binder.restoreCallingIdentity(identity);
4855 }
4856 }
4857
4858 @Override
4859 public int getVoWiFiRoamingModeSetting(int subId) {
4860 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4861 final long identity = Binder.clearCallingIdentity();
4862 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004863 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004864 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004865 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004866 } catch (ImsException e) {
4867 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004868 } finally {
4869 Binder.restoreCallingIdentity(identity);
4870 }
4871 }
4872
4873 @Override
4874 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4875 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4876 "setVoWiFiRoamingModeSetting");
4877 final long identity = Binder.clearCallingIdentity();
4878 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004879 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004880 // This setting doesn't require an active ImsService connection, so do not verify. The
4881 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004882 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004883 } catch (ImsException e) {
4884 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004885 } finally {
4886 Binder.restoreCallingIdentity(identity);
4887 }
4888 }
4889
4890 @Override
4891 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4892 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4893 "setRttCapabilityEnabled");
4894 final long identity = Binder.clearCallingIdentity();
4895 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004896 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004897 // This setting doesn't require an active ImsService connection, so do not verify. The
4898 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004899 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004900 } catch (ImsException e) {
4901 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004902 } finally {
4903 Binder.restoreCallingIdentity(identity);
4904 }
4905 }
4906
shilu366312e2019-12-17 09:28:10 -08004907 /**
4908 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4909 * @param subId The subscription to use to check the configuration.
4910 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004911 @Override
4912 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004913 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004914 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004915 final long identity = Binder.clearCallingIdentity();
4916 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004917 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004918 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004919 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004920 } catch (ImsException e) {
4921 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004922 } finally {
4923 Binder.restoreCallingIdentity(identity);
4924 }
4925 }
4926
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004927 @Override
4928 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4929 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004930
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004931 final long identity = Binder.clearCallingIdentity();
4932 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004933 if (!isImsAvailableOnDevice()) {
4934 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4935 "IMS not available on device.");
4936 }
4937 int slotId = getSlotIndexOrException(subId);
4938 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004939
4940 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4941 if (controller != null) {
4942 ImsManager imsManager = controller.getImsManager(subId);
4943 if (imsManager != null) {
4944 imsManager.addProvisioningCallbackForSubscription(callback, subId);
4945 } else {
4946 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4947 }
4948 } else {
4949 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4950 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004951 } catch (ImsException e) {
4952 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004953 } finally {
4954 Binder.restoreCallingIdentity(identity);
4955 }
4956 }
4957
4958 @Override
4959 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4960 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004961
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004962 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004963 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4964 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4965 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004966 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004967 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4968 if (controller != null) {
4969 ImsManager imsManager = controller.getImsManager(subId);
4970 if (imsManager != null) {
4971 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
4972 } else {
4973 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4974 + " is inactive, ignoring unregister.");
4975 // If the ImsManager is not valid, just return, since the callback will already
4976 // have been removed internally.
4977 }
4978 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004979 } finally {
4980 Binder.restoreCallingIdentity(identity);
4981 }
4982 }
4983
joonhunshincffb7fc2021-11-28 07:32:01 +00004984 @Override
4985 public void registerFeatureProvisioningChangedCallback(int subId,
4986 IFeatureProvisioningCallback callback) {
4987 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4988 mApp, subId, "registerFeatureProvisioningChangedCallback");
4989
4990 final long identity = Binder.clearCallingIdentity();
4991 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4992 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4993 }
4994
joonhunshin91bc1952022-04-29 08:47:15 +00004995 try {
4996 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4997 if (controller == null) {
4998 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4999 "Device does not support IMS");
5000 }
5001 controller.addFeatureProvisioningChangedCallback(subId, callback);
5002 } finally {
5003 Binder.restoreCallingIdentity(identity);
5004 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005005 }
5006
5007 @Override
5008 public void unregisterFeatureProvisioningChangedCallback(int subId,
5009 IFeatureProvisioningCallback callback) {
5010 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5011 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5012
5013 final long identity = Binder.clearCallingIdentity();
5014 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5015 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5016 }
5017
joonhunshin91bc1952022-04-29 08:47:15 +00005018 try {
5019 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5020 if (controller == null) {
5021 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5022 return;
5023 }
5024 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5025 } finally {
5026 Binder.restoreCallingIdentity(identity);
5027 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005028 }
allenwtsu99c623b2020-01-03 18:24:23 +08005029
5030 private void checkModifyPhoneStatePermission(int subId, String message) {
5031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5032 message);
5033 }
5034
allenwtsu99c623b2020-01-03 18:24:23 +08005035 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005036 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005037 boolean isProvisioned) {
5038 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5039
5040 final long identity = Binder.clearCallingIdentity();
5041 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005042 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5043 if (controller == null) {
5044 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5045 return;
5046 }
5047 controller.setRcsProvisioningStatusForCapability(
5048 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005049 } finally {
5050 Binder.restoreCallingIdentity(identity);
5051 }
allenwtsu99c623b2020-01-03 18:24:23 +08005052 }
5053
5054
5055 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005056 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5057 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5058 mApp, subId, "getRcsProvisioningStatusForCapability");
5059
allenwtsu99c623b2020-01-03 18:24:23 +08005060 final long identity = Binder.clearCallingIdentity();
5061 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005062 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5063 if (controller == null) {
5064 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5065
5066 // device does not support IMS, this method will return true always.
5067 return true;
5068 }
5069 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005070 } finally {
5071 Binder.restoreCallingIdentity(identity);
5072 }
5073 }
5074
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005075 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005076 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5077 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005078 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005079
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005080 final long identity = Binder.clearCallingIdentity();
5081 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005082 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5083 if (controller == null) {
5084 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5085 return;
5086 }
5087 controller.setImsProvisioningStatusForCapability(
5088 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005089 } finally {
5090 Binder.restoreCallingIdentity(identity);
5091 }
5092 }
5093
5094 @Override
5095 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005096 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5097 mApp, subId, "getProvisioningStatusForCapability");
5098
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005099 final long identity = Binder.clearCallingIdentity();
5100 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005101 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5102 if (controller == null) {
5103 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005104
joonhunshin91bc1952022-04-29 08:47:15 +00005105 // device does not support IMS, this method will return true always.
5106 return true;
5107 }
5108 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005109 } finally {
5110 Binder.restoreCallingIdentity(identity);
5111 }
5112 }
5113
5114 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005115 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5116 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5117 mApp, subId, "isProvisioningRequiredForCapability");
5118
5119 final long identity = Binder.clearCallingIdentity();
5120 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005121 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5122 if (controller == null) {
5123 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5124
5125 // device does not support IMS, this method will return false
5126 return false;
5127 }
5128 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005129 } finally {
5130 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005131 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005132 }
5133
5134 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005135 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5136 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5137 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005138
joonhunshincffb7fc2021-11-28 07:32:01 +00005139 final long identity = Binder.clearCallingIdentity();
5140 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005141 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5142 if (controller == null) {
5143 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5144
5145 // device does not support IMS, this method will return false
5146 return false;
5147 }
5148 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005149 } finally {
5150 Binder.restoreCallingIdentity(identity);
5151 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005152 }
5153
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005154 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005155 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005156 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5157 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5158 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005159 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5160 mApp, subId, "getImsProvisioningInt");
5161
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005162 final long identity = Binder.clearCallingIdentity();
5163 try {
5164 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005165 int slotId = getSlotIndex(subId);
5166 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5167 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5168 + subId + "' for key:" + key);
5169 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5170 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005171
joonhunshin91bc1952022-04-29 08:47:15 +00005172 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5173 if (controller == null) {
5174 loge("getImsProvisioningInt: Device does not support IMS");
5175
5176 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5177 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5178 }
5179 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005180 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5181 return retVal;
5182 }
5183
calvinpanb5a34062021-02-08 19:59:36 +08005184 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005185 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005186 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5187 + subId + "' for key:" + key);
5188 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005189 } finally {
5190 Binder.restoreCallingIdentity(identity);
5191 }
5192 }
5193
5194 @Override
5195 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005196 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5197 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5198 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005199 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5200 mApp, subId, "getImsProvisioningString");
5201
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005202 final long identity = Binder.clearCallingIdentity();
5203 try {
5204 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005205 int slotId = getSlotIndex(subId);
5206 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5207 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5208 + subId + "' for key:" + key);
5209 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5210 }
calvinpanb5a34062021-02-08 19:59:36 +08005211 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005212 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005213 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5214 + subId + "' for key:" + key);
5215 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005216 } finally {
5217 Binder.restoreCallingIdentity(identity);
5218 }
5219 }
5220
5221 @Override
5222 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005223 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5224 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5225 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005226 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5227 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005228
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005229 final long identity = Binder.clearCallingIdentity();
5230 try {
5231 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005232 int slotId = getSlotIndex(subId);
5233 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5234 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5235 + subId + "' for key:" + key);
5236 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5237 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005238
joonhunshin91bc1952022-04-29 08:47:15 +00005239 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5240 if (controller == null) {
5241 loge("setImsProvisioningInt: Device does not support IMS");
5242
5243 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5244 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5245 }
5246 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005247 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5248 return retVal;
5249 }
5250
calvinpanb5a34062021-02-08 19:59:36 +08005251 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5252 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005253 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005254 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005255 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005256 } finally {
5257 Binder.restoreCallingIdentity(identity);
5258 }
5259 }
5260
5261 @Override
5262 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005263 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5264 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5265 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5267 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005268 final long identity = Binder.clearCallingIdentity();
5269 try {
5270 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005271 int slotId = getSlotIndex(subId);
5272 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5273 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5274 + subId + "' for key:" + key);
5275 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5276 }
calvinpanb5a34062021-02-08 19:59:36 +08005277 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5278 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005279 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005280 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005281 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005282 } finally {
5283 Binder.restoreCallingIdentity(identity);
5284 }
5285 }
5286
Brad Ebinger919631e2021-06-02 17:46:35 -07005287 /**
5288 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5289 * for the given slot ID or no ImsResolver instance has been created.
5290 * @param slotId The slot ID that the IMS service is created for.
5291 * @throws ImsException If there is no ImsService configured for this slot.
5292 */
5293 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5294 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5295 ImsFeature.FEATURE_MMTEL)) {
5296 throw new ImsException("This subscription does not support MMTEL over IMS",
5297 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5298 }
5299 }
5300
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005301 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005302 int slotId = SubscriptionManager.getSlotIndex(subId);
5303 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005304 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5305 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005306 }
5307 return slotId;
5308 }
5309
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005310 private int getSlotIndex(int subId) {
5311 int slotId = SubscriptionManager.getSlotIndex(subId);
5312 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5313 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5314 }
5315 return slotId;
5316 }
5317
Wink Saville36469e72014-06-11 15:17:00 -07005318 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005319 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005320 */
5321 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005322 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5323 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005324 try {
5325 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5326 } catch (SecurityException se) {
5327 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5328 throw new SecurityException("Package " + callingPackage + " does not belong to "
5329 + Binder.getCallingUid());
5330 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005331 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005332 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005333 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005334 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005335 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005336 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005337 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005338 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5339 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005341 final long identity = Binder.clearCallingIdentity();
5342 try {
5343 final Phone phone = getPhone(subId);
5344 if (phone != null) {
5345 return phone.getServiceState().getDataNetworkType();
5346 } else {
5347 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5348 }
5349 } finally {
5350 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005352 }
5353
5354 /**
5355 * Returns the data network type
5356 */
5357 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005358 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005359 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005360 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005361 }
5362
5363 /**
5364 * Returns the data network type for a subId
5365 */
5366 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005367 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5368 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005369 String functionName = "getDataNetworkTypeForSubscriber";
5370 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5371 mApp, functionName)) {
5372 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5373 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5374 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5375 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005376 }
5377
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005378 final long identity = Binder.clearCallingIdentity();
5379 try {
5380 final Phone phone = getPhone(subId);
5381 if (phone != null) {
5382 return phone.getServiceState().getDataNetworkType();
5383 } else {
5384 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5385 }
5386 } finally {
5387 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005388 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005389 }
5390
5391 /**
Wink Saville36469e72014-06-11 15:17:00 -07005392 * Returns the Voice network type for a subId
5393 */
5394 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005395 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5396 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005397 String functionName = "getVoiceNetworkTypeForSubscriber";
5398 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5399 mApp, functionName)) {
5400 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5401 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5402 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5403 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005404 }
5405
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406 final long identity = Binder.clearCallingIdentity();
5407 try {
5408 final Phone phone = getPhone(subId);
5409 if (phone != null) {
5410 return phone.getServiceState().getVoiceNetworkType();
5411 } else {
5412 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5413 }
5414 } finally {
5415 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005416 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005417 }
5418
5419 /**
5420 * @return true if a ICC card is present
5421 */
5422 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005423 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005424 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005425 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005426 }
5427
5428 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005429 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005430 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005431 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005432 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005433 final long identity = Binder.clearCallingIdentity();
5434 try {
5435 final Phone phone = PhoneFactory.getPhone(slotIndex);
5436 if (phone != null) {
5437 return phone.getIccCard().hasIccCard();
5438 } else {
5439 return false;
5440 }
5441 } finally {
5442 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005443 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005444 }
5445
5446 /**
5447 * Return if the current radio is LTE on CDMA. This
5448 * is a tri-state return value as for a period of time
5449 * the mode may be unknown.
5450 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005451 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005452 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005453 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005454 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005455 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005456 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5457 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5458 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005459 }
5460
Sanket Padawe356d7632015-06-22 14:03:32 -07005461 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005462 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5463 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005464 try {
5465 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5466 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005467 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5468 }
5469
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005470 final long identity = Binder.clearCallingIdentity();
5471 try {
5472 final Phone phone = getPhone(subId);
5473 if (phone == null) {
5474 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5475 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005476 return TelephonyProperties.lte_on_cdma_device()
5477 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005478 }
5479 } finally {
5480 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005481 }
Wink Saville36469e72014-06-11 15:17:00 -07005482 }
5483
Wink Saville36469e72014-06-11 15:17:00 -07005484 /**
5485 * {@hide}
5486 * Returns Default subId, 0 in the case of single standby.
5487 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005488 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005489 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005490 }
5491
Shishir Agrawala9f32182016-04-12 12:00:16 -07005492 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005493 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005494 }
5495
Wink Savilleb564aae2014-10-23 10:18:09 -07005496 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005497 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005498 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005499
Pengquan Menge92a50d2018-09-21 15:54:48 -07005500 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08005501 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08005502 return getSubscriptionManagerService().isActiveSubId(subId,
Jack Yu285100e2022-12-02 22:48:35 -08005503 mApp.getOpPackageName(), mApp.getFeatureId());
5504 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07005505 return mSubscriptionController.isActiveSubId(subId);
5506 }
5507
Ihab Awadf2177b72013-11-25 13:33:23 -08005508 /**
5509 * @see android.telephony.TelephonyManager.WifiCallingChoices
5510 */
5511 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005512 final long identity = Binder.clearCallingIdentity();
5513 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005514 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005515 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5516 getWhenToMakeWifiCallsDefaultPreference());
5517 } finally {
5518 Binder.restoreCallingIdentity(identity);
5519 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005520 }
5521
5522 /**
5523 * @see android.telephony.TelephonyManager.WifiCallingChoices
5524 */
5525 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005526 final long identity = Binder.clearCallingIdentity();
5527 try {
5528 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005529 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005530 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5531 } finally {
5532 Binder.restoreCallingIdentity(identity);
5533 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005534 }
5535
Sailesh Nepald1e68152013-12-12 19:08:02 -08005536 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005537 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005538 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005539 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005540
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005541 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5542 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5543 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005544 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005545 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005546 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005547 }
5548 return PhoneFactory.getPhone(phoneId);
5549 }
5550
Shishir Agrawal566b7612013-10-28 14:41:00 -07005551 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005552 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005553 @NonNull IccLogicalChannelRequest request) {
5554 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5555 /*message=*/ "iccOpenLogicalChannel");
5556
5557 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5558 // Verify that the callingPackage in the request belongs to the calling UID
5559 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5560
5561 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005562 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005563
Rambo Wanga1782702021-11-10 20:15:19 -08005564 private Phone getPhoneFromValidIccLogicalChannelRequest(
5565 @NonNull IccLogicalChannelRequest request, String message) {
5566 Phone phone;
5567 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5568 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5569 mApp, request.subId, message);
5570 phone = getPhoneFromSubId(request.subId);
5571 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5572 enforceModifyPermission();
5573 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5574 } else {
5575 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005576 }
Rambo Wanga1782702021-11-10 20:15:19 -08005577 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005578 }
5579
5580 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005581 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005582 final long identity = Binder.clearCallingIdentity();
5583 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005584 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005585 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005586 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5587 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005588 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5589 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005590 loge("The calling package is not allowed to access ISD-R.");
5591 throw new SecurityException(
5592 "The calling package is not allowed to access ISD-R.");
5593 }
Derek Tan740e1672017-06-27 14:56:27 -07005594 }
Derek Tan740e1672017-06-27 14:56:27 -07005595
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005596 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005597 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5598 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005599 return response;
5600 } finally {
5601 Binder.restoreCallingIdentity(identity);
5602 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005603 }
5604
5605 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005606 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5607 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5608 /*message=*/"iccCloseLogicalChannel");
5609
5610 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5611
5612 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005613 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005614
Rambo Wanga1782702021-11-10 20:15:19 -08005615 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5616 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005617 // before this feature is enabled, this API should only return false if
5618 // the operation fails instead of throwing runtime exception for
5619 // backward-compatibility.
5620 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5621 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005622 final long identity = Binder.clearCallingIdentity();
5623 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005624 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005625 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005626 }
Chen Xue9d737e2022-01-01 23:41:31 -08005627 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005628 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005629 Boolean success = false;
5630 if (result instanceof RuntimeException) {
5631 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005632 if (shouldThrowExceptionOnFailure) {
5633 throw (RuntimeException) result;
5634 } else {
5635 return false;
5636 }
Chen Xue9d737e2022-01-01 23:41:31 -08005637 } else if (result instanceof Boolean) {
5638 success = (Boolean) result;
5639 } else {
5640 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5641 }
Rambo Wanga1782702021-11-10 20:15:19 -08005642 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005643 return success;
5644 } finally {
5645 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005646 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005647 }
5648
5649 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005650 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005651 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005652 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5653 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005654 if (DBG) {
5655 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5656 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5657 + p3 + " data=" + data);
5658 }
5659 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5660 command, p1, p2, p3, data);
5661 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005662
Jordan Liu4c733742019-02-28 12:03:40 -08005663 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005664 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005665 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005666 enforceModifyPermission();
5667 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005668 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005669 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5670 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005671 }
5672 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005673 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5674 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005675 }
5676
5677 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5678 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005679 final long identity = Binder.clearCallingIdentity();
5680 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005681 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005682 return "";
5683 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005684
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005685 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005686 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5687 null /* workSource */);
5688 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005689
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005690 // Append the returned status code to the end of the response payload.
5691 String s = Integer.toHexString(
5692 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5693 if (response.payload != null) {
5694 s = IccUtils.bytesToHexString(response.payload) + s;
5695 }
5696 return s;
5697 } finally {
5698 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005699 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005700 }
Jake Hambye994d462014-02-03 13:10:13 -08005701
Evan Charltonc66da362014-05-16 14:06:40 -07005702 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005703 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5704 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005705 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5706 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005707 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005708 if (DBG) {
5709 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5710 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5711 }
5712 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5713 cla, command, p1, p2, p3, data);
5714 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005715
Jordan Liu4c733742019-02-28 12:03:40 -08005716 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005717 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005718 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005719 enforceModifyPermission();
5720 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5721 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005722 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005723 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5724 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005725 }
5726
5727 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005728 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5729 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005730 }
5731
5732 // open APDU basic channel assuming the caller has sufficient permissions
5733 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5734 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005735 final long identity = Binder.clearCallingIdentity();
5736 try {
5737 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5738 && TextUtils.equals(ISDR_AID, data)) {
5739 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005740 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5741 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005742 if (bestComponent == null
5743 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5744 loge("The calling package is not allowed to select ISD-R.");
5745 throw new SecurityException(
5746 "The calling package is not allowed to select ISD-R.");
5747 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005748 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005749
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005750 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005751 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5752 null /* workSource */);
5753 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005754
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005755 // Append the returned status code to the end of the response payload.
5756 String s = Integer.toHexString(
5757 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5758 if (response.payload != null) {
5759 s = IccUtils.bytesToHexString(response.payload) + s;
5760 }
5761 return s;
5762 } finally {
5763 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005764 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005765 }
5766
5767 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005768 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005769 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5771 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005772
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005773 final long identity = Binder.clearCallingIdentity();
5774 try {
5775 if (DBG) {
5776 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5777 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5778 }
5779
5780 IccIoResult response =
5781 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5782 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5783 subId);
5784
5785 if (DBG) {
5786 log("Exchange SIM_IO [R]" + response);
5787 }
5788
5789 byte[] result = null;
5790 int length = 2;
5791 if (response.payload != null) {
5792 length = 2 + response.payload.length;
5793 result = new byte[length];
5794 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5795 } else {
5796 result = new byte[length];
5797 }
5798
5799 result[length - 1] = (byte) response.sw2;
5800 result[length - 2] = (byte) response.sw1;
5801 return result;
5802 } finally {
5803 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005804 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005805 }
5806
Nathan Haroldb3014052017-01-25 15:57:32 -08005807 /**
5808 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5809 * on a particular subscription
5810 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005811 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5812 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005813 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005814 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005815 return null;
5816 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005817
5818 final long identity = Binder.clearCallingIdentity();
5819 try {
5820 if (appType != TelephonyManager.APPTYPE_USIM
5821 && appType != TelephonyManager.APPTYPE_SIM) {
5822 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5823 return null;
5824 }
5825 Object response = sendRequest(
5826 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5827 if (response instanceof String[]) {
5828 return (String[]) response;
5829 }
yincheng zhao2737e882019-09-06 17:06:54 -07005830 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005831 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005832 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005833 } finally {
5834 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005835 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005836 }
5837
yincheng zhao2737e882019-09-06 17:06:54 -07005838 /**
5839 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5840 * subscription.
5841 *
5842 * @param subId the id of the subscription.
5843 * @param appType the uicc app type, must be USIM or SIM.
5844 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5845 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005846 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005847 * @return number of fplmns that is successfully written to the SIM.
5848 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005849 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5850 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005851 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5852 mApp, subId, "setForbiddenPlmns");
5853
yincheng zhao2737e882019-09-06 17:06:54 -07005854 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5855 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5856 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5857 }
5858 if (fplmns == null) {
5859 throw new IllegalArgumentException("Fplmn List provided is null");
5860 }
5861 for (String fplmn : fplmns) {
5862 if (!CellIdentity.isValidPlmn(fplmn)) {
5863 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5864 }
5865 }
5866 final long identity = Binder.clearCallingIdentity();
5867 try {
5868 Object response = sendRequest(
5869 CMD_SET_FORBIDDEN_PLMNS,
5870 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5871 subId);
5872 return (int) response;
5873 } finally {
5874 Binder.restoreCallingIdentity(identity);
5875 }
5876 }
5877
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005878 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005879 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005880 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5881 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005882
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005883 final long identity = Binder.clearCallingIdentity();
5884 try {
5885 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5886 if (response.payload == null) {
5887 return "";
5888 }
Evan Charltonc66da362014-05-16 14:06:40 -07005889
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005890 // Append the returned status code to the end of the response payload.
5891 String s = Integer.toHexString(
5892 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5893 s = IccUtils.bytesToHexString(response.payload) + s;
5894 return s;
5895 } finally {
5896 Binder.restoreCallingIdentity(identity);
5897 }
Evan Charltonc66da362014-05-16 14:06:40 -07005898 }
5899
Jake Hambye994d462014-02-03 13:10:13 -08005900 /**
5901 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5902 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5903 *
5904 * @param itemID the ID of the item to read
5905 * @return the NV item as a String, or null on error.
5906 */
5907 @Override
5908 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005909 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005910 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5911 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005912
5913 final long identity = Binder.clearCallingIdentity();
5914 try {
5915 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005916 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005917 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5918 return value;
5919 } finally {
5920 Binder.restoreCallingIdentity(identity);
5921 }
Jake Hambye994d462014-02-03 13:10:13 -08005922 }
5923
5924 /**
5925 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5926 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5927 *
5928 * @param itemID the ID of the item to read
5929 * @param itemValue the value to write, as a String
5930 * @return true on success; false on any failure
5931 */
5932 @Override
5933 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005934 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005935 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5936 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005937
5938 final long identity = Binder.clearCallingIdentity();
5939 try {
5940 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5941 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005942 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005943 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5944 return success;
5945 } finally {
5946 Binder.restoreCallingIdentity(identity);
5947 }
Jake Hambye994d462014-02-03 13:10:13 -08005948 }
5949
5950 /**
5951 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5952 * Used for device configuration by some CDMA operators.
5953 *
5954 * @param preferredRoamingList byte array containing the new PRL
5955 * @return true on success; false on any failure
5956 */
5957 @Override
5958 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005959 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5960 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005961
5962 final long identity = Binder.clearCallingIdentity();
5963 try {
5964 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5965 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5966 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5967 return success;
5968 } finally {
5969 Binder.restoreCallingIdentity(identity);
5970 }
Jake Hambye994d462014-02-03 13:10:13 -08005971 }
5972
5973 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005974 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005975 * Used for device configuration by some CDMA operators.
5976 *
chen xu6dac5ab2018-10-26 17:39:23 -07005977 * @param slotIndex - device slot.
5978 *
Jake Hambye994d462014-02-03 13:10:13 -08005979 * @return true on success; false on any failure
5980 */
5981 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005982 public boolean resetModemConfig(int slotIndex) {
5983 Phone phone = PhoneFactory.getPhone(slotIndex);
5984 if (phone != null) {
5985 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5986 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005987
chen xu6dac5ab2018-10-26 17:39:23 -07005988 final long identity = Binder.clearCallingIdentity();
5989 try {
5990 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5991 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5992 return success;
5993 } finally {
5994 Binder.restoreCallingIdentity(identity);
5995 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005996 }
chen xu6dac5ab2018-10-26 17:39:23 -07005997 return false;
5998 }
5999
6000 /**
6001 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6002 *
6003 * @param slotIndex - device slot.
6004 *
6005 * @return true on success; false on any failure
6006 */
6007 @Override
6008 public boolean rebootModem(int slotIndex) {
6009 Phone phone = PhoneFactory.getPhone(slotIndex);
6010 if (phone != null) {
6011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6012 mApp, phone.getSubId(), "rebootModem");
6013
6014 final long identity = Binder.clearCallingIdentity();
6015 try {
6016 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6017 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6018 return success;
6019 } finally {
6020 Binder.restoreCallingIdentity(identity);
6021 }
6022 }
6023 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006024 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006025
Brad Ebinger51f743a2017-01-23 13:50:20 -08006026 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006027 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6028 * {@link #disableIms(int)}.
6029 * @param slotIndex device slot.
6030 */
6031 public void resetIms(int slotIndex) {
6032 enforceModifyPermission();
6033
6034 final long identity = Binder.clearCallingIdentity();
6035 try {
6036 if (mImsResolver == null) {
6037 // may happen if the does not support IMS.
6038 return;
6039 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006040 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006041 } finally {
6042 Binder.restoreCallingIdentity(identity);
6043 }
6044 }
6045
6046 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006047 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6048 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006049 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006050 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006051 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006052
6053 final long identity = Binder.clearCallingIdentity();
6054 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006055 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006056 // may happen if the device does not support IMS.
6057 return;
6058 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006059 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006060 } finally {
6061 Binder.restoreCallingIdentity(identity);
6062 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006063 }
6064
6065 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006066 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6067 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006068 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006069 public void disableIms(int slotId) {
6070 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006071
6072 final long identity = Binder.clearCallingIdentity();
6073 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006074 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006075 // may happen if the device does not support IMS.
6076 return;
6077 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006078 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006079 } finally {
6080 Binder.restoreCallingIdentity(identity);
6081 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006082 }
6083
6084 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006085 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6086 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006087 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006088 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006089 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006090 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091
6092 final long identity = Binder.clearCallingIdentity();
6093 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006094 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006095 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6096 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006097 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006098 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006099 } finally {
6100 Binder.restoreCallingIdentity(identity);
6101 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006102 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006103 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006104 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6105 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006106 @Override
6107 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006108 enforceModifyPermission();
6109
6110 final long identity = Binder.clearCallingIdentity();
6111 try {
6112 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006113 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006114 } finally {
6115 Binder.restoreCallingIdentity(identity);
6116 }
6117 }
6118
6119 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006120 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006121 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006122 */
6123 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6124 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006125
6126 final long identity = Binder.clearCallingIdentity();
6127 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006128 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006129 // may happen if the device does not support IMS.
6130 return null;
6131 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006132 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006133 } finally {
6134 Binder.restoreCallingIdentity(identity);
6135 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006136 }
6137
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006138 /**
6139 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006140 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006141 */
6142 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6143 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006144
6145 final long identity = Binder.clearCallingIdentity();
6146 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006147 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006148 // may happen if the device does not support IMS.
6149 return null;
6150 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006151 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006152 } finally {
6153 Binder.restoreCallingIdentity(identity);
6154 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006155 }
6156
Brad Ebinger884c07b2018-02-15 16:17:40 -08006157 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006158 * Sets the ImsService Package Name that Telephony will bind to.
6159 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006160 * @param slotIndex the slot ID that the ImsService should bind for.
6161 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006162 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006163 * @param featureTypes An integer array of feature types associated with a packageName.
6164 * @param packageName The name of the package that the current configuration will be replaced
6165 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006166 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006167 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006168 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6169 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006170 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006171 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006172 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006173
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006174 final long identity = Binder.clearCallingIdentity();
6175 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006176 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006177 // may happen if the device does not support IMS.
6178 return false;
6179 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006180 Map<Integer, String> featureConfig = new HashMap<>();
6181 for (int featureType : featureTypes) {
6182 featureConfig.put(featureType, packageName);
6183 }
6184 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6185 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006186 } finally {
6187 Binder.restoreCallingIdentity(identity);
6188 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006189 }
6190
6191 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006192 * Clears any carrier ImsService overrides for the slot index specified that were previously
6193 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6194 *
6195 * This should only be used for testing.
6196 *
6197 * @param slotIndex the slot ID that the ImsService should bind for.
6198 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6199 */
6200 @Override
6201 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006202 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6203 "clearCarrierImsServiceOverride");
6204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006205 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006206
6207 final long identity = Binder.clearCallingIdentity();
6208 try {
6209 if (mImsResolver == null) {
6210 // may happen if the device does not support IMS.
6211 return false;
6212 }
6213 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6214 } finally {
6215 Binder.restoreCallingIdentity(identity);
6216 }
6217 }
6218
6219 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006220 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006221 *
6222 * @param slotId The slot that the ImsService is associated with.
6223 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6224 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006225 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006226 * @return the package name of the ImsService configuration.
6227 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006228 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6229 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006230 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006231 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6232 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006233
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006234 final long identity = Binder.clearCallingIdentity();
6235 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006236 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006237 // may happen if the device does not support IMS.
6238 return "";
6239 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006240 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006241 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6242 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006243 } finally {
6244 Binder.restoreCallingIdentity(identity);
6245 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006246 }
6247
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006248 /**
6249 * Get the MmTelFeature state associated with the requested subscription id.
6250 * @param subId The subscription that the MmTelFeature is associated with.
6251 * @param callback A callback with an integer containing the
6252 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6253 */
6254 @Override
6255 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6256 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006257 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6258 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6259 "IMS not available on device.");
6260 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006261 final long token = Binder.clearCallingIdentity();
6262 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006263 int slotId = getSlotIndex(subId);
6264 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6265 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6266 + subId + "'");
6267 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6268 }
6269 verifyImsMmTelConfiguredOrThrow(slotId);
6270 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6271 try {
6272 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6273 } catch (RemoteException e) {
6274 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6275 + "Ignore");
6276 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006277 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006278 } catch (ImsException e) {
6279 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006280 } finally {
6281 Binder.restoreCallingIdentity(token);
6282 }
6283 }
6284
Daniel Brightbb5840b2021-01-12 15:48:18 -08006285 /**
6286 * Sets the ims registration state on all valid {@link Phone}s.
6287 */
6288 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006289 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006290
6291 final long identity = Binder.clearCallingIdentity();
6292 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006293 // NOTE: Before S, this method only set the default phone.
6294 for (final Phone phone : PhoneFactory.getPhones()) {
6295 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6296 phone.setImsRegistrationState(registered);
6297 }
6298 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006299 } finally {
6300 Binder.restoreCallingIdentity(identity);
6301 }
Wink Saville36469e72014-06-11 15:17:00 -07006302 }
6303
6304 /**
Stuart Scott54788802015-03-30 13:18:01 -07006305 * Set the network selection mode to automatic.
6306 *
6307 */
6308 @Override
6309 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6311 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006312
6313 final long identity = Binder.clearCallingIdentity();
6314 try {
shilufc958392020-01-20 11:36:01 -08006315 if (!isActiveSubscription(subId)) {
6316 return;
6317 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006318 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006319 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6320 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006321 } finally {
6322 Binder.restoreCallingIdentity(identity);
6323 }
Stuart Scott54788802015-03-30 13:18:01 -07006324 }
6325
Jack Yud10cdd42020-09-28 20:28:01 -07006326 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006327 * Ask the radio to connect to the input network and change selection mode to manual.
6328 *
6329 * @param subId the id of the subscription.
6330 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6331 * the operator to attach to.
6332 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6333 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6334 * normal network selection next time.
6335 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006336 */
6337 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006338 public boolean setNetworkSelectionModeManual(
6339 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6341 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006342
Jack Yu285100e2022-12-02 22:48:35 -08006343 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006344 if (!isActiveSubscription(subId)) {
6345 return false;
6346 }
6347
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006348 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006349 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006350 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006351 if (DBG) {
6352 log("setNetworkSelectionModeManual: subId: " + subId
6353 + " operator: " + operatorInfo);
6354 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006355 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6356 } finally {
6357 Binder.restoreCallingIdentity(identity);
6358 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006359 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006360 /**
shilu84f6e8b2019-12-19 13:58:01 -08006361 * Get the manual network selection
6362 *
6363 * @param subId the id of the subscription.
6364 *
6365 * @return the previously saved user selected PLMN
6366 */
6367 @Override
6368 public String getManualNetworkSelectionPlmn(int subId) {
6369 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006370 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6371 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006372
6373 final long identity = Binder.clearCallingIdentity();
6374 try {
6375 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006376 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006377 }
6378
6379 final Phone phone = getPhone(subId);
6380 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006381 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006382 }
6383 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6384 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006385 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006386 } finally {
6387 Binder.restoreCallingIdentity(identity);
6388 }
6389 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006390
6391 /**
6392 * Scans for available networks.
6393 */
6394 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006395 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6396 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006397 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6398 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006399 LocationAccessPolicy.LocationPermissionResult locationResult =
6400 LocationAccessPolicy.checkLocationPermission(mApp,
6401 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6402 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006403 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006404 .setCallingPid(Binder.getCallingPid())
6405 .setCallingUid(Binder.getCallingUid())
6406 .setMethod("getCellNetworkScanResults")
6407 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006408 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6409 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006410 .build());
6411 switch (locationResult) {
6412 case DENIED_HARD:
6413 throw new SecurityException("Not allowed to access scan results -- location");
6414 case DENIED_SOFT:
6415 return null;
6416 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006417
Pengquan Menga1bb6272018-09-06 09:59:22 -07006418 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006419 try {
6420 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006421 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006422 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006423 } finally {
6424 Binder.restoreCallingIdentity(identity);
6425 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006426 }
6427
6428 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006429 * Get the call forwarding info, given the call forwarding reason.
6430 */
6431 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006432 public void getCallForwarding(int subId, int callForwardingReason,
6433 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006434 enforceReadPrivilegedPermission("getCallForwarding");
6435 long identity = Binder.clearCallingIdentity();
6436 try {
6437 if (DBG) {
6438 log("getCallForwarding: subId " + subId
6439 + " callForwardingReason" + callForwardingReason);
6440 }
Hall Liu27d24262020-09-18 19:04:59 -07006441
6442 Phone phone = getPhone(subId);
6443 if (phone == null) {
6444 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006445 callback.onError(
6446 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006447 } catch (RemoteException e) {
6448 // ignore
6449 }
6450 return;
6451 }
6452
6453 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6454 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6455 @Override
6456 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6457 try {
6458 callback.onCallForwardingInfoAvailable(info);
6459 } catch (RemoteException e) {
6460 // ignore
6461 }
6462 }
6463
6464 @Override
6465 public void onError(int error) {
6466 try {
6467 callback.onError(error);
6468 } catch (RemoteException e) {
6469 // ignore
6470 }
6471 }
6472 });
6473 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006474 } finally {
6475 Binder.restoreCallingIdentity(identity);
6476 }
6477 }
6478
6479 /**
6480 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6481 * reason, the number to forward, and the timeout before the forwarding is attempted.
6482 */
6483 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006484 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6485 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006486 enforceModifyPermission();
6487 long identity = Binder.clearCallingIdentity();
6488 try {
6489 if (DBG) {
6490 log("setCallForwarding: subId " + subId
6491 + " callForwardingInfo" + callForwardingInfo);
6492 }
Hall Liu27d24262020-09-18 19:04:59 -07006493
6494 Phone phone = getPhone(subId);
6495 if (phone == null) {
6496 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006497 callback.accept(
6498 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006499 } catch (RemoteException e) {
6500 // ignore
6501 }
6502 return;
6503 }
6504
6505 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6506 FunctionalUtils.ignoreRemoteException(callback::accept));
6507
6508 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006509 } finally {
6510 Binder.restoreCallingIdentity(identity);
6511 }
6512 }
6513
6514 /**
Hall Liu27d24262020-09-18 19:04:59 -07006515 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006516 */
6517 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006518 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006519 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006520 long identity = Binder.clearCallingIdentity();
6521 try {
Hall Liu27d24262020-09-18 19:04:59 -07006522 Phone phone = getPhone(subId);
6523 if (phone == null) {
6524 try {
6525 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6526 } catch (RemoteException e) {
6527 // ignore
6528 }
6529 return;
6530 }
SongFerngWang0e767992021-03-31 22:08:45 +08006531 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6532 PersistableBundle c = configManager.getConfigForSubId(subId);
6533 boolean requireUssd = c.getBoolean(
6534 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006535
Shuo Qian4a594052020-01-23 11:59:30 -08006536 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006537 if (requireUssd) {
6538 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6539 getSubscriptionCarrierId(subId));
6540 String newUssdCommand = "";
6541 try {
6542 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006543 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006544 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6545 } catch (NullPointerException e) {
6546 loge("Failed to generate USSD number" + e);
6547 }
6548 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6549 mMainThreadHandler, callback, carrierXmlParser,
6550 CarrierXmlParser.SsEntry.SSAction.QUERY);
6551 final String ussdCommand = newUssdCommand;
6552 Executors.newSingleThreadExecutor().execute(() -> {
6553 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6554 });
6555 } else {
6556 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6557 callback::accept);
6558 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6559 }
Shuo Qian4a594052020-01-23 11:59:30 -08006560 } finally {
6561 Binder.restoreCallingIdentity(identity);
6562 }
6563 }
6564
6565 /**
Hall Liu27d24262020-09-18 19:04:59 -07006566 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006567 */
6568 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006569 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006570 enforceModifyPermission();
6571 long identity = Binder.clearCallingIdentity();
6572 try {
Hall Liu27d24262020-09-18 19:04:59 -07006573 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6574
6575 Phone phone = getPhone(subId);
6576 if (phone == null) {
6577 try {
6578 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6579 } catch (RemoteException e) {
6580 // ignore
6581 }
6582 return;
6583 }
6584
SongFerngWang0e767992021-03-31 22:08:45 +08006585 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6586 PersistableBundle c = configManager.getConfigForSubId(subId);
6587 boolean requireUssd = c.getBoolean(
6588 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006589
SongFerngWang0e767992021-03-31 22:08:45 +08006590 if (DBG) log("getCallWaitingStatus: subId " + subId);
6591 if (requireUssd) {
6592 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6593 getSubscriptionCarrierId(subId));
6594 CarrierXmlParser.SsEntry.SSAction ssAction =
6595 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6596 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6597 String newUssdCommand = "";
6598 try {
6599 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006600 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006601 .makeCommand(ssAction, null);
6602 } catch (NullPointerException e) {
6603 loge("Failed to generate USSD number" + e);
6604 }
6605 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6606 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6607 final String ussdCommand = newUssdCommand;
6608 Executors.newSingleThreadExecutor().execute(() -> {
6609 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6610 });
6611 } else {
6612 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6613 FunctionalUtils.ignoreRemoteException(callback::accept));
6614
6615 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6616 }
Shuo Qian4a594052020-01-23 11:59:30 -08006617 } finally {
6618 Binder.restoreCallingIdentity(identity);
6619 }
6620 }
6621
6622 /**
yinxub1bed742017-04-17 11:45:04 -07006623 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006624 *
yinxub1bed742017-04-17 11:45:04 -07006625 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006626 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6627 * location related information which will be sent if the caller already possess
6628 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006629 * @param request contains the radio access networks with bands/channels to scan
6630 * @param messenger callback messenger for scan results or errors
6631 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006632 * @return the id of the requested scan which can be used to stop the scan.
6633 */
6634 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006635 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6636 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006637 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006638 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6639 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006640 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006641 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6642 if (!renounceFineLocationAccess) {
6643 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006644 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6645 .setCallingPackage(callingPackage)
6646 .setCallingFeatureId(callingFeatureId)
6647 .setCallingPid(Binder.getCallingPid())
6648 .setCallingUid(Binder.getCallingUid())
6649 .setMethod("requestNetworkScan")
6650 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6651 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6652 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6653 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006654 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006655 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006656 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6657 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006658 if (e != null) {
6659 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6660 throw e;
6661 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006662 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006663 return TelephonyScanManager.INVALID_SCAN_ID;
6664 }
6665 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006666 }
Hall Liu912dfd32019-04-25 14:02:26 -07006667 int callingUid = Binder.getCallingUid();
6668 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006669 final long identity = Binder.clearCallingIdentity();
6670 try {
6671 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006672 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006673 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006674 } finally {
6675 Binder.restoreCallingIdentity(identity);
6676 }
yinxu504e1392017-04-12 16:03:22 -07006677 }
6678
Hall Liub2ac8ef2019-02-28 15:56:23 -08006679 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006680 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006681 boolean hasCarrierPriv;
6682 final long identity = Binder.clearCallingIdentity();
6683 try {
6684 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6685 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6686 } finally {
6687 Binder.restoreCallingIdentity(identity);
6688 }
Hall Liu558027f2019-05-15 19:14:05 -07006689 boolean hasNetworkScanPermission =
6690 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006691 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07006692
6693 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6694 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6695 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006696 }
6697
6698 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6699 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006700 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6701 return new SecurityException("Specific channels must not be"
6702 + " scanned without location access.");
6703 }
6704 }
6705 }
6706
Hall Liub2ac8ef2019-02-28 15:56:23 -08006707 return null;
6708 }
6709
yinxu504e1392017-04-12 16:03:22 -07006710 /**
6711 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006712 *
6713 * @param subId id of the subscription
6714 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006715 */
6716 @Override
6717 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006718 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6719 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006720
Hall Liu912dfd32019-04-25 14:02:26 -07006721 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006722 final long identity = Binder.clearCallingIdentity();
6723 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006724 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006725 } finally {
6726 Binder.restoreCallingIdentity(identity);
6727 }
yinxu504e1392017-04-12 16:03:22 -07006728 }
6729
6730 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006731 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006732 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006733 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006734 */
6735 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006736 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006737 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006738 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006739 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006740
6741 final long identity = Binder.clearCallingIdentity();
6742 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006743 if (DBG) log("getAllowedNetworkTypesBitmask");
6744 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6745 int networkTypesBitmask = (result != null ? result[0] : -1);
6746 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6747 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006748 } finally {
6749 Binder.restoreCallingIdentity(identity);
6750 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006751 }
6752
6753 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006754 * Get the allowed network types for certain reason.
6755 *
6756 * @param subId the id of the subscription.
6757 * @param reason the reason the allowed network type change is taking place
6758 * @return the allowed network types.
6759 */
6760 @Override
6761 public long getAllowedNetworkTypesForReason(int subId,
6762 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006763 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006764 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006765 final long identity = Binder.clearCallingIdentity();
6766 try {
6767 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6768 } finally {
6769 Binder.restoreCallingIdentity(identity);
6770 }
6771 }
6772
6773 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006774 * Enable/Disable E-UTRA-NR Dual Connectivity
6775 * @param subId subscription id of the sim card
6776 * @param nrDualConnectivityState expected NR dual connectivity state
6777 * This can be passed following states
6778 * <ol>
6779 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6780 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6781 * <li>Disable NR dual connectivity and force secondary cell to be released
6782 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6783 * </ol>
6784 * @return operation result.
6785 */
6786 @Override
6787 public int setNrDualConnectivityState(int subId,
6788 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6790 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006791 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006792 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6793 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6794 }
6795
Sooraj Sasindran37444802020-08-11 10:40:43 -07006796 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6797 final long identity = Binder.clearCallingIdentity();
6798 try {
6799 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6800 nrDualConnectivityState, subId,
6801 workSource);
6802 if (DBG) log("enableNRDualConnectivity result: " + result);
6803 return result;
6804 } finally {
6805 Binder.restoreCallingIdentity(identity);
6806 }
6807 }
6808
6809 /**
6810 * Is E-UTRA-NR Dual Connectivity enabled
6811 * @return true if dual connectivity is enabled else false
6812 */
6813 @Override
6814 public boolean isNrDualConnectivityEnabled(int subId) {
6815 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006816 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006817 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006818 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006819 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6820 return false;
6821 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006822 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6823 final long identity = Binder.clearCallingIdentity();
6824 try {
6825 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6826 null, subId, workSource);
6827 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6828 return isEnabled;
6829 } finally {
6830 Binder.restoreCallingIdentity(identity);
6831 }
6832 }
6833
6834 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006835 * Set the allowed network types of the device and
6836 * provide the reason triggering the allowed network change.
6837 *
6838 * @param subId the id of the subscription.
6839 * @param reason the reason the allowed network type change is taking place
6840 * @param allowedNetworkTypes the allowed network types.
6841 * @return true on success; false on any failure.
6842 */
6843 @Override
6844 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006845 @TelephonyManager.AllowedNetworkTypesReason int reason,
6846 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6848 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006849 // If the caller only has carrier privileges, then they should not be able to override
6850 // any network types which were set for security reasons.
6851 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6852 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006853 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006854 throw new SecurityException(
6855 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006856 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006857 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006858 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006859 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08006860 return false;
6861 }
6862 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6863 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006864 return false;
6865 }
6866
Jack Yu5b494332023-01-23 18:18:04 +00006867 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
6868 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006869
Jack Yue37dd262022-12-16 11:53:37 -08006870 Phone phone = getPhone(subId);
6871 if (phone == null) {
6872 return false;
6873 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006874
Jack Yue37dd262022-12-16 11:53:37 -08006875 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006876 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006877 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006878 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006879
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006880 final long identity = Binder.clearCallingIdentity();
6881 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006882 Boolean success = (Boolean) sendRequest(
6883 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6884 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6885
6886 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6887 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006888 } finally {
6889 Binder.restoreCallingIdentity(identity);
6890 }
6891 }
6892
6893 /**
Miaoa84611c2019-03-15 09:21:10 +08006894 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006895 *
Miaoa84611c2019-03-15 09:21:10 +08006896 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006897 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006898 * @hide
6899 */
6900 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006901 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006902 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006903 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006904 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006905 try {
Miaoa84611c2019-03-15 09:21:10 +08006906 if (phone != null) {
6907 return phone.hasMatchedTetherApnSetting();
6908 } else {
6909 return false;
6910 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006911 } finally {
6912 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006913 }
Junda Liu475951f2014-11-07 16:45:03 -08006914 }
6915
6916 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006917 * Get the user enabled state of Mobile Data.
6918 *
6919 * TODO: remove and use isUserDataEnabled.
6920 * This can't be removed now because some vendor codes
6921 * calls through ITelephony directly while they should
6922 * use TelephonyManager.
6923 *
6924 * @return true on enabled
6925 */
6926 @Override
6927 public boolean getDataEnabled(int subId) {
6928 return isUserDataEnabled(subId);
6929 }
6930
6931 /**
6932 * Get whether mobile data is enabled per user setting.
6933 *
6934 * There are other factors deciding whether mobile data is actually enabled, but they are
6935 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006936 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006937 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6938 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006939 *
6940 * @return {@code true} if data is enabled else {@code false}
6941 */
6942 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006943 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006944 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006945 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006946 try {
6947 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6948 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006949 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006950 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6951 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006952 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006953 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006954 mApp, subId, functionName);
6955
Robert Greenwalt646120a2014-05-23 11:54:03 -07006956 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006957
6958 final long identity = Binder.clearCallingIdentity();
6959 try {
Jack Yu285100e2022-12-02 22:48:35 -08006960 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006961 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6962 Phone phone = PhoneFactory.getPhone(phoneId);
6963 if (phone != null) {
6964 boolean retVal = phone.isUserDataEnabled();
6965 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6966 return retVal;
6967 } else {
6968 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6969 return false;
6970 }
6971 } finally {
6972 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006973 }
6974 }
6975
6976 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006977 * Checks if the device is capable of mobile data by considering whether whether the
6978 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6979 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006980 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006981 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006982 */
6983 @Override
6984 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006985 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006986 try {
6987 try {
6988 mApp.enforceCallingOrSelfPermission(
6989 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006990 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006991 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006992 try {
6993 mApp.enforceCallingOrSelfPermission(
6994 android.Manifest.permission.READ_PHONE_STATE,
6995 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006996 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006997 mApp.enforceCallingOrSelfPermission(
6998 permission.READ_BASIC_PHONE_STATE, functionName);
6999 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007000 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007001 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007002 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007003 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007004
7005 final long identity = Binder.clearCallingIdentity();
7006 try {
Jack Yu285100e2022-12-02 22:48:35 -08007007 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007008 Phone phone = PhoneFactory.getPhone(phoneId);
7009 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007010 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007011 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007012 return retVal;
7013 } else {
7014 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7015 return false;
7016 }
7017 } finally {
7018 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007019 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007020 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007021
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007022 /**
7023 * Check if data is enabled for a specific reason
7024 * @param subId Subscription index
7025 * @param reason the reason the data enable change is taking place
7026 * @return {@code true} if the overall data is enabled; {@code false} if not.
7027 */
7028 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007029 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007030 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007031 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007032 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007033 try {
7034 mApp.enforceCallingOrSelfPermission(
7035 android.Manifest.permission.ACCESS_NETWORK_STATE,
7036 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007037 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007038 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7039 functionName);
7040 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007041 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007042 try {
7043 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007044 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007045 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007046 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007047 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007048 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007049 }
7050
7051
7052 final long identity = Binder.clearCallingIdentity();
7053 try {
Jack Yu285100e2022-12-02 22:48:35 -08007054 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007055 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007056 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007057 + " reason=" + reason);
7058 }
7059 Phone phone = PhoneFactory.getPhone(phoneId);
7060 if (phone != null) {
7061 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007062 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007063 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007064 return retVal;
7065 } else {
7066 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007067 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007068 + subId + " retVal=false");
7069 }
7070 return false;
7071 }
7072 } finally {
7073 Binder.restoreCallingIdentity(identity);
7074 }
7075 }
7076
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007077 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007078 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007079 // No permission needed; this only lets the caller inspect their own status.
7080 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007081 }
Junda Liu29340342014-07-10 15:23:27 -07007082
7083 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007084 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007085 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007086 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7087 }
7088
7089 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7090 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007091 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007092 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007093 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7094 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007095 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7096 if (cpt == null) {
7097 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007098 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7099 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007100 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007101 }
7102
7103 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007104 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007105 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007106 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007107 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007108 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007109 Phone phone = getPhone(subId);
7110 if (phone == null) {
7111 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7112 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7113 }
7114 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7115 if (cpt == null) {
7116 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007117 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7118 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007119 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007120 }
7121
7122 @Override
7123 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007124 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007125 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7126 }
7127
7128 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007129 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007130 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007131 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007132 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007133 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7134 Phone phone = PhoneFactory.getPhone(phoneId);
7135 if (phone == null) {
7136 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007137 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007138 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7139 if (cpt == null) {
7140 continue;
7141 }
7142 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007143 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7144 break;
7145 }
7146 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007147 return result;
Junda Liu29340342014-07-10 15:23:27 -07007148 }
Derek Tan89e89d42014-07-08 17:00:10 -07007149
7150 @Override
Junda Liue64de782015-04-16 17:19:16 -07007151 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007152 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007153 Phone phone = PhoneFactory.getPhone(phoneId);
7154 if (phone == null) {
7155 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007156 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007157 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7158 if (cpt == null) {
7159 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007160 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007161 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007162 }
7163
Amith Yamasani6e118872016-02-19 12:53:51 -08007164 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007165 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007166 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007167 Phone phone = PhoneFactory.getPhone(phoneId);
7168 if (phone == null) {
7169 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007170 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007171 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7172 if (cpt == null) {
7173 return Collections.emptyList();
7174 }
7175 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007176 }
7177
chen xuf7e9fe82019-05-09 19:31:02 -07007178 @Override
7179 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007180 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007181 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007182 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007183 try {
7184 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7185 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7186 }
7187 } finally {
7188 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007189 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007190 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007191 }
7192
Rambo Wang6812ffb2022-03-15 16:54:17 -07007193 @Override
7194 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7195 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7196
7197 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7198 if (phone == null) {
7199 return null;
7200 }
7201 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7202 if (cpt == null) {
7203 return null;
7204 }
7205 return cpt.getCarrierServicePackageName();
7206 }
7207
Wink Savilleb564aae2014-10-23 10:18:09 -07007208 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007209 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007210 UiccPort port = phone == null ? null : phone.getUiccPort();
7211 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007212 return null;
7213 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007214 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007215 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007216 return null;
7217 }
7218 return iccId;
7219 }
7220
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007221 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007222 public void setCallComposerStatus(int subId, int status) {
7223 enforceModifyPermission();
7224
7225 final long identity = Binder.clearCallingIdentity();
7226 try {
7227 Phone phone = getPhone(subId);
7228 if (phone != null) {
7229 Phone defaultPhone = phone.getImsPhone();
7230 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7231 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7232 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007233 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7234 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007235 }
7236 }
Shuo Qian284ae752020-12-22 19:10:14 -08007237 } catch (ImsException e) {
7238 throw new ServiceSpecificException(e.getCode());
7239 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007240 Binder.restoreCallingIdentity(identity);
7241 }
7242 }
7243
7244 @Override
7245 public int getCallComposerStatus(int subId) {
7246 enforceReadPrivilegedPermission("getCallComposerStatus");
7247
7248 final long identity = Binder.clearCallingIdentity();
7249 try {
7250 Phone phone = getPhone(subId);
7251 if (phone != null) {
7252 Phone defaultPhone = phone.getImsPhone();
7253 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7254 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7255 return imsPhone.getCallComposerStatus();
7256 }
7257 }
7258 } finally {
7259 Binder.restoreCallingIdentity(identity);
7260 }
7261 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7262 }
7263
7264 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007265 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7266 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007267 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007268 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007269
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007270 final long identity = Binder.clearCallingIdentity();
7271 try {
7272 final String iccId = getIccId(subId);
7273 final Phone phone = getPhone(subId);
7274 if (phone == null) {
7275 return false;
7276 }
7277 final String subscriberId = phone.getSubscriberId();
7278
7279 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007280 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007281 + subscriberId + " to " + number);
7282 }
7283
7284 if (TextUtils.isEmpty(iccId)) {
7285 return false;
7286 }
7287
7288 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7289
7290 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7291 if (alphaTag == null) {
7292 editor.remove(alphaTagPrefKey);
7293 } else {
7294 editor.putString(alphaTagPrefKey, alphaTag);
7295 }
7296
7297 // Record both the line number and IMSI for this ICCID, since we need to
7298 // track all merged IMSIs based on line number
7299 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7300 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7301 if (number == null) {
7302 editor.remove(numberPrefKey);
7303 editor.remove(subscriberPrefKey);
7304 } else {
7305 editor.putString(numberPrefKey, number);
7306 editor.putString(subscriberPrefKey, subscriberId);
7307 }
7308
7309 editor.commit();
7310 return true;
7311 } finally {
7312 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007313 }
Derek Tan7226c842014-07-02 17:42:23 -07007314 }
7315
7316 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007317 public String getLine1NumberForDisplay(int subId, String callingPackage,
7318 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007319 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007320 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007321 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007322 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007323 return null;
7324 }
Derek Tan97ebb422014-09-05 16:55:38 -07007325
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007326 final long identity = Binder.clearCallingIdentity();
7327 try {
7328 String iccId = getIccId(subId);
7329 if (iccId != null) {
7330 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7331 if (DBG_MERGE) {
7332 log("getLine1NumberForDisplay returning "
7333 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7334 }
7335 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007336 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007337 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7338 return null;
7339 } finally {
7340 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007341 }
Derek Tan7226c842014-07-02 17:42:23 -07007342 }
7343
7344 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007345 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7346 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007347 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007348 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007349 return null;
7350 }
Derek Tan97ebb422014-09-05 16:55:38 -07007351
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007352 final long identity = Binder.clearCallingIdentity();
7353 try {
7354 String iccId = getIccId(subId);
7355 if (iccId != null) {
7356 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7357 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7358 }
7359 return null;
7360 } finally {
7361 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007362 }
Derek Tan7226c842014-07-02 17:42:23 -07007363 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007364
7365 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007366 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7367 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007368 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7369 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007370 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007371 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007372 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007373 return null;
7374 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007375
Jordan Liub49b04b2019-05-06 14:45:15 -07007376 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7377 // the process, where TelephonyManager was instantiated.
7378 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007379 final long identity = Binder.clearCallingIdentity();
7380 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007381 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007382 final TelephonyManager tele = TelephonyManager.from(context);
7383 final SubscriptionManager sub = SubscriptionManager.from(context);
7384
7385 // Figure out what subscribers are currently active
7386 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007387
Jordan Liub49b04b2019-05-06 14:45:15 -07007388 // Only consider subs which match the current subId
7389 // This logic can be simplified. See b/131189269 for progress.
7390 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007391 activeSubscriberIds.add(tele.getSubscriberId(subId));
7392 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007393
7394 // First pass, find a number override for an active subscriber
7395 String mergeNumber = null;
7396 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7397 for (String key : prefs.keySet()) {
7398 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7399 final String subscriberId = (String) prefs.get(key);
7400 if (activeSubscriberIds.contains(subscriberId)) {
7401 final String iccId = key.substring(
7402 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7403 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7404 mergeNumber = (String) prefs.get(numberKey);
7405 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007406 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007407 + " for active subscriber " + subscriberId);
7408 }
7409 if (!TextUtils.isEmpty(mergeNumber)) {
7410 break;
7411 }
7412 }
7413 }
7414 }
7415
7416 // Shortcut when no active merged subscribers
7417 if (TextUtils.isEmpty(mergeNumber)) {
7418 return null;
7419 }
7420
7421 // Second pass, find all subscribers under that line override
7422 final ArraySet<String> result = new ArraySet<>();
7423 for (String key : prefs.keySet()) {
7424 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7425 final String number = (String) prefs.get(key);
7426 if (mergeNumber.equals(number)) {
7427 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7428 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7429 final String subscriberId = (String) prefs.get(subscriberKey);
7430 if (!TextUtils.isEmpty(subscriberId)) {
7431 result.add(subscriberId);
7432 }
7433 }
7434 }
7435 }
7436
7437 final String[] resultArray = result.toArray(new String[result.size()]);
7438 Arrays.sort(resultArray);
7439 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007440 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007441 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7442 }
7443 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007444 } finally {
7445 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007446 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007447 }
7448
7449 @Override
zoey chen38003472019-12-13 17:16:31 +08007450 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7451 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007452
7453 final long identity = Binder.clearCallingIdentity();
7454 try {
7455 final TelephonyManager telephonyManager = mApp.getSystemService(
7456 TelephonyManager.class);
7457 String subscriberId = telephonyManager.getSubscriberId(subId);
7458 if (subscriberId == null) {
7459 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007460 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007461 + subId);
7462 }
7463 return null;
7464 }
7465
Jack Yu285100e2022-12-02 22:48:35 -08007466 ParcelUuid groupUuid;
7467 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08007468 final SubscriptionInfo info = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08007469 .getSubscriptionInfo(subId);
7470 groupUuid = info.getGroupUuid();
7471 } else {
7472 final SubscriptionInfo info = mSubscriptionController
7473 .getSubscriptionInfo(subId);
7474 groupUuid = info.getGroupUuid();
7475 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007476 // If it doesn't belong to any group, return just subscriberId of itself.
7477 if (groupUuid == null) {
7478 return new String[]{subscriberId};
7479 }
7480
7481 // Get all subscriberIds from the group.
7482 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08007483 List<SubscriptionInfo> groupInfos;
7484 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08007485 groupInfos = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08007486 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7487 mApp.getAttributionTag());
7488 } else {
7489 groupInfos = mSubscriptionController
7490 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7491 mApp.getAttributionTag());
7492 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007493 for (SubscriptionInfo subInfo : groupInfos) {
7494 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7495 if (subscriberId != null) {
7496 mergedSubscriberIds.add(subscriberId);
7497 }
7498 }
7499
7500 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7501 } finally {
7502 Binder.restoreCallingIdentity(identity);
7503
7504 }
7505 }
7506
7507 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007508 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007509 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007510 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007511
7512 final long identity = Binder.clearCallingIdentity();
7513 try {
7514 final Phone phone = getPhone(subId);
7515 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7516 } finally {
7517 Binder.restoreCallingIdentity(identity);
7518 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007519 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007520
7521 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007522 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007523 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7524 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007525 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7526 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007527
7528 final long identity = Binder.clearCallingIdentity();
7529 try {
7530 final Phone phone = getPhone(subId);
7531 if (phone == null) {
7532 return false;
7533 }
7534 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7535 cdmaNonRoamingList);
7536 } finally {
7537 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007538 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007539 }
7540
7541 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007542 @Deprecated
7543 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7544 enforceModifyPermission();
7545
7546 int returnValue = 0;
7547 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007548 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007549 if(result.exception == null) {
7550 if (result.result != null) {
7551 byte[] responseData = (byte[])(result.result);
7552 if(responseData.length > oemResp.length) {
7553 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7554 responseData.length + "bytes. Buffer Size is " +
7555 oemResp.length + "bytes.");
7556 }
7557 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7558 returnValue = responseData.length;
7559 }
7560 } else {
7561 CommandException ex = (CommandException) result.exception;
7562 returnValue = ex.getCommandError().ordinal();
7563 if(returnValue > 0) returnValue *= -1;
7564 }
7565 } catch (RuntimeException e) {
7566 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7567 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7568 if(returnValue > 0) returnValue *= -1;
7569 }
7570
7571 return returnValue;
7572 }
7573
7574 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007575 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007576 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007577 try {
7578 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007579 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007580 mApp, phone.getSubId(), "getRadioAccessFamily");
7581 } catch (SecurityException e) {
7582 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7583 throw e;
7584 }
chen xub97461a2018-10-26 14:17:57 -07007585 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007586 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007587 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007588 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007589 final long identity = Binder.clearCallingIdentity();
7590 try {
chen xub97461a2018-10-26 14:17:57 -07007591 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007592 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007593 mApp, phone.getSubId(), "getRadioAccessFamily");
7594 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007595 } finally {
7596 Binder.restoreCallingIdentity(identity);
7597 }
chen xub97461a2018-10-26 14:17:57 -07007598 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007599 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007600
7601 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007602 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007603 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007604 try {
7605 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7606 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007607 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007608 }
7609 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007610 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007611 }
7612 RoleManager rm = mApp.getSystemService(RoleManager.class);
7613 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7614 if (!dialerRoleHolders.contains(callingPackage)) {
7615 throw new SecurityException("App must be the dialer role holder to"
7616 + " upload a call composer pic");
7617 }
7618
7619 Executors.newSingleThreadExecutor().execute(() -> {
7620 ByteArrayOutputStream output = new ByteArrayOutputStream(
7621 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7622 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7623 boolean readUntilEnd = false;
7624 int totalBytesRead = 0;
7625 byte[] buffer = new byte[16 * 1024];
7626 while (true) {
7627 int numRead;
7628 try {
7629 numRead = input.read(buffer);
7630 } catch (IOException e) {
7631 try {
7632 fd.checkError();
7633 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7634 null);
7635 } catch (IOException e1) {
7636 // This means that the other side closed explicitly with an error. If this
7637 // happens, log and ignore.
7638 loge("Remote end of call composer picture pipe closed: " + e1);
7639 }
7640 break;
7641 }
7642 if (numRead == -1) {
7643 readUntilEnd = true;
7644 break;
7645 }
7646 totalBytesRead += numRead;
7647 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7648 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7649 try {
7650 input.close();
7651 } catch (IOException e) {
7652 // ignore
7653 }
7654 break;
7655 }
7656 output.write(buffer, 0, numRead);
7657 }
7658 // Generally, the remote end will close the file descriptors. The only case where we
7659 // close is above, where the picture size is too big.
7660
7661 try {
7662 fd.checkError();
7663 } catch (IOException e) {
7664 loge("Remote end for call composer closed with an error: " + e);
7665 return;
7666 }
7667
Hall Liuaa4211e2021-01-20 15:43:39 -08007668 if (!readUntilEnd) {
7669 loge("Did not finish reading entire image; aborting");
7670 return;
7671 }
Hall Liu82694d52020-12-11 18:22:04 -08007672
Hall Liuaa4211e2021-01-20 15:43:39 -08007673 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7674 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7675 new CallComposerPictureTransfer.Factory() {},
7676 imageData,
7677 (result) -> {
7678 if (result.first != null) {
7679 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7680 Bundle outputResult = new Bundle();
7681 outputResult.putParcelable(
7682 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7683 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7684 outputResult);
7685 } else {
7686 callback.send(result.second, null);
7687 }
7688 }
7689 );
Hall Liu82694d52020-12-11 18:22:04 -08007690 });
7691 }
7692
7693 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007694 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007695 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007696 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007697
7698 final long identity = Binder.clearCallingIdentity();
7699 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007700 ImsManager.getInstance(defaultPhone.getContext(),
7701 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007702 } finally {
7703 Binder.restoreCallingIdentity(identity);
7704 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007705 }
7706
7707 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007708 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007709 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007710 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7711 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007712 return false;
7713 }
Svet Ganovb320e182015-04-16 12:30:10 -07007714
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007715 final long identity = Binder.clearCallingIdentity();
7716 try {
7717 // Check the user preference and the system-level IMS setting. Even if the user has
7718 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7719 // In the long run, we may instead need to check if there exists a connection service
7720 // which can support video calling.
7721 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007722 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007723 return imsManager.isVtEnabledByPlatform()
7724 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7725 && imsManager.isVtEnabledByUser();
7726 } finally {
7727 Binder.restoreCallingIdentity(identity);
7728 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007729 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007730
Andrew Leea1239f22015-03-02 17:44:07 -08007731 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007732 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7733 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007734 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007735 mApp, subId, callingPackage, callingFeatureId,
7736 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007737 return false;
7738 }
7739
7740 final long identity = Binder.clearCallingIdentity();
7741 try {
7742 CarrierConfigManager configManager =
7743 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007744 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007745 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7746 } finally {
7747 Binder.restoreCallingIdentity(identity);
7748 }
Andrew Leea1239f22015-03-02 17:44:07 -08007749 }
7750
7751 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007752 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007753 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007754 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007755 return false;
7756 }
7757
7758 final long identity = Binder.clearCallingIdentity();
7759 try {
7760 CarrierConfigManager configManager =
7761 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007762 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007763 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7764 } finally {
7765 Binder.restoreCallingIdentity(identity);
7766 }
Andrew Leea1239f22015-03-02 17:44:07 -08007767 }
7768
Andrew Lee9431b832015-03-09 18:46:45 -07007769 @Override
7770 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007771 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007772 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007773 }
7774
7775 @Override
7776 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007777 final long identity = Binder.clearCallingIdentity();
7778 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007779 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007780 } finally {
7781 Binder.restoreCallingIdentity(identity);
7782 }
Andrew Lee9431b832015-03-09 18:46:45 -07007783 }
7784
Hall Liuf6668912018-10-31 17:05:23 -07007785 /**
7786 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7787 * support for the feature and device firmware support.
7788 *
7789 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7790 */
7791 @Override
7792 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007793 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007794 final Phone phone = getPhone(subscriptionId);
7795 if (phone == null) {
7796 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7797 return false;
7798 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007799 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007800 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007801 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7802 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007803 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007804 return isCarrierSupported && isDeviceSupported;
7805 } finally {
7806 Binder.restoreCallingIdentity(identity);
7807 }
Hall Liu98187582018-01-22 19:15:32 -08007808 }
7809
Hall Liuf6668912018-10-31 17:05:23 -07007810 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007811 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7812 * RTT setting, will return true if the device and carrier both support RTT.
7813 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007814 */
7815 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007816 final long identity = Binder.clearCallingIdentity();
7817 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007818 boolean isRttSupported = isRttSupported(subscriptionId);
7819 boolean isUserRttSettingOn = Settings.Secure.getInt(
7820 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7821 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7822 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7823 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007824 } finally {
7825 Binder.restoreCallingIdentity(identity);
7826 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007827 }
7828
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007829 @Deprecated
7830 @Override
7831 public String getDeviceId(String callingPackage) {
7832 return getDeviceIdWithFeature(callingPackage, null);
7833 }
7834
Sanket Padawe7310cc72015-01-14 09:53:20 -08007835 /**
7836 * Returns the unique device ID of phone, for example, the IMEI for
7837 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7838 *
7839 * <p>Requires Permission:
7840 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7841 */
7842 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007843 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007844 try {
7845 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7846 } catch (SecurityException se) {
7847 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7848 throw new SecurityException("Package " + callingPackage + " does not belong to "
7849 + Binder.getCallingUid());
7850 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007851 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007852 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007853 return null;
7854 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007855 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007856 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007857 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007858 return null;
7859 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007860
7861 final long identity = Binder.clearCallingIdentity();
7862 try {
7863 return phone.getDeviceId();
7864 } finally {
7865 Binder.restoreCallingIdentity(identity);
7866 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007867 }
7868
Ping Sunc67b7c22016-03-02 19:16:45 +08007869 /**
7870 * {@hide}
7871 * Returns the IMS Registration Status on a particular subid
7872 *
7873 * @param subId
7874 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007875 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007876 Phone phone = getPhone(subId);
7877 if (phone != null) {
7878 return phone.isImsRegistered();
7879 } else {
7880 return false;
7881 }
7882 }
7883
Santos Cordon7a1885b2015-02-03 11:15:19 -08007884 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007885 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007886 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007887 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007888 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007889 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7890 }
7891 final long identity = Binder.clearCallingIdentity();
7892 try {
7893 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7894 } finally {
7895 Binder.restoreCallingIdentity(identity);
7896 }
7897 }
7898
7899 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007900 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007901 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007902 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007903 mApp,
7904 subscriptionId,
7905 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
7906 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007907 final long identity = Binder.clearCallingIdentity();
7908 try {
7909 Phone phone = getPhone(subscriptionId);
7910 if (phone == null) {
7911 return null;
7912 }
7913 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7914 } finally {
7915 Binder.restoreCallingIdentity(identity);
7916 }
7917 }
7918
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007919 /**
7920 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007921 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007922 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007923 final long identity = Binder.clearCallingIdentity();
7924 try {
7925 Phone phone = getPhone(subId);
7926 if (phone != null) {
7927 return phone.isWifiCallingEnabled();
7928 } else {
7929 return false;
7930 }
7931 } finally {
7932 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007933 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007934 }
7935
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007936 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007937 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007938 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007939 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007940 final long identity = Binder.clearCallingIdentity();
7941 try {
7942 Phone phone = getPhone(subId);
7943 if (phone != null) {
7944 return phone.isVideoEnabled();
7945 } else {
7946 return false;
7947 }
7948 } finally {
7949 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007950 }
7951 }
7952
7953 /**
7954 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7955 * defined in {@link ImsRegistrationImplBase}.
7956 */
7957 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007958 final long identity = Binder.clearCallingIdentity();
7959 try {
7960 Phone phone = getPhone(subId);
7961 if (phone != null) {
7962 return phone.getImsRegistrationTech();
7963 } else {
7964 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7965 }
7966 } finally {
7967 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007968 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007969 }
7970
Stuart Scott8eef64f2015-04-08 15:13:54 -07007971 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007972 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007973 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007974 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7975 return;
7976 }
Kai Shif70f46f2021-03-03 13:59:46 -08007977 Phone defaultPhone = getDefaultPhone();
7978 if (defaultPhone != null) {
7979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7980 mApp, getDefaultPhone().getSubId(), "factoryReset");
7981 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007982 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007983
Svet Ganovcc087f82015-05-12 20:35:54 -07007984 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007985 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7986 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007987 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007988 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007989 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007990 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007991 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007992 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007993 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007994 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007995 // There has been issues when Sms raw table somehow stores orphan
7996 // fragments. They lead to garbled message when new fragments come
7997 // in and combined with those stale ones. In case this happens again,
7998 // user can reset all network settings which will clean up this table.
7999 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008000 // Clean up IMS settings as well here.
8001 int slotId = getSlotIndex(subId);
8002 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8003 ImsManager.getInstance(mApp, slotId).factoryReset();
8004 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008005
Kai Shif70f46f2021-03-03 13:59:46 -08008006 if (defaultPhone == null) {
8007 return;
8008 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008009 // Erase modem config if erase modem on network setting is enabled.
8010 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8011 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8012 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008013 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008014 }
Kai Shif70f46f2021-03-03 13:59:46 -08008015
8016 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008017 } finally {
8018 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008019 }
8020 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008021
SongFerngWangfd89b102021-05-27 22:44:54 +08008022 @VisibleForTesting
8023 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8024 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8025 return;
8026 }
8027 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8028 RILConstants.PREFERRED_NETWORK_MODE);
8029 SubscriptionManager.setSubscriptionProperty(subId,
8030 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8031 "user=" + defaultNetworkType);
8032 phone.loadAllowedNetworksFromSubscriptionDatabase();
8033 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8034 defaultNetworkType, null);
8035 }
8036
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008037 private void cleanUpSmsRawTable(Context context) {
8038 ContentResolver resolver = context.getContentResolver();
8039 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8040 resolver.delete(uri, null, null);
8041 }
8042
Narayan Kamath1c496c22015-04-16 14:40:19 +01008043 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008044 public String getSimLocaleForSubscriber(int subId) {
8045 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
8046 final Phone phone = getPhone(subId);
8047 if (phone == null) {
8048 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008049 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008050 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008051 final long identity = Binder.clearCallingIdentity();
8052 try {
Jack Yu285100e2022-12-02 22:48:35 -08008053 SubscriptionInfo info;
8054 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008055 info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
Jack Yu285100e2022-12-02 22:48:35 -08008056 phone.getContext().getOpPackageName(),
8057 phone.getContext().getAttributionTag());
8058 if (info == null) {
8059 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8060 return null;
8061 }
8062 } else {
8063 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
8064 phone.getContext().getOpPackageName(),
8065 phone.getContext().getAttributionTag());
8066 if (info == null) {
8067 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8068 return null;
8069 }
chen xu6291c472019-02-04 12:55:53 -08008070 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008071 // Try and fetch the locale from the carrier properties or from the SIM language
8072 // preferences (EF-PL and EF-LI)...
8073 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008074 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008075 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8076 if (localeFromDefaultSim != null) {
8077 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8078 if (DBG) log("Using locale from subId: " + subId + " locale: "
8079 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008080 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008081 } else {
8082 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008083 }
8084 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008085
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008086 // The SIM language preferences only store a language (e.g. fr = French), not an
8087 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8088 // the SIM and carrier preferences does not include a country we add the country
8089 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008090 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008091 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008092 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008093 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008094 }
8095
8096 if (DBG) log("No locale found - returning null");
8097 return null;
8098 } finally {
8099 Binder.restoreCallingIdentity(identity);
8100 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008101 }
8102
tom hsu0b59d292022-09-29 23:49:21 +08008103 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008104 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008105 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008106 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008107 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008108 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8109 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008110 Locale.forLanguageTag(localeTag).getCountry())) {
8111 return localeTag;
8112 }
8113 }
8114 return inputLocale.toLanguageTag();
8115 }
8116
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008117 /**
8118 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8119 */
8120 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08008121 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008122 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Jack Yu285100e2022-12-02 22:48:35 -08008123 mApp.getOpPackageName(), mApp.getAttributionTag());
8124 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008125 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08008126 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008127 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008128
Gary Jian3aa9a762022-01-24 16:41:19 +08008129 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8130 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008131
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008132 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008133 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8134 * representing the state of the modem.
8135 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008136 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8137 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008138 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008139 */
8140 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008141 public void requestModemActivityInfo(ResultReceiver result) {
8142 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008143 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008144
8145 final long identity = Binder.clearCallingIdentity();
8146 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008147 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008148 } finally {
8149 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008150 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008151 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008152
Gary Jian76280a42022-12-07 16:18:33 +08008153 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008154 // less than total activity duration.
8155 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8156 if (info == null) {
8157 return false;
8158 }
8159 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008160 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008161 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8162
Hall Liu49656c02020-10-09 19:00:11 -07008163 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8164
Siddharth Rayb8114062018-06-17 15:02:38 -07008165 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008166 && (info.getSleepTimeMillis() <= activityDurationMs)
8167 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008168 }
8169
Gary Jian3aa9a762022-01-24 16:41:19 +08008170 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8171 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8172 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8173 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8174
8175 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8176 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8177 }
8178
8179 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8180 mLastModemActivityInfo.setReceiveTimeMillis(
8181 rat,
8182 freq,
8183 info.getReceiveTimeMillis(rat, freq)
8184 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8185 }
8186
8187 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8188 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8189 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8190 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8191
8192 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8193 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8194 }
8195 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8196 mLastModemActivityInfo.setReceiveTimeMillis(
8197 rat,
8198 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8199 }
8200
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008201 /**
8202 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8203 * @param info recent ModemActivityInfo
8204 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008205 private void mergeModemActivityInfo(ModemActivityInfo info) {
8206 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008207 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008208 boolean matched;
8209 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8210 matched = false;
8211 int rat = info.getSpecificInfoRat(i);
8212 int freq = info.getSpecificInfoFrequencyRange(i);
8213 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8214 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8215 //if it already exists
8216 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8217 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8218 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8219 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8220 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8221 updateLastModemActivityInfo(info, rat, freq);
8222 matched = true;
8223 }
8224 } else {
8225 updateLastModemActivityInfo(info, rat);
8226 matched = true;
8227 }
8228 }
8229 }
8230
8231 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008232 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008233 new ActivityStatsTechSpecificInfo(
8234 rat,
8235 freq,
8236 info.getTransmitTimeMillis(rat, freq),
8237 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008238 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008239 }
8240 }
8241 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8242 mLastModemActivitySpecificInfo =
8243 new ActivityStatsTechSpecificInfo[merged.size()];
8244 merged.toArray(mLastModemActivitySpecificInfo);
8245
8246 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8247 mLastModemActivityInfo.setSleepTimeMillis(
8248 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008249 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008250 mLastModemActivityInfo.setIdleTimeMillis(
8251 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008252 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008253
8254 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008255 new ModemActivityInfo(
8256 mLastModemActivityInfo.getTimestampMillis(),
8257 mLastModemActivityInfo.getSleepTimeMillis(),
8258 mLastModemActivityInfo.getIdleTimeMillis(),
8259 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008260 }
8261
8262 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8263 ActivityStatsTechSpecificInfo[] info) {
8264 int infoSize = info.length;
8265 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8266 for (int i = 0; i < infoSize; i++) {
8267 ret[i] = new ActivityStatsTechSpecificInfo(
8268 info[i].getRat(), info[i].getFrequencyRange(),
8269 info[i].getTransmitTimeMillis(),
8270 (int) info[i].getReceiveTimeMillis());
8271 }
8272 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008273 }
8274
Jack Yu85bd38a2015-11-09 11:34:32 -08008275 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008276 * Returns the service state information on specified subscription.
8277 */
8278 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008279 public ServiceState getServiceStateForSubscriber(int subId,
8280 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8281 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008282 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008283 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008284 return null;
8285 }
8286
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008287 boolean hasFinePermission = false;
8288 boolean hasCoarsePermission = false;
8289 if (!renounceFineLocationAccess) {
8290 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8291 LocationAccessPolicy.checkLocationPermission(mApp,
8292 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8293 .setCallingPackage(callingPackage)
8294 .setCallingFeatureId(callingFeatureId)
8295 .setCallingPid(Binder.getCallingPid())
8296 .setCallingUid(Binder.getCallingUid())
8297 .setMethod("getServiceStateForSubscriber")
8298 .setLogAsInfo(true)
8299 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8300 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8301 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8302 .build());
8303 hasFinePermission =
8304 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8305 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008306
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008307 if (!renounceCoarseLocationAccess) {
8308 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8309 LocationAccessPolicy.checkLocationPermission(mApp,
8310 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8311 .setCallingPackage(callingPackage)
8312 .setCallingFeatureId(callingFeatureId)
8313 .setCallingPid(Binder.getCallingPid())
8314 .setCallingUid(Binder.getCallingUid())
8315 .setMethod("getServiceStateForSubscriber")
8316 .setLogAsInfo(true)
8317 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8318 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8319 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8320 .build());
8321 hasCoarsePermission =
8322 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8323 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008324
Jack Yu479f40e2020-10-27 21:29:25 -07008325 final Phone phone = getPhone(subId);
8326 if (phone == null) {
8327 return null;
8328 }
8329
Jordan Liu0f2bc442020-11-18 16:47:37 -08008330 final long identity = Binder.clearCallingIdentity();
8331
Jack Yu479f40e2020-10-27 21:29:25 -07008332 boolean isCallingPackageDataService = phone.getDataServicePackages()
8333 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008334 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008335 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008336 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008337 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08008338 .getSubscriptionInfoInternal(subId);
8339 if (subInfo == null || !subInfo.isActive()) {
8340 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8341 + "subId=" + subId);
8342 return null;
8343 }
8344 } else {
8345 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8346 callingFeatureId)) {
8347 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8348 + "subId=" + subId);
8349 return null;
8350 }
Jordan Liuc437b192020-08-17 10:59:12 -07008351 }
8352
Hall Liuf19c44f2018-11-27 14:38:17 -08008353 ServiceState ss = phone.getServiceState();
8354
8355 // Scrub out the location info in ServiceState depending on what level of access
8356 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008357 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008358 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8359 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008360 } finally {
8361 Binder.restoreCallingIdentity(identity);
8362 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008363 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008364
8365 /**
8366 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8367 *
8368 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8369 * voicemail ringtone.
8370 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8371 * PhoneAccount.
8372 */
8373 @Override
8374 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008375 final long identity = Binder.clearCallingIdentity();
8376 try {
8377 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8378 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008379 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008380 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008381
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008382 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8383 } finally {
8384 Binder.restoreCallingIdentity(identity);
8385 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008386 }
8387
8388 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008389 * Sets the per-account voicemail ringtone.
8390 *
8391 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8392 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8393 *
8394 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8395 * voicemail ringtone.
8396 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8397 * PhoneAccount.
8398 */
8399 @Override
8400 public void setVoicemailRingtoneUri(String callingPackage,
8401 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008402 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008403 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008404 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8405 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8407 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8408 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008409 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008410
8411 final long identity = Binder.clearCallingIdentity();
8412 try {
8413 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8414 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008415 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008416 }
8417 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8418 } finally {
8419 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008420 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008421 }
8422
8423 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008424 * Returns whether vibration is set for voicemail notification in Phone settings.
8425 *
8426 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8427 * voicemail vibration setting.
8428 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8429 */
8430 @Override
8431 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008432 final long identity = Binder.clearCallingIdentity();
8433 try {
8434 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8435 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008436 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008437 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008439 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8440 } finally {
8441 Binder.restoreCallingIdentity(identity);
8442 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008443 }
8444
Youhan Wange64578a2016-05-02 15:32:42 -07008445 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008446 * Sets the per-account voicemail vibration.
8447 *
8448 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8449 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8450 *
8451 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8452 * voicemail vibration setting.
8453 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8454 * specific PhoneAccount.
8455 */
8456 @Override
8457 public void setVoicemailVibrationEnabled(String callingPackage,
8458 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008459 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008460 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008461 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8462 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008463 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8464 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8465 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008466 }
8467
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008468 final long identity = Binder.clearCallingIdentity();
8469 try {
8470 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8471 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008472 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008473 }
8474 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8475 } finally {
8476 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008477 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008478 }
8479
8480 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008481 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8482 *
8483 * @throws SecurityException if the caller does not have the required permission
8484 */
arunvoddud7401012022-12-15 16:08:12 +00008485 @VisibleForTesting
8486 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008487 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008488 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008489 }
8490
8491 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008492 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8493 * permission.
8494 *
8495 * @throws SecurityException if the caller does not have the required permission
8496 */
8497 private void enforceSendSmsPermission() {
8498 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8499 }
8500
8501 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008502 * Make sure either called from same process as self (phone) or IPC caller has interact across
8503 * users permission.
8504 *
8505 * @throws SecurityException if the caller does not have the required permission
8506 */
8507 private void enforceInteractAcrossUsersPermission(String message) {
8508 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8509 }
8510
8511 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008512 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008513 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008514 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008515 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008516 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008517 final long identity = Binder.clearCallingIdentity();
8518 try {
8519 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008520 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008521 if (componentName == null) {
8522 throw new SecurityException(
8523 "Caller not current active visual voicemail package[null]");
8524 }
8525 String vvmPackage = componentName.getPackageName();
8526 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008527 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008528 }
8529 } finally {
8530 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008531 }
8532 }
8533
8534 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008535 * Return the application ID for the app type.
8536 *
8537 * @param subId the subscription ID that this request applies to.
8538 * @param appType the uicc app type.
8539 * @return Application ID for specificied app type, or null if no uicc.
8540 */
8541 @Override
8542 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008543 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008544 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008545
8546 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008547 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008548 if (phone == null) {
8549 return null;
8550 }
8551 String aid = null;
8552 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008553 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008554 .getApplicationByType(appType).getAid();
8555 } catch (Exception e) {
8556 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8557 }
8558 return aid;
8559 } finally {
8560 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008561 }
Youhan Wange64578a2016-05-02 15:32:42 -07008562 }
8563
Youhan Wang4001d252016-05-11 10:29:41 -07008564 /**
8565 * Return the Electronic Serial Number.
8566 *
8567 * @param subId the subscription ID that this request applies to.
8568 * @return ESN or null if error.
8569 */
8570 @Override
8571 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008572 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008573 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008574
8575 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008576 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008577 if (phone == null) {
8578 return null;
8579 }
8580 String esn = null;
8581 try {
8582 esn = phone.getEsn();
8583 } catch (Exception e) {
8584 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8585 }
8586 return esn;
8587 } finally {
8588 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008589 }
Youhan Wang4001d252016-05-11 10:29:41 -07008590 }
8591
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008592 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008593 * Return the Preferred Roaming List Version.
8594 *
8595 * @param subId the subscription ID that this request applies to.
8596 * @return PRLVersion or null if error.
8597 */
8598 @Override
8599 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008600 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008601 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008602
8603 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008604 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008605 if (phone == null) {
8606 return null;
8607 }
8608 String cdmaPrlVersion = null;
8609 try {
8610 cdmaPrlVersion = phone.getCdmaPrlVersion();
8611 } catch (Exception e) {
8612 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8613 }
8614 return cdmaPrlVersion;
8615 } finally {
8616 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008617 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008618 }
8619
8620 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008621 * Get snapshot of Telephony histograms
8622 * @return List of Telephony histograms
8623 * @hide
8624 */
8625 @Override
8626 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8628 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008629
8630 final long identity = Binder.clearCallingIdentity();
8631 try {
8632 return RIL.getTelephonyRILTimingHistograms();
8633 } finally {
8634 Binder.restoreCallingIdentity(identity);
8635 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008636 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008637
8638 /**
8639 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008640 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8641 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008642 * Require system privileges. In the future we may add this to carrier APIs.
8643 *
Michele Berionne482f8202018-11-27 18:57:59 -08008644 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008645 */
8646 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008647 @TelephonyManager.SetCarrierRestrictionResult
8648 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008649 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008650 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008651
Michele Berionne482f8202018-11-27 18:57:59 -08008652 if (carrierRestrictionRules == null) {
8653 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008654 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008655
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008656 final long identity = Binder.clearCallingIdentity();
8657 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008658 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008659 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008660 } finally {
8661 Binder.restoreCallingIdentity(identity);
8662 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008663 }
8664
8665 /**
8666 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008667 * Get the allowed carrier list and the excluded carrier list, including the priority between
8668 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008669 * Require system privileges. In the future we may add this to carrier APIs.
8670 *
Michele Berionne482f8202018-11-27 18:57:59 -08008671 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008672 */
8673 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008674 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008675 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008676 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008677
8678 final long identity = Binder.clearCallingIdentity();
8679 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008680 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8681 if (response instanceof CarrierRestrictionRules) {
8682 return (CarrierRestrictionRules) response;
8683 }
8684 // Response is an Exception of some kind,
8685 // which is signalled to the user as a NULL retval
8686 return null;
8687 } catch (Exception e) {
8688 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8689 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008690 } finally {
8691 Binder.restoreCallingIdentity(identity);
8692 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008693 }
8694
fionaxu59545b42016-05-25 15:53:37 -07008695 /**
arunvoddud7401012022-12-15 16:08:12 +00008696 * Fetches the carrier restriction status of the device and sends the status to the caller
8697 * through the callback.
8698 *
8699 * @param callback The callback that will be used to send the result.
8700 * @throws SecurityException if the caller does not have the required permission/privileges or
8701 * the caller is not allowlisted.
8702 */
8703 @Override
8704 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
8705 enforceReadPermission("getCarrierRestrictionStatus");
8706 int carrierId = validateCallerAndGetCarrierId(packageName);
8707 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
8708 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
8709 throw new SecurityException("Not an authorized caller");
8710 }
8711 final long identity = Binder.clearCallingIdentity();
8712 try {
8713 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
8714 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
8715 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
8716 } finally {
8717 Binder.restoreCallingIdentity(identity);
8718 }
8719 }
8720
8721 @VisibleForTesting
8722 public int validateCallerAndGetCarrierId(String packageName) {
8723 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8724 return allowListInfo.validateCallerAndGetCarrierId(packageName);
8725 }
8726
8727 /**
fionaxu59545b42016-05-25 15:53:37 -07008728 * Action set from carrier signalling broadcast receivers to enable/disable radio
8729 * @param subId the subscription ID that this action applies to.
8730 * @param enabled control enable or disable radio.
8731 * {@hide}
8732 */
8733 @Override
8734 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8735 enforceModifyPermission();
8736 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008737
8738 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008739 if (phone == null) {
8740 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8741 return;
8742 }
8743 try {
8744 phone.carrierActionSetRadioEnabled(enabled);
8745 } catch (Exception e) {
8746 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008747 } finally {
8748 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008749 }
8750 }
8751
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008752 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008753 * Enable or disable Voice over NR (VoNR)
8754 * @param subId the subscription ID that this action applies to.
8755 * @param enabled enable or disable VoNR.
8756 * @return operation result.
8757 */
8758 @Override
8759 public int setVoNrEnabled(int subId, boolean enabled) {
8760 enforceModifyPermission();
8761 final Phone phone = getPhone(subId);
8762
8763 final long identity = Binder.clearCallingIdentity();
8764 if (phone == null) {
8765 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8766 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8767 }
8768
8769 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8770 try {
8771 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8772 workSource);
8773 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008774
8775 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8776 if (DBG) {
8777 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8778 }
8779 SubscriptionManager.setSubscriptionProperty(
8780 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8781 (enabled ? "1" : "0"));
8782 }
8783
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008784 return result;
8785 } finally {
8786 Binder.restoreCallingIdentity(identity);
8787 }
8788 }
8789
8790 /**
8791 * Is voice over NR enabled
8792 * @return true if VoNR is enabled else false
8793 */
8794 @Override
8795 public boolean isVoNrEnabled(int subId) {
8796 enforceReadPrivilegedPermission("isVoNrEnabled");
8797 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8798 final long identity = Binder.clearCallingIdentity();
8799 try {
8800 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8801 null, subId, workSource);
8802 if (DBG) log("isVoNrEnabled: " + isEnabled);
8803 return isEnabled;
8804 } finally {
8805 Binder.restoreCallingIdentity(identity);
8806 }
8807 }
8808
8809 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008810 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8811 * network status based on which carrier apps could apply actions accordingly,
8812 * enable/disable default url handler for example.
8813 *
8814 * @param subId the subscription ID that this action applies to.
8815 * @param report control start/stop reporting the default network status.
8816 * {@hide}
8817 */
8818 @Override
8819 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8820 enforceModifyPermission();
8821 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008822
8823 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008824 if (phone == null) {
8825 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8826 return;
8827 }
8828 try {
8829 phone.carrierActionReportDefaultNetworkStatus(report);
8830 } catch (Exception e) {
8831 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008832 } finally {
8833 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008834 }
8835 }
8836
8837 /**
fionaxud9622282017-07-17 17:51:30 -07008838 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8839 * @param subId the subscription ID that this action applies to.
8840 * {@hide}
8841 */
8842 @Override
8843 public void carrierActionResetAll(int subId) {
8844 enforceModifyPermission();
8845 final Phone phone = getPhone(subId);
8846 if (phone == null) {
8847 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8848 return;
8849 }
8850 try {
8851 phone.carrierActionResetAll();
8852 } catch (Exception e) {
8853 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8854 }
8855 }
8856
8857 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008858 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8859 * bug report is being generated.
8860 */
8861 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008862 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008863 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8864 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008865 writer.println("Permission Denial: can't dump Phone from pid="
8866 + Binder.getCallingPid()
8867 + ", uid=" + Binder.getCallingUid()
8868 + "without permission "
8869 + android.Manifest.permission.DUMP);
8870 return;
8871 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008872 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008873 }
Jack Yueb89b242016-06-22 13:27:47 -07008874
Brad Ebingerdac2f002018-04-03 15:17:52 -07008875 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008876 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8877 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8878 @NonNull String[] args) {
8879 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8880 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008881 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008882 }
8883
Jack Yueb89b242016-06-22 13:27:47 -07008884 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008885 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008886 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008887 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008888 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008889 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008890 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008891 */
8892 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008893 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008894 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008895 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8896 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8897 try {
8898 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008899 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008900 } catch (SecurityException se) {
8901 enforceModifyPermission();
8902 }
8903 } else {
8904 enforceModifyPermission();
8905 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008906
8907 final long identity = Binder.clearCallingIdentity();
8908 try {
8909 Phone phone = getPhone(subId);
8910 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008911 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8912 phone.carrierActionSetMeteredApnsEnabled(enabled);
8913 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008914 phone.getDataSettingsManager().setDataEnabled(
8915 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008916 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008917 }
8918 } finally {
8919 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008920 }
8921 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008922
8923 /**
8924 * Get Client request stats
8925 * @return List of Client Request Stats
8926 * @hide
8927 */
8928 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008929 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8930 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008931 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008932 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008933 return null;
8934 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008935 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008936
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008937 final long identity = Binder.clearCallingIdentity();
8938 try {
8939 if (phone != null) {
8940 return phone.getClientRequestStats();
8941 }
8942
8943 return null;
8944 } finally {
8945 Binder.restoreCallingIdentity(identity);
8946 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008947 }
8948
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008949 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008950 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008951 if (uid == Process.ROOT_UID && packageName == null) {
8952 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8953 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8954 // exception. ROOT_UID seems not to have a valid package name returned by
8955 // PackageManager, so just fake it here to avoid issues when running telephony shell
8956 // commands that plumb through the RIL as root, like so:
8957 // $ adb root
8958 // $ adb shell cmd phone ...
8959 packageName = "root";
8960 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008961 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008962 }
Jack Yueb4124c2017-02-16 15:32:43 -08008963
8964 /**
Grace Chen70990072017-03-24 17:21:30 -07008965 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008966 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008967 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008968 * @param state State of SIM (power down, power up, pass through)
8969 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8970 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8971 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008972 *
8973 **/
8974 @Override
Grace Chen70990072017-03-24 17:21:30 -07008975 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008976 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008977 Phone phone = PhoneFactory.getPhone(slotIndex);
8978
vagdeviaf9a5b92018-08-15 16:01:53 -07008979 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8980
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008981 final long identity = Binder.clearCallingIdentity();
8982 try {
8983 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008984 phone.setSimPowerState(state, null, workSource);
8985 }
8986 } finally {
8987 Binder.restoreCallingIdentity(identity);
8988 }
8989 }
8990
8991 /**
8992 * Set SIM card power state.
8993 *
8994 * @param slotIndex SIM slot id.
8995 * @param state State of SIM (power down, power up, pass through)
8996 * @param callback callback to trigger after success or failure
8997 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8998 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8999 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9000 *
9001 **/
9002 @Override
9003 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9004 IIntegerConsumer callback) {
9005 enforceModifyPermission();
9006 Phone phone = PhoneFactory.getPhone(slotIndex);
9007
9008 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9009
9010 final long identity = Binder.clearCallingIdentity();
9011 try {
9012 if (phone != null) {
9013 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9014 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009015 }
9016 } finally {
9017 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009018 }
9019 }
Shuo Qiandd210312017-04-12 22:11:33 +00009020
Tyler Gunn65d45c22017-06-05 11:22:26 -07009021 private boolean isUssdApiAllowed(int subId) {
9022 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009023 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009024 if (configManager == null) {
9025 return false;
9026 }
9027 PersistableBundle pb = configManager.getConfigForSubId(subId);
9028 if (pb == null) {
9029 return false;
9030 }
9031 return pb.getBoolean(
9032 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9033 }
9034
Shuo Qiandd210312017-04-12 22:11:33 +00009035 /**
9036 * Check if phone is in emergency callback mode
9037 * @return true if phone is in emergency callback mode
9038 * @param subId sub id
9039 */
goneil9c5f4872017-12-05 14:07:56 -08009040 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009041 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009042 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00009043 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009044
9045 final long identity = Binder.clearCallingIdentity();
9046 try {
9047 if (phone != null) {
9048 return phone.isInEcm();
9049 } else {
9050 return false;
9051 }
9052 } finally {
9053 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009054 }
9055 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009056
9057 /**
9058 * Get the current signal strength information for the given subscription.
9059 * Because this information is not updated when the device is in a low power state
9060 * it should not be relied-upon to be current.
9061 * @param subId Subscription index
9062 * @return the most recent cached signal strength info from the modem
9063 */
9064 @Override
9065 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009066 final long identity = Binder.clearCallingIdentity();
9067 try {
9068 Phone p = getPhone(subId);
9069 if (p == null) {
9070 return null;
9071 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009072
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009073 return p.getSignalStrength();
9074 } finally {
9075 Binder.restoreCallingIdentity(identity);
9076 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009077 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009078
Pengquan Meng77b7f132018-08-22 14:49:57 -07009079 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009080 * Get the current modem radio state for the given slot.
9081 * @param slotIndex slot index.
9082 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009083 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009084 * @return the current radio power state from the modem
9085 */
9086 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009087 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009088 Phone phone = PhoneFactory.getPhone(slotIndex);
9089 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009090 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9091 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009092 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9093 }
9094
9095 final long identity = Binder.clearCallingIdentity();
9096 try {
9097 return phone.getRadioPowerState();
9098 } finally {
9099 Binder.restoreCallingIdentity(identity);
9100 }
9101 }
9102 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9103 }
9104
9105 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009106 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9107 *
9108 * <p>Requires one of the following permissions:
9109 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009110 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009111 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9112 * privileges.
9113 *
9114 * @param subId subscription id
9115 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9116 * {@code false}.
9117 */
9118 @Override
9119 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009120 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009121 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009122 try {
9123 mApp.enforceCallingOrSelfPermission(
9124 android.Manifest.permission.ACCESS_NETWORK_STATE,
9125 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009126 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009127 mApp.enforceCallingOrSelfPermission(
9128 permission.READ_BASIC_PHONE_STATE, functionName);
9129 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009130 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009131 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009132 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009133 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009134
Pengquan Menga1bb6272018-09-06 09:59:22 -07009135 boolean isEnabled = false;
9136 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009137 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009138 Phone phone = getPhone(subId);
9139 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009140 } finally {
9141 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009142 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009143 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009144 }
9145
9146
9147 /**
9148 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9149 *
9150 * <p> Requires permission:
9151 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9152 * privileges.
9153 *
9154 * @param subId subscription id
9155 * @param isEnabled {@code true} means enable, {@code false} means disable.
9156 */
9157 @Override
9158 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9160 mApp, subId, "setDataRoamingEnabled");
9161
Pengquan Menga1bb6272018-09-06 09:59:22 -07009162 final long identity = Binder.clearCallingIdentity();
9163 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009164 Phone phone = getPhone(subId);
9165 if (phone != null) {
9166 phone.setDataRoamingEnabled(isEnabled);
9167 }
9168 } finally {
9169 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009170 }
9171 }
9172
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009173 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009174 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009175 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009176 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009177 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009178
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009179 boolean isAllowed = true;
9180 final long identity = Binder.clearCallingIdentity();
9181 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009182 Phone phone = getPhone(subId);
9183 if (phone != null) {
9184 isAllowed = phone.isCspPlmnEnabled();
9185 }
9186 } finally {
9187 Binder.restoreCallingIdentity(identity);
9188 }
9189 return isAllowed;
9190 }
9191
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009192 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9193 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009194 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009195 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009196 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009197 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9198 if (phone == null) {
9199 return false;
9200 }
9201 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9202 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9203 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009204 }
9205
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009206 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009207 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009208 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009209 mApp.getSystemService(AppOpsManager.class)
9210 .checkPackage(Binder.getCallingUid(), callingPackage);
9211
Jordan Liu1e142fc2019-04-22 15:10:43 -07009212 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009213 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009214 try {
9215 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009216 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009217 } catch (SecurityException e) {
9218 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9219 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009220 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009221 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009222 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009223 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009224 }
sandeepjsb6c87872021-09-27 15:34:44 +00009225 // checking compatibility, if calling app's target SDK is T and beyond.
9226 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9227 Binder.getCallingUid())) {
9228 isIccIdAccessRestricted = true;
9229 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009230 final long identity = Binder.clearCallingIdentity();
9231 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009232 UiccController uiccController = UiccController.getInstance();
9233 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009234 if (hasReadPermission) {
9235 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009236 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009237
9238 // Remove private info if the caller doesn't have access
9239 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9240 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009241 //setting the value after compatibility check
9242 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009243 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9244 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009245 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009246 if (card == null) {
9247 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009248 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009249 continue;
9250 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009251 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9252 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009253 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009254 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009255 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009256 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9257 for (UiccPortInfo portInfo : portInfos) {
9258 UiccPort port = uiccController.getUiccPortForSlot(
9259 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9260 if (port == null) {
9261 // assume no access if port is null
9262 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9263 continue;
9264 }
9265 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9266 uiccPortInfos.add(portInfo);
9267 } else {
9268 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9269 }
9270 }
9271 filteredInfos.add(new UiccCardInfo(
9272 cardInfo.isEuicc(),
9273 cardInfo.getCardId(),
9274 null,
9275 cardInfo.getPhysicalSlotIndex(),
9276 cardInfo.isRemovable(),
9277 cardInfo.isMultipleEnabledProfilesSupported(),
9278 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009279 }
9280 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009281 } finally {
9282 Binder.restoreCallingIdentity(identity);
9283 }
9284 }
9285
sandeepjsb6c87872021-09-27 15:34:44 +00009286 /**
9287 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9288 * generally private and require carrier privileges to view.
9289 *
9290 * @hide
9291 */
9292 @NonNull
9293 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9294 List<UiccPortInfo> portinfo = new ArrayList<>();
9295 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9296 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9297 }
9298 return new UiccCardInfo(
9299 cardInfo.isEuicc(),
9300 cardInfo.getCardId(),
9301 null,
9302 cardInfo.getPhysicalSlotIndex(),
9303 cardInfo.isRemovable(),
9304 cardInfo.isMultipleEnabledProfilesSupported(),
9305 portinfo
9306 );
9307 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009308
sandeepjsb6c87872021-09-27 15:34:44 +00009309 /**
9310 * @hide
9311 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9312 * These values are generally private and require carrier privileges to view.
9313 */
9314 @NonNull
9315 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9316 return new UiccPortInfo(
9317 UiccPortInfo.ICCID_REDACTED,
9318 portInfo.getPortIndex(),
9319 portInfo.getLogicalSlotIndex(),
9320 portInfo.isActive()
9321 );
9322 }
9323 @Override
9324 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009325 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009326 mApp.getSystemService(AppOpsManager.class)
9327 .checkPackage(Binder.getCallingUid(), callingPackage);
9328
sandeepjsb6c87872021-09-27 15:34:44 +00009329 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009330
Aman Guptaf3c90b32022-03-17 04:54:16 +00009331 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9332 // we are reading iccId which is PII data.
9333 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009334
9335 // checking compatibility, if calling app's target SDK is T and beyond.
9336 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9337 Binder.getCallingUid())) {
9338 isLogicalSlotAccessRestricted = true;
9339 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009340 final long identity = Binder.clearCallingIdentity();
9341 try {
9342 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009343 if (slots == null || slots.length == 0) {
9344 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009345 return null;
9346 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009347 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9348 for (int i = 0; i < slots.length; i++) {
9349 UiccSlot slot = slots[i];
9350 if (slot == null) {
9351 continue;
9352 }
9353
Jordan Liu7be7e652019-05-06 18:55:02 +00009354 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009355 UiccCard card = slot.getUiccCard();
9356 if (card != null) {
9357 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009358 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009359 cardId = slot.getEid();
9360 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009361 // If cardId is null, use iccId of default port as cardId.
9362 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009363 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009364 }
9365
Jordan Liu857451f2019-05-09 16:35:35 -07009366 if (cardId != null) {
9367 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9368 // if cardId is an EID, it's all digits so this is fine
9369 cardId = IccUtils.stripTrailingFs(cardId);
9370 }
9371
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009372 int cardState = 0;
9373 switch (slot.getCardState()) {
9374 case CARDSTATE_ABSENT:
9375 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9376 break;
9377 case CARDSTATE_PRESENT:
9378 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9379 break;
9380 case CARDSTATE_ERROR:
9381 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9382 break;
9383 case CARDSTATE_RESTRICTED:
9384 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9385 break;
9386 default:
9387 break;
9388
9389 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009390 List<UiccPortInfo> portInfos = new ArrayList<>();
9391 int[] portIndexes = slot.getPortList();
9392 for (int portIdx : portIndexes) {
9393 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009394 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009395 portInfos.add(new UiccPortInfo(iccId, portIdx,
9396 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009397 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009398 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009399 slot.isEuicc(),
9400 cardId,
9401 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009402 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009403 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009404 //setting the value after compatibility check
9405 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009406 }
9407 return infos;
9408 } finally {
9409 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009410 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009411 }
9412
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009413 /* Returns null if doesn't have read permission or carrier privilege access. */
9414 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9415 boolean hasReadPermission) {
9416 String iccId = slot.getIccId(portIndex);
9417 if (hasReadPermission) { // if has read permission
9418 return iccId;
9419 } else {
9420 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9421 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9422 // if no read permission, checking carrier privilege access
9423 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9424 return iccId;
9425 }
9426 }
9427 }
9428 // No read permission or carrier privilege access.
9429 return UiccPortInfo.ICCID_REDACTED;
9430 }
9431
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009432 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009433 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009434 public boolean switchSlots(int[] physicalSlots) {
9435 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009436
9437 final long identity = Binder.clearCallingIdentity();
9438 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009439 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9440 for (int i = 0; i < physicalSlots.length; i++) {
9441 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9442 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9443 physicalSlots[i], i));
9444 }
9445 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009446 } finally {
9447 Binder.restoreCallingIdentity(identity);
9448 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009449 }
Jack Yu4c988042018-02-27 15:30:01 -08009450
9451 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009452 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9453 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9454 enforceModifyPermission();
9455
9456 final long identity = Binder.clearCallingIdentity();
9457 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009458 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009459 } finally {
9460 Binder.restoreCallingIdentity(identity);
9461 }
9462 }
9463
9464 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009465 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009466 final long identity = Binder.clearCallingIdentity();
9467 try {
9468 return UiccController.getInstance().getCardIdForDefaultEuicc();
9469 } finally {
9470 Binder.restoreCallingIdentity(identity);
9471 }
9472 }
9473
Pengquan Meng85728fb2018-03-12 16:31:21 -07009474 /**
goneil47ffb6e2018-04-06 15:40:58 -07009475 * A test API to reload the UICC profile.
9476 *
9477 * <p>Requires that the calling app has permission
9478 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9479 * @hide
9480 */
9481 @Override
9482 public void refreshUiccProfile(int subId) {
9483 enforceModifyPermission();
9484
9485 final long identity = Binder.clearCallingIdentity();
9486 try {
9487 Phone phone = getPhone(subId);
9488 if (phone == null) {
9489 return;
9490 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009491 UiccPort uiccPort = phone.getUiccPort();
9492 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009493 return;
9494 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009495 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009496 if (uiccProfile == null) {
9497 return;
9498 }
9499 uiccProfile.refresh();
9500 } finally {
9501 Binder.restoreCallingIdentity(identity);
9502 }
9503 }
9504
9505 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009506 * Returns false if the mobile data is disabled by default, otherwise return true.
9507 */
9508 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009509 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009510 }
9511
9512 /**
9513 * Returns true if the data roaming is enabled by default, i.e the system property
9514 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9515 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9516 */
9517 private boolean getDefaultDataRoamingEnabled(int subId) {
9518 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009519 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009520 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009521 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9522 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9523 return isDataRoamingEnabled;
9524 }
9525
9526 /**
9527 * Returns the default network type for the given {@code subId}, if the default network type is
9528 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9529 */
9530 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009531 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009532 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009533 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9534 return list.get(phoneId);
9535 }
9536 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009537 }
fionaxua13278b2018-03-21 00:08:13 -07009538
9539 @Override
9540 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009541 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009542 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009543
9544 final long identity = Binder.clearCallingIdentity();
9545 try {
9546 final Phone phone = getPhone(subId);
9547 if (phone == null) {
9548 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9549 return;
9550 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009551 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9552 if (cpt != null) {
9553 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9554 }
9555 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009556 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9557 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009558 if (carrierPrivilegeRules == null) {
9559 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9560 } else {
9561 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9562 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009563 } finally {
9564 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009565 }
fionaxua13278b2018-03-21 00:08:13 -07009566 }
9567
9568 @Override
9569 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009570 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009571
9572 final long identity = Binder.clearCallingIdentity();
9573 try {
9574 final Phone phone = getPhone(subId);
9575 if (phone == null) {
9576 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9577 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9578 }
9579 return phone.getCarrierIdListVersion();
9580 } finally {
9581 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009582 }
fionaxua13278b2018-03-21 00:08:13 -07009583 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009584
9585 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009586 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9587 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009588 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009589 mApp, subId, callingPackage, callingFeatureId,
9590 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009591 return -1;
9592 }
9593
9594 final long identity = Binder.clearCallingIdentity();
9595 try {
9596 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9597 } finally {
9598 Binder.restoreCallingIdentity(identity);
9599 }
9600 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009601
9602 @Override
9603 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009604 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009605 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009606 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -07009607
9608 final long identity = Binder.clearCallingIdentity();
9609 try {
9610 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9611 } finally {
9612 Binder.restoreCallingIdentity(identity);
9613 }
9614 }
9615
9616 @Override
9617 public boolean setCdmaRoamingMode(int subId, int mode) {
9618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9619 mApp, subId, "setCdmaRoamingMode");
9620
9621 final long identity = Binder.clearCallingIdentity();
9622 try {
9623 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9624 } finally {
9625 Binder.restoreCallingIdentity(identity);
9626 }
9627 }
9628
9629 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009630 public int getCdmaSubscriptionMode(int subId) {
9631 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009632 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009633 mApp, subId, "getCdmaSubscriptionMode");
9634
9635 final long identity = Binder.clearCallingIdentity();
9636 try {
9637 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9638 } finally {
9639 Binder.restoreCallingIdentity(identity);
9640 }
9641 }
9642
9643 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009644 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9645 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9646 mApp, subId, "setCdmaSubscriptionMode");
9647
9648 final long identity = Binder.clearCallingIdentity();
9649 try {
9650 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9651 } finally {
9652 Binder.restoreCallingIdentity(identity);
9653 }
9654 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009655
sqianc5eccab2018-10-19 18:46:41 -07009656 @Override
sqian8c685422019-02-22 15:55:18 -08009657 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009658 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009659 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009660 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9661 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009662 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9663 }
9664 final long identity = Binder.clearCallingIdentity();
9665 try {
sqian854d44b2018-12-12 16:48:18 -08009666 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9667 for (Phone phone: PhoneFactory.getPhones()) {
9668 if (phone.getEmergencyNumberTracker() != null
9669 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9670 emergencyNumberListInternal.put(
9671 phone.getSubId(),
9672 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9673 }
sqian11b7a0e2018-12-05 18:48:28 -08009674 }
sqian854d44b2018-12-12 16:48:18 -08009675 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009676 } finally {
9677 Binder.restoreCallingIdentity(identity);
9678 }
sqianc5eccab2018-10-19 18:46:41 -07009679 }
9680
9681 @Override
sqian8c685422019-02-22 15:55:18 -08009682 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009683 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009684 if (!exactMatch) {
9685 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009686 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009687 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009688 }
9689 final long identity = Binder.clearCallingIdentity();
9690 try {
sqian854d44b2018-12-12 16:48:18 -08009691 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009692 //Note: we ignore passed in param exactMatch. We can remove it once
9693 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009694 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009695 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009696 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009697 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009698 }
sqian11b7a0e2018-12-05 18:48:28 -08009699 }
9700 return false;
9701 } finally {
9702 Binder.restoreCallingIdentity(identity);
9703 }
9704 }
9705
sqianf4ca7ed2019-01-15 18:32:07 -08009706 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009707 * Start emergency callback mode for GsmCdmaPhone for testing.
9708 */
9709 @Override
9710 public void startEmergencyCallbackMode() {
9711 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9712 "startEmergencyCallbackMode");
9713 enforceModifyPermission();
9714 final long identity = Binder.clearCallingIdentity();
9715 try {
9716 for (Phone phone : PhoneFactory.getPhones()) {
9717 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9718 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9719 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9720 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9721 gsmCdmaPhone.obtainMessage(
9722 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9723 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9724 }
9725 }
9726 } finally {
9727 Binder.restoreCallingIdentity(identity);
9728 }
9729 }
9730
9731 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009732 * Update emergency number list for test mode.
9733 */
9734 @Override
9735 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9736 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9737 "updateEmergencyNumberListTestMode");
9738
9739 final long identity = Binder.clearCallingIdentity();
9740 try {
9741 for (Phone phone: PhoneFactory.getPhones()) {
9742 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9743 if (tracker != null) {
9744 tracker.executeEmergencyNumberTestModeCommand(action, num);
9745 }
9746 }
9747 } finally {
9748 Binder.restoreCallingIdentity(identity);
9749 }
9750 }
9751
9752 /**
9753 * Get the full emergency number list for test mode.
9754 */
9755 @Override
9756 public List<String> getEmergencyNumberListTestMode() {
9757 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9758 "getEmergencyNumberListTestMode");
9759
9760 final long identity = Binder.clearCallingIdentity();
9761 try {
9762 Set<String> emergencyNumbers = new HashSet<>();
9763 for (Phone phone: PhoneFactory.getPhones()) {
9764 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9765 if (tracker != null) {
9766 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9767 emergencyNumbers.add(num.getNumber());
9768 }
9769 }
9770 }
9771 return new ArrayList<>(emergencyNumbers);
9772 } finally {
9773 Binder.restoreCallingIdentity(identity);
9774 }
9775 }
9776
chen xud6b45bd2018-10-30 22:27:10 -07009777 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009778 public int getEmergencyNumberDbVersion(int subId) {
9779 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9780
9781 final long identity = Binder.clearCallingIdentity();
9782 try {
9783 final Phone phone = getPhone(subId);
9784 if (phone == null) {
9785 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9786 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9787 }
9788 return phone.getEmergencyNumberDbVersion();
9789 } finally {
9790 Binder.restoreCallingIdentity(identity);
9791 }
9792 }
9793
9794 @Override
9795 public void notifyOtaEmergencyNumberDbInstalled() {
9796 enforceModifyPermission();
9797
9798 final long identity = Binder.clearCallingIdentity();
9799 try {
9800 for (Phone phone: PhoneFactory.getPhones()) {
9801 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9802 if (tracker != null) {
9803 tracker.updateOtaEmergencyNumberDatabase();
9804 }
9805 }
9806 } finally {
9807 Binder.restoreCallingIdentity(identity);
9808 }
9809 }
9810
9811 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009812 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009813 enforceActiveEmergencySessionPermission();
9814
9815 final long identity = Binder.clearCallingIdentity();
9816 try {
9817 for (Phone phone: PhoneFactory.getPhones()) {
9818 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9819 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009820 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9821 }
9822 }
9823 } finally {
9824 Binder.restoreCallingIdentity(identity);
9825 }
9826 }
9827
9828 @Override
9829 public void resetOtaEmergencyNumberDbFilePath() {
9830 enforceActiveEmergencySessionPermission();
9831
9832 final long identity = Binder.clearCallingIdentity();
9833 try {
9834 for (Phone phone: PhoneFactory.getPhones()) {
9835 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9836 if (tracker != null) {
9837 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009838 }
9839 }
9840 } finally {
9841 Binder.restoreCallingIdentity(identity);
9842 }
9843 }
9844
9845 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009846 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9847 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9848 Phone phone = getPhone(subId);
9849 if (phone == null) {
9850 return null;
9851 }
9852 final long identity = Binder.clearCallingIdentity();
9853 try {
9854 UiccProfile profile = UiccController.getInstance()
9855 .getUiccProfileForPhone(phone.getPhoneId());
9856 if (profile != null) {
9857 return profile.getCertsFromCarrierPrivilegeAccessRules();
9858 }
9859 } finally {
9860 Binder.restoreCallingIdentity(identity);
9861 }
9862 return null;
9863 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009864
9865 /**
9866 * Enable or disable a modem stack.
9867 */
9868 @Override
9869 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9870 enforceModifyPermission();
9871
9872 final long identity = Binder.clearCallingIdentity();
9873 try {
9874 Phone phone = PhoneFactory.getPhone(slotIndex);
9875 if (phone == null) {
9876 return false;
9877 } else {
9878 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9879 }
9880 } finally {
9881 Binder.restoreCallingIdentity(identity);
9882 }
9883 }
Michelecea4cf22018-12-21 15:00:11 -08009884
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009885 /**
9886 * Whether a modem stack is enabled or not.
9887 */
9888 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009889 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9890 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009891 Phone phone = PhoneFactory.getPhone(slotIndex);
9892 if (phone == null) return false;
9893
9894 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009895 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9896 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009897 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9898 }
9899
9900 final long identity = Binder.clearCallingIdentity();
9901 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009902 try {
9903 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9904 } catch (NoSuchElementException ex) {
9905 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9906 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009907 } finally {
9908 Binder.restoreCallingIdentity(identity);
9909 }
9910 }
9911
Michelecea4cf22018-12-21 15:00:11 -08009912 @Override
Michele0ea7d782019-03-19 14:58:42 -07009913 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009914 enforceModifyPermission();
9915
9916 final long identity = Binder.clearCallingIdentity();
9917 try {
9918 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009919 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009920 .commit();
9921 } finally {
9922 Binder.restoreCallingIdentity(identity);
9923 }
9924 }
9925
9926 @Override
Michele0ea7d782019-03-19 14:58:42 -07009927 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009928 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009929 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009930 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9931 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009932 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009933 }
Michelecea4cf22018-12-21 15:00:11 -08009934
9935 final long identity = Binder.clearCallingIdentity();
9936 try {
Michele0ea7d782019-03-19 14:58:42 -07009937 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009938 } finally {
9939 Binder.restoreCallingIdentity(identity);
9940 }
9941 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009942
Michele0ea7d782019-03-19 14:58:42 -07009943 @TelephonyManager.IsMultiSimSupportedResult
9944 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009945 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9946 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9947 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009948 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9949 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009950 }
9951 // Check if the hardware supports multisim functionality. If usage of multisim is not
9952 // supported by the modem, indicate that it is restricted.
9953 PhoneCapability staticCapability =
9954 mPhoneConfigurationManager.getStaticPhoneCapability();
9955 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009956 loge("isMultiSimSupportedInternal: no static configuration available");
9957 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009958 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009959 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009960 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9961 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009962 }
9963 // Check if support of multiple SIMs is restricted by carrier
9964 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009965 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009966 }
9967
Michele0ea7d782019-03-19 14:58:42 -07009968 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009969 }
9970
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009971 /**
9972 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009973 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9974 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9975 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009976 * @param numOfSims number of active sims we want to switch to
9977 */
9978 @Override
9979 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009980 if (numOfSims == 1) {
9981 enforceModifyPermission();
9982 } else {
9983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9984 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9985 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009986 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009987
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009988 try {
Michele30b57b22019-03-01 12:01:14 -08009989 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009990 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009991 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9992 return;
9993 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009994 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9995 } finally {
9996 Binder.restoreCallingIdentity(identity);
9997 }
9998 }
9999
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010000 @Override
10001 public boolean isApplicationOnUicc(int subId, int appType) {
10002 enforceReadPrivilegedPermission("isApplicationOnUicc");
10003 Phone phone = getPhone(subId);
10004 if (phone == null) {
10005 return false;
10006 }
10007 final long identity = Binder.clearCallingIdentity();
10008 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010009 UiccPort uiccPort = phone.getUiccPort();
10010 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010011 return false;
10012 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010013 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010014 if (uiccProfile == null) {
10015 return false;
10016 }
10017 if (TelephonyManager.APPTYPE_SIM <= appType
10018 && appType <= TelephonyManager.APPTYPE_ISIM) {
10019 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10020 }
10021 return false;
10022 } finally {
10023 Binder.restoreCallingIdentity(identity);
10024 }
10025 }
10026
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010027 /**
chen xub4baa772019-04-03 10:23:41 -070010028 * Get whether making changes to modem configurations will trigger reboot.
10029 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010030 */
10031 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010032 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10033 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010034 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010035 mApp, subId, callingPackage, callingFeatureId,
10036 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010037 return false;
10038 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010039 final long identity = Binder.clearCallingIdentity();
10040 try {
10041 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10042 } finally {
10043 Binder.restoreCallingIdentity(identity);
10044 }
10045 }
10046
Nathan Harold29f5f052019-02-15 13:41:57 -080010047 private void updateModemStateMetrics() {
10048 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10049 // TODO: check the state for each modem if the api is ready.
10050 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10051 }
10052
Pengquan Meng3889a572019-01-23 11:16:29 -080010053 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010054 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010055 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010056 // Verify that the callingPackage belongs to the calling UID
10057 mApp.getSystemService(AppOpsManager.class)
10058 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010059 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010060 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010061 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010062 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10063 if (slotInfos != null) {
10064 for (int i = 0; i < slotInfos.length; i++) {
10065 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10066 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10067 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10068 portInfo.getLogicalSlotIndex()));
10069 }
10070 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010071 }
10072 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010073 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010074 } finally {
10075 Binder.restoreCallingIdentity(identity);
10076 }
10077 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010078
10079 /**
10080 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010081 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010082 */
jimsunf9ec1622022-09-13 21:18:43 +080010083 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010084 @Override
10085 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010086 return getHalVersion(HAL_SERVICE_RADIO);
10087 }
10088
10089 /**
10090 * Get the HAL Version of a specific service
10091 */
10092 @Override
10093 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010094 Phone phone = getDefaultPhone();
10095 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010096 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010097 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10098 return hv.major * 100 + hv.minor;
10099 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010100
10101 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010102 * Get the current calling package name.
10103 * @return the current calling package name
10104 */
10105 @Override
10106 public String getCurrentPackageName() {
10107 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10108 }
10109
10110 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010111 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10112 * corresponding network requests on a subId.
10113 *
10114 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010115 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010116 * 2) APN is un-metered for this subscription, or
10117 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010118 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010119 *
10120 * @return whether data is allowed for a apn type.
10121 *
10122 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010123 */
10124 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010125 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010126 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10127 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010128
10129 // Now that all security checks passes, perform the operation as ourselves.
10130 final long identity = Binder.clearCallingIdentity();
10131 try {
10132 Phone phone = getPhone(subId);
10133 if (phone == null) return false;
10134
Jack Yu27422a52022-03-21 10:38:05 -070010135 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010136 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010137 isMetered = phone.getDataNetworkController().getDataConfigManager()
10138 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10139 phone.getServiceState().getDataRoaming());
10140 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010141 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010142 } finally {
10143 Binder.restoreCallingIdentity(identity);
10144 }
10145 }
10146
10147 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010148 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010149 enforceReadPrivilegedPermission("isApnMetered");
10150
10151 // Now that all security checks passes, perform the operation as ourselves.
10152 final long identity = Binder.clearCallingIdentity();
10153 try {
10154 Phone phone = getPhone(subId);
10155 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010156 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10157 DataUtils.apnTypeToNetworkCapability(apnType),
10158 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010159 } finally {
10160 Binder.restoreCallingIdentity(identity);
10161 }
10162 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010163
10164 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010165 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10166 int subscriptionId, IBooleanConsumer resultCallback) {
10167 enforceModifyPermission();
10168 long token = Binder.clearCallingIdentity();
10169 try {
10170 Phone phone = getPhone(subscriptionId);
10171 if (phone == null) {
10172 try {
10173 if (resultCallback != null) {
10174 resultCallback.accept(false);
10175 }
10176 } catch (RemoteException e) {
10177 // ignore
10178 }
10179 return;
10180 }
10181 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10182 Pair.create(specifiers, (x) -> {
10183 try {
10184 if (resultCallback != null) {
10185 resultCallback.accept(x);
10186 }
10187 } catch (RemoteException e) {
10188 // ignore
10189 }
10190 });
10191 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10192 } finally {
10193 Binder.restoreCallingIdentity(token);
10194 }
10195 }
10196
10197 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010198 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10199 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010200 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010201 mApp, subId, "getSystemSelectionChannels");
10202 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10203 final long identity = Binder.clearCallingIdentity();
10204 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010205 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10206 if (result instanceof IllegalStateException) {
10207 throw (IllegalStateException) result;
10208 }
10209 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010210 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10211 return specifiers;
10212 } finally {
10213 Binder.restoreCallingIdentity(identity);
10214 }
10215 }
10216
10217 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010218 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010219 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010220 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010221 }
10222
10223 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010224 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10225 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010226 if (callingPackage == null) {
10227 callingPackage = getCurrentPackageName();
10228 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010229 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10230 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010231 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10232 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010233 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10234 }
10235 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10236 Intent intent = new Intent();
10237 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10238 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10239 // Bring up choose default SMS subscription dialog right now
10240 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10241 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10242 mApp.startActivity(intent);
10243 }
chen xud5ca2d52019-05-28 15:20:57 -070010244
10245 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010246 public void showSwitchToManagedProfileDialog() {
10247 enforceModifyPermission();
10248
10249 Intent intent = new Intent();
10250 intent.setClass(mApp, ErrorDialogActivity.class);
10251 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10252 mApp.startActivity(intent);
10253 }
10254
10255 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010256 public String getMmsUAProfUrl(int subId) {
10257 //TODO investigate if this API should require proper permission check in R b/133791609
10258 final long identity = Binder.clearCallingIdentity();
10259 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010260 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10261 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10262 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10263 return carrierUAProfUrl;
10264 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010265 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10266 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010267 } finally {
10268 Binder.restoreCallingIdentity(identity);
10269 }
10270 }
10271
10272 @Override
10273 public String getMmsUserAgent(int subId) {
10274 //TODO investigate if this API should require proper permission check in R b/133791609
10275 final long identity = Binder.clearCallingIdentity();
10276 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010277 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10278 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10279 if (!TextUtils.isEmpty(carrierUserAgent)) {
10280 return carrierUserAgent;
10281 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010282 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10283 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010284 } finally {
10285 Binder.restoreCallingIdentity(identity);
10286 }
10287 }
Jack Yub07d4972019-05-28 16:12:25 -070010288
10289 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010290 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10291 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010292
Jack Yub07d4972019-05-28 16:12:25 -070010293 final long identity = Binder.clearCallingIdentity();
10294 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010295 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010296 if (phone == null) return false;
10297
Ling Maf188d502022-09-16 15:22:36 -070010298 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010299 } finally {
10300 Binder.restoreCallingIdentity(identity);
10301 }
10302 }
10303
10304 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010305 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010306 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010307 enforceModifyPermission();
10308
changbettyd5c246e2019-12-24 15:40:37 +080010309 final long identity = Binder.clearCallingIdentity();
10310 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010311 Phone phone = getPhone(subscriptionId);
10312 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010313
Ling Maf188d502022-09-16 15:22:36 -070010314 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010315 } finally {
10316 Binder.restoreCallingIdentity(identity);
10317 }
10318 }
10319
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010320 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010321 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010322 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10323 * otherwise.
10324 */
10325 @Override
10326 public void setCepEnabled(boolean isCepEnabled) {
10327 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10328
10329 final long identity = Binder.clearCallingIdentity();
10330 try {
10331 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10332 for (Phone phone : PhoneFactory.getPhones()) {
10333 Phone defaultPhone = phone.getImsPhone();
10334 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10335 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10336 ImsPhoneCallTracker imsPhoneCallTracker =
10337 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10338 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10339 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10340 + imsPhone.getMsisdn());
10341 }
10342 }
10343 } finally {
10344 Binder.restoreCallingIdentity(identity);
10345 }
10346 }
allenwtsu46dcc572020-01-08 18:24:03 +080010347
10348 /**
10349 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10350 *
10351 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10352 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10353 * before being read.
10354 */
10355 @Override
10356 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10357 isCompressed) {
10358 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10359 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010360 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10361 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10362 }
10363 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010364 // ProvisioningManager can not handle ServiceSpecificException.
10365 // Throw the IllegalStateException and annotate ProvisioningManager.
10366 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010367 }
10368
10369 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010370 try {
Hui Wang761a6682020-10-31 05:12:53 +000010371 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10372 } finally {
10373 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010374 }
10375 }
zoey chene02881a2019-12-30 16:11:23 +080010376
10377 @Override
10378 public boolean isIccLockEnabled(int subId) {
10379 enforceReadPrivilegedPermission("isIccLockEnabled");
10380
10381 // Now that all security checks passes, perform the operation as ourselves.
10382 final long identity = Binder.clearCallingIdentity();
10383 try {
10384 Phone phone = getPhone(subId);
10385 if (phone != null && phone.getIccCard() != null) {
10386 return phone.getIccCard().getIccLockEnabled();
10387 } else {
10388 return false;
10389 }
10390 } finally {
10391 Binder.restoreCallingIdentity(identity);
10392 }
10393 }
10394
10395 /**
10396 * Set the ICC pin lock enabled or disabled.
10397 *
10398 * @return an integer representing the status of IccLock enabled or disabled in the following
10399 * three cases:
10400 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10401 * successfully.
10402 * - Positive number and zero for remaining password attempts.
10403 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10404 *
10405 */
10406 @Override
10407 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10408 enforceModifyPermission();
10409
10410 Phone phone = getPhone(subId);
10411 if (phone == null) {
10412 return 0;
10413 }
10414 // Now that all security checks passes, perform the operation as ourselves.
10415 final long identity = Binder.clearCallingIdentity();
10416 try {
10417 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10418 new Pair<Boolean, String>(enabled, password), phone, null);
10419 return attemptsRemaining;
10420
10421 } catch (Exception e) {
10422 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10423 } finally {
10424 Binder.restoreCallingIdentity(identity);
10425 }
10426 return 0;
10427 }
10428
10429 /**
10430 * Change the ICC password used in ICC pin lock.
10431 *
10432 * @return an integer representing the status of IccLock changed in the following three cases:
10433 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10434 * - Positive number and zero for remaining password attempts.
10435 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10436 *
10437 */
10438 @Override
10439 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10440 enforceModifyPermission();
10441
10442 Phone phone = getPhone(subId);
10443 if (phone == null) {
10444 return 0;
10445 }
10446 // Now that all security checks passes, perform the operation as ourselves.
10447 final long identity = Binder.clearCallingIdentity();
10448 try {
10449 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10450 new Pair<String, String>(oldPassword, newPassword), phone, null);
10451 return attemptsRemaining;
10452
10453 } catch (Exception e) {
10454 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10455 } finally {
10456 Binder.restoreCallingIdentity(identity);
10457 }
10458 return 0;
10459 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010460
10461 /**
10462 * Request for receiving user activity notification
10463 */
10464 @Override
10465 public void requestUserActivityNotification() {
10466 if (!mNotifyUserActivity.get()
10467 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10468 mNotifyUserActivity.set(true);
10469 }
10470 }
10471
10472 /**
10473 * Called when userActivity is signalled in the power manager.
10474 * This is safe to call from any thread, with any window manager locks held or not.
10475 */
10476 @Override
10477 public void userActivity() {
10478 // ***************************************
10479 // * Inherited from PhoneWindowManager *
10480 // ***************************************
10481 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10482 // WITH ITS LOCKS HELD.
10483 //
10484 // This code must be VERY careful about the locks
10485 // it acquires.
10486 // In fact, the current code acquires way too many,
10487 // and probably has lurking deadlocks.
10488
10489 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10490 throw new SecurityException("Only the OS may call notifyUserActivity()");
10491 }
10492
10493 if (mNotifyUserActivity.getAndSet(false)) {
10494 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10495 USER_ACTIVITY_NOTIFICATION_DELAY);
10496 }
10497 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010498
10499 @Override
10500 public boolean canConnectTo5GInDsdsMode() {
10501 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10502 }
Jack Yud10cdd42020-09-28 20:28:01 -070010503
10504 @Override
10505 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10506 String callingFeatureId) {
10507 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10508 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10509 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10510 }
10511
10512 Phone phone = getPhone(subId);
10513 if (phone == null) {
10514 throw new RuntimeException("phone is not available");
10515 }
10516 // Now that all security checks passes, perform the operation as ourselves.
10517 final long identity = Binder.clearCallingIdentity();
10518 try {
10519 return phone.getEquivalentHomePlmns();
10520 } finally {
10521 Binder.restoreCallingIdentity(identity);
10522 }
10523 }
Daniel Bright59e67312020-11-13 11:49:37 -080010524
10525 @Override
10526 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010527 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10528 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010529 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010530 if (radioInterfaceCapabilities == null) {
10531 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010532 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010533 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010534 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010535
Hui Wang641e81c2020-10-12 12:14:23 -070010536 @Override
10537 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10538 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010539 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10540 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10541 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10542 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10543 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010544 if (DBG) {
10545 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10546 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10547 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10548 }
10549
10550 if (!SubscriptionManager.isValidSubscriptionId(subId)
10551 || appType < TelephonyManager.APPTYPE_UNKNOWN
10552 || appType > TelephonyManager.APPTYPE_ISIM
10553 || nafUrl == null || securityProtocol == null || callback == null) {
10554 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10555 if (callback != null) {
10556 try {
10557 callback.onAuthenticationFailure(
10558 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10559 } catch (RemoteException exception) {
10560 log("Fail to notify onAuthenticationFailure due to " + exception);
10561 }
10562 return;
10563 }
10564 }
10565
10566 final long token = Binder.clearCallingIdentity();
10567 try {
10568 getGbaManager(subId).bootstrapAuthenticationRequest(
10569 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010570 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070010571 } finally {
10572 Binder.restoreCallingIdentity(token);
10573 }
10574 }
10575
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010576 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010577 * Attempts to set the radio power state for all phones for thermal reason.
10578 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010579 * requested radio power state will actually be set. See {@link
10580 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10581 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010582 * @param enable {@code true} if trying to turn radio on.
10583 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10584 * false}.
10585 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010586 private boolean setRadioPowerForThermal(boolean enable) {
10587 boolean isPhoneAvailable = false;
10588 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10589 Phone phone = PhoneFactory.getPhone(i);
10590 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010591 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010592 isPhoneAvailable = true;
10593 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010594 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010595
10596 // return true if successfully informed the phone object about the thermal radio power
10597 // request.
10598 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010599 }
10600
10601 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010602 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010603 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10604 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10605 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10606 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10607 throw new IllegalArgumentException("modem does not support data throttling");
10608 }
10609
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010610 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10611 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010612 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010613 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10614 }
10615
Sarah Chinecc78c42022-03-31 21:16:48 -070010616 setDataEnabledForReason(
10617 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010618
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010619 if (isDataThrottlingSupported) {
10620 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010621 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010622 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10623 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10624 } else if (thermalMitigationResult
10625 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010626 log("Modem likely does not support data throttling on secondary carrier. Data " +
10627 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10628 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010629 }
10630 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010631 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010632
10633 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010634 }
10635
Jack Nudelman644b91a2021-03-12 14:09:48 -080010636 private static List<String> getThermalMitigationAllowlist(Context context) {
10637 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10638 for (String pckg : context.getResources()
10639 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10640 sThermalMitigationAllowlistedPackages.add(pckg);
10641 }
10642 }
10643
10644 return sThermalMitigationAllowlistedPackages;
10645 }
10646
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010647 private boolean isAnyPhoneInEmergencyState() {
10648 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10649 if (tm.isInEmergencyCall()) {
10650 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10651 return true;
10652 }
10653 for (Phone phone : PhoneFactory.getPhones()) {
10654 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10655 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010656 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10657 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010658 return true;
10659 }
10660 }
10661
10662 return false;
10663 }
10664
Jack Nudelman644b91a2021-03-12 14:09:48 -080010665 /**
10666 * Used by shell commands to add an authorized package name for thermal mitigation.
10667 * @param packageName name of package to be allowlisted
10668 * @param context
10669 */
10670 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10671 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10672 sThermalMitigationAllowlistedPackages.add(packageName);
10673 }
10674
10675 /**
10676 * Used by shell commands to remove an authorized package name for thermal mitigation.
10677 * @param packageName name of package to remove from allowlist
10678 * @param context
10679 */
10680 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10681 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10682 sThermalMitigationAllowlistedPackages.remove(packageName);
10683 }
10684
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010685 /**
10686 * Thermal mitigation request to control functionalities at modem.
10687 *
10688 * @param subId the id of the subscription.
10689 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010690 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010691 *
10692 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10693 */
10694 @Override
10695 @ThermalMitigationResult
10696 public int sendThermalMitigationRequest(
10697 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010698 ThermalMitigationRequest thermalMitigationRequest,
10699 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010700 enforceModifyPermission();
10701
Jack Nudelman644b91a2021-03-12 14:09:48 -080010702 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10703 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10704 .contains(callingPackage)) {
10705 throw new SecurityException("Calling package must be configured in the device config. "
10706 + "calling package: " + callingPackage);
10707 }
10708
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010709 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10710 final long identity = Binder.clearCallingIdentity();
10711
10712 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10713 try {
10714 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10715 switch (thermalMitigationAction) {
10716 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10717 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010718 handleDataThrottlingRequest(subId,
10719 thermalMitigationRequest.getDataThrottlingRequest(),
10720 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010721 break;
10722 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10723 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10724 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10725 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10726 }
10727
10728 // Ensure that radio is on. If not able to power on due to phone being
10729 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010730 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010731 thermalMitigationResult =
10732 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10733 break;
10734 }
10735
10736 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010737 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010738 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10739 break;
10740 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10741 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10742 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10743 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10744 }
10745
10746 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10747 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010748 Phone phone = getPhone(subId);
10749 if (phone == null) {
10750 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010751 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010752 break;
10753 }
10754
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010755 TelephonyConnectionService service =
10756 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010757 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010758 Log.e(LOG_TAG, "An emergency call is pending");
10759 thermalMitigationResult =
10760 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10761 break;
10762 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010763 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010764 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010765 break;
10766 }
10767 } else {
10768 thermalMitigationResult =
10769 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10770 break;
10771 }
10772
10773 // Turn radio off. If not able to power off due to phone being unavailable,
10774 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010775 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010776 thermalMitigationResult =
10777 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10778 break;
10779 }
10780 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010781 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010782 break;
10783 default:
10784 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10785 + "not exist. Requested action: " + thermalMitigationAction);
10786 }
10787 } catch (IllegalArgumentException e) {
10788 throw e;
10789 } catch (Exception e) {
10790 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10791 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10792 } finally {
10793 Binder.restoreCallingIdentity(identity);
10794 }
10795
10796 if (DBG) {
10797 log("thermalMitigationRequest returning with thermalMitigationResult: "
10798 + thermalMitigationResult);
10799 }
10800
10801 return thermalMitigationResult;
10802 }
Hui Wang641e81c2020-10-12 12:14:23 -070010803
10804 /**
10805 * Set the GbaService Package Name that Telephony will bind to.
10806 *
10807 * @param subId The sim that the GbaService is associated with.
10808 * @param packageName The name of the package to be replaced with.
10809 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10810 */
10811 @Override
10812 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10813 enforceModifyPermission();
10814
10815 final long identity = Binder.clearCallingIdentity();
10816 try {
10817 return getGbaManager(subId).overrideServicePackage(packageName);
10818 } finally {
10819 Binder.restoreCallingIdentity(identity);
10820 }
10821 }
10822
10823 /**
10824 * Return the package name of the currently bound GbaService.
10825 *
10826 * @param subId The sim that the GbaService is associated with.
10827 * @return the package name of the GbaService configuration, null if GBA is not supported.
10828 */
10829 @Override
10830 public String getBoundGbaService(int subId) {
10831 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10832
10833 final long identity = Binder.clearCallingIdentity();
10834 try {
10835 return getGbaManager(subId).getServicePackage();
10836 } finally {
10837 Binder.restoreCallingIdentity(identity);
10838 }
10839 }
10840
10841 /**
10842 * Set the release time for telephony to unbind GbaService.
10843 *
10844 * @param subId The sim that the GbaService is associated with.
10845 * @param interval The release time to unbind GbaService by millisecond.
10846 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10847 */
10848 @Override
10849 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10850 enforceModifyPermission();
10851
10852 final long identity = Binder.clearCallingIdentity();
10853 try {
10854 return getGbaManager(subId).overrideReleaseTime(interval);
10855 } finally {
10856 Binder.restoreCallingIdentity(identity);
10857 }
10858 }
10859
10860 /**
10861 * Return the release time for telephony to unbind GbaService.
10862 *
10863 * @param subId The sim that the GbaService is associated with.
10864 * @return The release time to unbind GbaService by millisecond.
10865 */
10866 @Override
10867 public int getGbaReleaseTime(int subId) {
10868 enforceReadPrivilegedPermission("getGbaReleaseTime");
10869
10870 final long identity = Binder.clearCallingIdentity();
10871 try {
10872 return getGbaManager(subId).getReleaseTime();
10873 } finally {
10874 Binder.restoreCallingIdentity(identity);
10875 }
10876 }
10877
10878 private GbaManager getGbaManager(int subId) {
10879 GbaManager instance = GbaManager.getInstance(subId);
10880 if (instance == null) {
10881 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10882 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10883 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10884 }
10885 return instance;
10886 }
Hui Wang761a6682020-10-31 05:12:53 +000010887
10888 /**
10889 * indicate whether the device and the carrier can support
10890 * RCS VoLTE single registration.
10891 */
10892 @Override
10893 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010894 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10895 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10896 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10897 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010898
10899 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10900 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10901 }
10902
10903 final long identity = Binder.clearCallingIdentity();
10904 try {
10905 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10906 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010907 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10908 if (isCapable != null) {
10909 return isCapable;
10910 }
Hui Wang761a6682020-10-31 05:12:53 +000010911 }
Hui Wang67af90e2021-06-04 16:57:15 -070010912 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10913 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010914 } finally {
10915 Binder.restoreCallingIdentity(identity);
10916 }
10917 }
10918
10919 /**
10920 * Register RCS provisioning callback.
10921 */
10922 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010923 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010924 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010925 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010926 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010927 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10928 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010929
10930 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10931 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10932 }
10933 if (!isImsAvailableOnDevice()) {
10934 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10935 "IMS not available on device.");
10936 }
10937
10938 final long identity = Binder.clearCallingIdentity();
10939 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010940 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010941 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010942 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10943 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010944 }
Hui Wang761a6682020-10-31 05:12:53 +000010945 } finally {
10946 Binder.restoreCallingIdentity(identity);
10947 }
10948 }
10949
10950 /**
10951 * Unregister RCS provisioning callback.
10952 */
10953 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010954 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010955 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010956 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010957 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010958 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10959 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010960
10961 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10962 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10963 }
10964 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010965 // operation failed silently
10966 Rlog.w(LOG_TAG, "IMS not available on device.");
10967 return;
Hui Wang761a6682020-10-31 05:12:53 +000010968 }
10969
10970 final long identity = Binder.clearCallingIdentity();
10971 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010972 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010973 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010974 } finally {
10975 Binder.restoreCallingIdentity(identity);
10976 }
10977 }
10978
10979 /**
10980 * trigger RCS reconfiguration.
10981 */
10982 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010983 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10984 "triggerRcsReconfiguration",
10985 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010986
10987 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10988 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10989 }
10990 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010991 // ProvisioningManager can not handle ServiceSpecificException.
10992 // Throw the IllegalStateException and annotate ProvisioningManager.
10993 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010994 }
10995
10996 final long identity = Binder.clearCallingIdentity();
10997 try {
10998 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10999 } finally {
11000 Binder.restoreCallingIdentity(identity);
11001 }
11002 }
11003
11004 /**
11005 * Provide the client configuration parameters of the RCS application.
11006 */
11007 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011008 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11009 "setRcsClientConfiguration",
11010 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011011
11012 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11013 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11014 }
11015 if (!isImsAvailableOnDevice()) {
11016 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11017 "IMS not available on device.");
11018 }
11019
11020 final long identity = Binder.clearCallingIdentity();
11021
11022 try {
11023 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11024 if (configBinder == null) {
11025 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011026 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11027 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011028 } else {
11029 configBinder.setRcsClientConfiguration(rcc);
11030 }
joonhunshin3e154242021-09-17 06:33:39 +000011031
11032 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11033 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011034 } catch (RemoteException e) {
11035 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011036 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11037 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011038 } finally {
11039 Binder.restoreCallingIdentity(identity);
11040 }
11041 }
11042
11043 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011044 * Enables or disables the test mode for RCS VoLTE single registration.
11045 */
11046 @Override
11047 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11048 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11049 "setRcsSingleRegistrationTestModeEnabled");
11050
11051 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11052 }
11053
11054 /**
11055 * Gets the test mode for RCS VoLTE single registration.
11056 */
11057 @Override
11058 public boolean getRcsSingleRegistrationTestModeEnabled() {
11059 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11060 "getRcsSingleRegistrationTestModeEnabled");
11061
11062 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11063 }
11064
11065 /**
Hui Wang761a6682020-10-31 05:12:53 +000011066 * Overrides the config of RCS VoLTE single registration enabled for the device.
11067 */
11068 @Override
11069 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11070 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11071 "setDeviceSingleRegistrationEnabledOverride");
11072 enforceModifyPermission();
11073
11074 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11075 : Boolean.parseBoolean(enabledStr);
11076 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011077 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011078 }
11079
11080 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011081 * Sends a device to device communication message. Only usable via shell.
11082 * @param message message to send.
11083 * @param value message value.
11084 */
11085 @Override
11086 public void sendDeviceToDeviceMessage(int message, int value) {
11087 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011088 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011089 enforceModifyPermission();
11090
11091 final long identity = Binder.clearCallingIdentity();
11092 try {
11093 TelephonyConnectionService service =
11094 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11095 if (service == null) {
11096 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11097 return;
11098 }
11099 service.sendTestDeviceToDeviceMessage(message, value);
11100 } finally {
11101 Binder.restoreCallingIdentity(identity);
11102 }
11103 }
11104
Tyler Gunnbabbda02021-02-10 11:05:02 -080011105 /**
11106 * Sets the specified device to device transport active.
11107 * @param transport The transport to set active.
11108 */
11109 @Override
11110 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11111 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11112 "setActiveDeviceToDeviceTransport");
11113 enforceModifyPermission();
11114
11115 final long identity = Binder.clearCallingIdentity();
11116 try {
11117 TelephonyConnectionService service =
11118 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11119 if (service == null) {
11120 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11121 return;
11122 }
11123 service.setActiveDeviceToDeviceTransport(transport);
11124 } finally {
11125 Binder.restoreCallingIdentity(identity);
11126 }
11127 }
Tyler Gunn92479152021-01-20 16:30:10 -080011128
Tyler Gunnd4339262021-05-03 14:46:49 -070011129 @Override
11130 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11131 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11132 "setDeviceToDeviceForceEnabled");
11133
11134 final long identity = Binder.clearCallingIdentity();
11135 try {
11136 Arrays.stream(PhoneFactory.getPhones()).forEach(
11137 p -> {
11138 Phone thePhone = p.getImsPhone();
11139 if (thePhone != null && thePhone instanceof ImsPhone) {
11140 ImsPhone imsPhone = (ImsPhone) thePhone;
11141 CallTracker tracker = imsPhone.getCallTracker();
11142 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11143 ImsPhoneCallTracker imsPhoneCallTracker =
11144 (ImsPhoneCallTracker) tracker;
11145 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11146 }
11147 }
11148 }
11149 );
11150 } finally {
11151 Binder.restoreCallingIdentity(identity);
11152 }
11153 }
11154
Tyler Gunn92479152021-01-20 16:30:10 -080011155 /**
Hui Wang761a6682020-10-31 05:12:53 +000011156 * Gets the config of RCS VoLTE single registration enabled for the device.
11157 */
11158 @Override
11159 public boolean getDeviceSingleRegistrationEnabled() {
11160 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11161 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11162 }
11163
11164 /**
11165 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11166 */
11167 @Override
11168 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11169 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11170 "setCarrierSingleRegistrationEnabledOverride");
11171 enforceModifyPermission();
11172
11173 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11174 : Boolean.parseBoolean(enabledStr);
11175 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11176 subId, enabled);
11177 }
11178
11179 /**
11180 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11181 */
11182 @Override
11183 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11184 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11185 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11186 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011187
11188 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011189 * Overrides the ims feature validation result
11190 */
11191 @Override
11192 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11193 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11194 "setImsFeatureValidationOverride");
11195
11196 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11197 : Boolean.parseBoolean(enabledStr);
11198 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11199 subId, enabled);
11200 }
11201
11202 /**
11203 * Gets the ims feature validation override value
11204 */
11205 @Override
11206 public boolean getImsFeatureValidationOverride(int subId) {
11207 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11208 "getImsFeatureValidationOverride");
11209 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11210 }
11211
11212 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011213 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11214 * their mobile plan.
11215 */
11216 @Override
11217 public String getMobileProvisioningUrl() {
11218 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11219 final long identity = Binder.clearCallingIdentity();
11220 try {
11221 return getDefaultPhone().getMobileProvisioningUrl();
11222 } finally {
11223 Binder.restoreCallingIdentity(identity);
11224 }
11225 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011226
James.cf Linbcdf8b32021-01-14 16:44:13 +080011227 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011228 * Get the EAB contact from the EAB database.
11229 */
11230 @Override
11231 public String getContactFromEab(String contact) {
11232 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11233 enforceModifyPermission();
11234 final long identity = Binder.clearCallingIdentity();
11235 try {
11236 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11237 } finally {
11238 Binder.restoreCallingIdentity(identity);
11239 }
11240 }
11241
11242 /**
Calvin Pana1434322021-07-01 19:27:01 +080011243 * Get the EAB capability from the EAB database.
11244 */
11245 @Override
11246 public String getCapabilityFromEab(String contact) {
11247 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11248 enforceModifyPermission();
11249 final long identity = Binder.clearCallingIdentity();
11250 try {
11251 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11252 } finally {
11253 Binder.restoreCallingIdentity(identity);
11254 }
11255 }
11256
11257 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011258 * Remove the EAB contacts from the EAB database.
11259 */
11260 @Override
11261 public int removeContactFromEab(int subId, String contacts) {
11262 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11263 enforceModifyPermission();
11264 final long identity = Binder.clearCallingIdentity();
11265 try {
11266 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11267 } finally {
11268 Binder.restoreCallingIdentity(identity);
11269 }
11270 }
11271
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011272 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011273 public boolean getDeviceUceEnabled() {
11274 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11275 final long identity = Binder.clearCallingIdentity();
11276 try {
11277 return mApp.getDeviceUceEnabled();
11278 } finally {
11279 Binder.restoreCallingIdentity(identity);
11280 }
11281 }
11282
11283 @Override
11284 public void setDeviceUceEnabled(boolean isEnabled) {
11285 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11286 final long identity = Binder.clearCallingIdentity();
11287 try {
11288 mApp.setDeviceUceEnabled(isEnabled);
11289 } finally {
11290 Binder.restoreCallingIdentity(identity);
11291 }
11292 }
11293
Brad Ebinger14d467f2021-02-12 06:18:28 +000011294 /**
11295 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11296 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11297 */
11298 // Used for SHELL command only right now.
11299 @Override
11300 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11301 List<String> featureTags) {
11302 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11303 "addUceRegistrationOverrideShell");
11304 final long identity = Binder.clearCallingIdentity();
11305 try {
11306 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11307 new ArraySet<>(featureTags));
11308 } catch (ImsException e) {
11309 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11310 } finally {
11311 Binder.restoreCallingIdentity(identity);
11312 }
11313 }
11314
11315 /**
11316 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11317 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11318 */
11319 // Used for SHELL command only right now.
11320 @Override
11321 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11322 List<String> featureTags) {
11323 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11324 "removeUceRegistrationOverrideShell");
11325 final long identity = Binder.clearCallingIdentity();
11326 try {
11327 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11328 new ArraySet<>(featureTags));
11329 } catch (ImsException e) {
11330 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11331 } finally {
11332 Binder.restoreCallingIdentity(identity);
11333 }
11334 }
11335
11336 /**
11337 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11338 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11339 */
11340 // Used for SHELL command only right now.
11341 @Override
11342 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11343 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11344 "clearUceRegistrationOverrideShell");
11345 final long identity = Binder.clearCallingIdentity();
11346 try {
11347 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11348 } catch (ImsException e) {
11349 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11350 } finally {
11351 Binder.restoreCallingIdentity(identity);
11352 }
11353 }
11354
11355 /**
11356 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11357 */
11358 // Used for SHELL command only right now.
11359 @Override
11360 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11361 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11362 "getLatestRcsContactUceCapabilityShell");
11363 final long identity = Binder.clearCallingIdentity();
11364 try {
11365 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11366 } catch (ImsException e) {
11367 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11368 } finally {
11369 Binder.restoreCallingIdentity(identity);
11370 }
11371 }
11372
11373 /**
11374 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11375 * device does not have an active PUBLISH.
11376 */
11377 // Used for SHELL command only right now.
11378 @Override
11379 public String getLastUcePidfXmlShell(int subId) {
11380 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11381 final long identity = Binder.clearCallingIdentity();
11382 try {
11383 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11384 } catch (ImsException e) {
11385 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11386 } finally {
11387 Binder.restoreCallingIdentity(identity);
11388 }
11389 }
11390
James.cf Line8713a42021-04-29 16:04:26 +080011391 /**
11392 * Remove UCE requests cannot be sent to the network status.
11393 */
11394 // Used for SHELL command only right now.
11395 @Override
11396 public boolean removeUceRequestDisallowedStatus(int subId) {
11397 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11398 final long identity = Binder.clearCallingIdentity();
11399 try {
11400 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11401 } catch (ImsException e) {
11402 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11403 } finally {
11404 Binder.restoreCallingIdentity(identity);
11405 }
11406 }
11407
James.cf Lin18bb9002021-05-25 01:37:38 +080011408 /**
11409 * Remove UCE requests cannot be sent to the network status.
11410 */
11411 // Used for SHELL command only.
11412 @Override
11413 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11414 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11415 final long identity = Binder.clearCallingIdentity();
11416 try {
11417 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11418 } catch (ImsException e) {
11419 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11420 } finally {
11421 Binder.restoreCallingIdentity(identity);
11422 }
11423 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011424
James.cf Lin4b784aa2021-01-31 03:25:15 +080011425 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011426 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11427 String callingPackage) {
11428 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11429 mApp, subId, "setSignalStrengthUpdateRequest");
11430
11431 final int callingUid = Binder.getCallingUid();
11432 // Verify that tha callingPackage belongs to the calling UID
11433 mApp.getSystemService(AppOpsManager.class)
11434 .checkPackage(callingUid, callingPackage);
11435
Rambo Wang3607f502021-02-01 21:51:40 -080011436 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011437
11438 final long identity = Binder.clearCallingIdentity();
11439 try {
11440 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11441 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11442
11443 if (result instanceof IllegalStateException) {
11444 throw (IllegalStateException) result;
11445 }
11446 } finally {
11447 Binder.restoreCallingIdentity(identity);
11448 }
11449 }
11450
11451 @Override
11452 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11453 String callingPackage) {
11454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11455 mApp, subId, "clearSignalStrengthUpdateRequest");
11456
11457 final int callingUid = Binder.getCallingUid();
11458 // Verify that tha callingPackage belongs to the calling UID
11459 mApp.getSystemService(AppOpsManager.class)
11460 .checkPackage(callingUid, callingPackage);
11461
11462 final long identity = Binder.clearCallingIdentity();
11463 try {
11464 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11465 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11466
11467 if (result instanceof IllegalStateException) {
11468 throw (IllegalStateException) result;
11469 }
11470 } finally {
11471 Binder.restoreCallingIdentity(identity);
11472 }
11473 }
11474
Rambo Wang3607f502021-02-01 21:51:40 -080011475 private static void validateSignalStrengthUpdateRequest(Context context,
11476 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011477 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11478 // phone/system process do not have further restriction on request
11479 return;
11480 }
11481
11482 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011483 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011484 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011485 context.enforceCallingOrSelfPermission(
11486 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11487 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011488 }
11489
11490 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011491 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011492 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011493 || info.isEnabled()) {
11494 throw new IllegalArgumentException(
11495 "Only system can set hide fields in SignalThresholdInfo");
11496 }
11497
11498 // Thresholds length for each RAN need in range. This has been validated in
11499 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11500 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11501 final int[] thresholds = info.getThresholds();
11502 Objects.requireNonNull(thresholds);
11503 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11504 || thresholds.length
11505 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11506 throw new IllegalArgumentException(
11507 "thresholds length is out of range: " + thresholds.length);
11508 }
11509 }
11510 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011511
11512 /**
11513 * Gets the current phone capability.
11514 *
11515 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11516 * @return the PhoneCapability which describes the data connection capability of modem.
11517 * It's used to evaluate possible phone config change, for example from single
11518 * SIM device to multi-SIM device.
11519 */
11520 @Override
11521 public PhoneCapability getPhoneCapability() {
11522 enforceReadPrivilegedPermission("getPhoneCapability");
11523 final long identity = Binder.clearCallingIdentity();
11524 try {
11525 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11526 } finally {
11527 Binder.restoreCallingIdentity(identity);
11528 }
11529 }
Michele Berionne5e411512020-11-13 02:36:59 +000011530
11531 /**
11532 * Prepare TelephonyManager for an unattended reboot. The reboot is
11533 * required to be done shortly after the API is invoked.
11534 */
11535 @Override
11536 @TelephonyManager.PrepareUnattendedRebootResult
11537 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011538 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011539 enforceRebootPermission();
11540
11541 final long identity = Binder.clearCallingIdentity();
11542 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011543 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011544 } finally {
11545 Binder.restoreCallingIdentity(identity);
11546 }
11547 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011548
11549 /**
11550 * Request to get the current slicing configuration including URSP rules and
11551 * NSSAIs (configured, allowed and rejected).
11552 *
11553 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11554 */
11555 @Override
11556 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011557 TelephonyPermissions
11558 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11559 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011560
11561 final long identity = Binder.clearCallingIdentity();
11562 try {
11563 Phone phone = getDefaultPhone();
11564 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11565 } finally {
11566 Binder.restoreCallingIdentity(identity);
11567 }
11568 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011569
11570 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011571 * Check whether the given premium capability is available for purchase from the carrier.
11572 *
11573 * @param capability The premium capability to check.
11574 * @param subId The subId to check the premium capability for.
11575 *
11576 * @return Whether the given premium capability is available to purchase.
11577 */
11578 @Override
11579 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11580 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11581 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11582 log("Premium capability "
11583 + TelephonyManager.convertPremiumCapabilityToString(capability)
11584 + " is not available for purchase due to missing permissions.");
11585 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11586 + "permission READ_BASIC_PHONE_STATE.");
11587 }
11588
11589 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011590 if (phone == null) {
11591 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11592 return false;
11593 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011594 final long identity = Binder.clearCallingIdentity();
11595 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011596 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011597 .isPremiumCapabilityAvailableForPurchase(capability);
11598 } finally {
11599 Binder.restoreCallingIdentity(identity);
11600 }
11601 }
11602
11603 /**
11604 * Purchase the given premium capability from the carrier.
11605 *
11606 * @param capability The premium capability to purchase.
11607 * @param callback The result of the purchase request.
11608 * @param subId The subId to purchase the premium capability for.
11609 */
11610 @Override
11611 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11612 log("purchasePremiumCapability: capability="
11613 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11614 + getCurrentPackageName());
11615
11616 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11617 mApp, "purchasePremiumCapability")) {
11618 log("purchasePremiumCapability "
11619 + TelephonyManager.convertPremiumCapabilityToString(capability)
11620 + " failed due to missing permissions.");
11621 throw new SecurityException("purchasePremiumCapability requires permission "
11622 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011623 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
11624 mApp, "purchasePremiumCapability")) {
11625 log("purchasePremiumCapability "
11626 + TelephonyManager.convertPremiumCapabilityToString(capability)
11627 + " failed due to missing permissions.");
11628 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070011629 }
11630
11631 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011632 if (phone == null) {
11633 try {
11634 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11635 callback.accept(result);
11636 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11637 } catch (RemoteException e) {
11638 String logStr = "Purchase premium capability "
11639 + TelephonyManager.convertPremiumCapabilityToString(capability)
11640 + " failed due to RemoteException handling null phone: " + e;
11641 if (DBG) log(logStr);
11642 AnomalyReporter.reportAnomaly(
11643 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11644 }
11645 return;
11646 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011647
11648 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070011649 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011650 callingProcess = mApp.getPackageManager().getApplicationInfo(
11651 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070011652 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011653 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070011654 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011655
11656 boolean isVisible = false;
11657 ActivityManager am = mApp.getSystemService(ActivityManager.class);
11658 if (am != null) {
11659 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
11660 if (processes != null) {
11661 for (ActivityManager.RunningAppProcessInfo process : processes) {
11662 log("purchasePremiumCapability: process " + process.processName
11663 + "has importance " + process.importance);
11664 if (process.processName.equals(callingProcess) && process.importance
11665 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
11666 isVisible = true;
11667 break;
11668 }
11669 }
11670 }
11671 }
11672
11673 if (!isVisible) {
11674 try {
11675 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
11676 callback.accept(result);
11677 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
11678 } catch (RemoteException e) {
11679 String logStr = "Purchase premium capability "
11680 + TelephonyManager.convertPremiumCapabilityToString(capability)
11681 + " failed due to RemoteException handling background application: " + e;
11682 if (DBG) log(logStr);
11683 AnomalyReporter.reportAnomaly(
11684 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11685 }
11686 return;
11687 }
11688
Sarah Chin71b3a852022-09-28 15:54:19 -070011689 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080011690 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011691 }
11692
11693 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011694 * Register an IMS connection state callback
11695 */
11696 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011697 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11698 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011699 if (feature == ImsFeature.FEATURE_MMTEL) {
11700 // ImsMmTelManager
11701 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11702 TelephonyPermissions
11703 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11704 mApp, subId, "registerImsStateCallback");
11705 } else if (feature == ImsFeature.FEATURE_RCS) {
11706 // ImsRcsManager or SipDelegateManager
11707 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11708 Binder.getCallingUid(), "registerImsStateCallback",
11709 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11710 Manifest.permission.READ_PRECISE_PHONE_STATE,
11711 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11712 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11713 }
11714
11715 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11716 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11717 "IMS not available on device.");
11718 }
11719
11720 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11721 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11722 }
11723
11724 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11725 if (controller == null) {
11726 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11727 "IMS not available on device.");
11728 }
11729
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011730 if (callingPackage == null) {
11731 callingPackage = getCurrentPackageName();
11732 }
11733
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011734 final long token = Binder.clearCallingIdentity();
11735 try {
11736 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011737 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011738 } catch (ImsException e) {
11739 throw new ServiceSpecificException(e.getCode());
11740 } finally {
11741 Binder.restoreCallingIdentity(token);
11742 }
11743 }
11744
11745 /**
11746 * Unregister an IMS connection state callback
11747 */
11748 @Override
11749 public void unregisterImsStateCallback(IImsStateCallback cb) {
11750 final long token = Binder.clearCallingIdentity();
11751 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11752 if (controller == null) {
11753 return;
11754 }
11755 try {
11756 controller.unregisterImsStateCallback(cb);
11757 } finally {
11758 Binder.restoreCallingIdentity(token);
11759 }
11760 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011761
11762 /**
11763 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11764 *
11765 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11766 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11767 * SecurityException.
11768 * If there is current registered network this value will be same as the registered cell
11769 * identity. If the device goes out of service the previous cell identity is cached and
11770 * will be returned. If the cache age of the Cell identity is more than 24 hours
11771 * it will be cleared and null will be returned.
11772 *
11773 */
11774 @Override
11775 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11776 String callingFeatureId) {
11777 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11778 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11779 LocationAccessPolicy.checkLocationPermission(mApp,
11780 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11781 .setCallingPackage(callingPackage)
11782 .setCallingFeatureId(callingFeatureId)
11783 .setCallingPid(Binder.getCallingPid())
11784 .setCallingUid(Binder.getCallingUid())
11785 .setMethod("getLastKnownCellIdentity")
11786 .setLogAsInfo(true)
11787 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11788 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11789 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11790 .build());
11791
11792 boolean hasFinePermission =
11793 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11794 if (!hasFinePermission
11795 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11796 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011797 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011798 }
11799
11800 final long identity = Binder.clearCallingIdentity();
11801 try {
11802 Phone phone = getPhone(subId);
11803 if (phone == null) return null;
11804 ServiceStateTracker sst = phone.getServiceStateTracker();
11805 if (sst == null) return null;
11806 return sst.getLastKnownCellIdentity();
11807 } finally {
11808 Binder.restoreCallingIdentity(identity);
11809 }
11810 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011811
jimsun3b9ccac2021-10-26 15:01:23 +080011812 /**
11813 * Sets the modem service class Name that Telephony will bind to.
11814 *
11815 * @param serviceName The class name of the modem service.
11816 * @return true if the operation is succeed, otherwise false.
11817 */
11818 public boolean setModemService(String serviceName) {
11819 Log.d(LOG_TAG, "setModemService - " + serviceName);
11820 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11821 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011822 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11823 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080011824 return mPhoneConfigurationManager.setModemService(serviceName);
11825 }
11826
11827 /**
11828 * Return the class name of the currently bounded modem service.
11829 *
11830 * @return the class name of the modem service.
11831 */
11832 public String getModemService() {
11833 String result;
11834 Log.d(LOG_TAG, "getModemService");
11835 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11836 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011837 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080011838 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11839 "getModemService");
11840 result = mPhoneConfigurationManager.getModemService();
11841 Log.d(LOG_TAG, "result = " + result);
11842 return result;
11843 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011844
11845 @Override
11846 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11847 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11848 mApp.enforceCallingOrSelfPermission(
11849 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11850 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11851
11852 final long identity = Binder.clearCallingIdentity();
11853 try {
11854 Phone phone = getPhone(subId);
11855 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080011856 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
11857 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011858 phone.setVoiceServiceStateOverride(hasService);
11859 } finally {
11860 Binder.restoreCallingIdentity(identity);
11861 }
11862 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011863
11864 /**
11865 * set removable eSIM as default eUICC.
11866 *
11867 * @hide
11868 */
11869 @Override
11870 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11871 enforceModifyPermission();
11872 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11873
11874 final long identity = Binder.clearCallingIdentity();
11875 try {
11876 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11877 } finally {
11878 Binder.restoreCallingIdentity(identity);
11879 }
11880 }
11881
11882 /**
11883 * Returns whether the removable eSIM is default eUICC or not.
11884 *
11885 * @hide
11886 */
11887 @Override
11888 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11889 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11890 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11891
11892 final long identity = Binder.clearCallingIdentity();
11893 try {
11894 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11895 } finally {
11896 Binder.restoreCallingIdentity(identity);
11897 }
11898 }
11899
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011900 /**
11901 * Get the component name of the default app to direct respond-via-message intent for the
11902 * user associated with this subscription, update the cache if there is no respond-via-message
11903 * application currently configured for this user.
11904 * @return component name of the app and class to direct Respond Via Message intent to, or
11905 * {@code null} if the functionality is not supported.
11906 * @hide
11907 */
11908 @Override
11909 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11910 boolean updateIfNeeded) {
11911 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011912
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000011913 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
11914
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011915 UserHandle userHandle = null;
11916 final long identity = Binder.clearCallingIdentity();
11917 try {
11918 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11919 } finally {
11920 Binder.restoreCallingIdentity(identity);
11921 }
11922 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11923 updateIfNeeded, userHandle);
11924 }
Jack Yuf5badd92022-12-08 00:50:53 -080011925
11926 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011927 * Set whether the device is able to connect with null ciphering or integrity
11928 * algorithms. This is a global setting and will apply to all active subscriptions
11929 * and all new subscriptions after this.
11930 *
11931 * @param enabled when true, null cipher and integrity algorithms are allowed.
11932 * @hide
11933 */
11934 @Override
11935 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11936 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11937 enforceModifyPermission();
11938 checkForNullCipherAndIntegritySupport();
11939
11940 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11941 // for listening to these preference changes and applying them immediately.
11942 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11943 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11944 editor.apply();
11945
11946 for (Phone phone: PhoneFactory.getPhones()) {
11947 phone.handleNullCipherEnabledChange();
11948 }
11949 }
11950
11951
11952 /**
11953 * Get whether the device is able to connect with null ciphering or integrity
11954 * algorithms. Note that this retrieves the phone-global preference and not
11955 * the state of the radio.
11956 *
11957 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11958 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11959 * version for this feature.
11960 * @hide
11961 */
11962 @Override
11963 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11964 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11965 enforceReadPermission();
11966 checkForNullCipherAndIntegritySupport();
11967 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11968 }
11969
11970 private void checkForNullCipherAndIntegritySupport() {
11971 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11972 throw new UnsupportedOperationException(
11973 "Null cipher and integrity operations require HAL 2.1 or above");
11974 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000011975 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
11976 throw new UnsupportedOperationException(
11977 "Null cipher and integrity operations unsupported by modem");
11978 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011979 }
11980
11981 /**
Jack Yuf5badd92022-12-08 00:50:53 -080011982 * Get the SIM state for the slot index.
11983 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11984 *
11985 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11986 */
11987 @Override
11988 @SimState
11989 public int getSimStateForSlotIndex(int slotIndex) {
11990 IccCardConstants.State simState;
11991 if (slotIndex < 0) {
11992 simState = IccCardConstants.State.UNKNOWN;
11993 } else {
11994 Phone phone = null;
11995 try {
11996 phone = PhoneFactory.getPhone(slotIndex);
11997 } catch (IllegalStateException e) {
11998 // ignore
11999 }
12000 if (phone == null) {
12001 simState = IccCardConstants.State.UNKNOWN;
12002 } else {
12003 IccCard icc = phone.getIccCard();
12004 if (icc == null) {
12005 simState = IccCardConstants.State.UNKNOWN;
12006 } else {
12007 simState = icc.getState();
12008 }
12009 }
12010 }
12011 return simState.ordinal();
12012 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012013
12014 /**
12015 * Get current cell broadcast ranges.
12016 */
12017 @Override
12018 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12019 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12020 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12021 "getCellBroadcastIdRanges");
12022 final long identity = Binder.clearCallingIdentity();
12023 try {
12024 return getPhone(subId).getCellBroadcastIdRanges();
12025 } finally {
12026 Binder.restoreCallingIdentity(identity);
12027 }
12028 }
12029
12030 /**
12031 * Set reception of cell broadcast messages with the list of the given ranges
12032 *
12033 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12034 */
12035 @Override
12036 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12037 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12038 @Nullable IIntegerConsumer callback) {
12039 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12040 "setCellBroadcastIdRanges");
12041 final long identity = Binder.clearCallingIdentity();
12042 try {
12043 Phone phone = getPhoneFromSubId(subId);
12044 if (DBG) {
12045 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12046 }
12047 phone.setCellBroadcastIdRanges(ranges, result -> {
12048 if (callback != null) {
12049 try {
12050 callback.accept(result);
12051 } catch (RemoteException e) {
12052 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12053 }
12054 }
12055 });
12056 } finally {
12057 Binder.restoreCallingIdentity(identity);
12058 }
12059 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012060
12061 /**
12062 * Returns whether the device supports the domain selection service.
12063 *
12064 * @return {@code true} if the device supports the domain selection service.
12065 */
12066 @Override
12067 public boolean isDomainSelectionSupported() {
12068 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12069 "isDomainSelectionSupported");
12070
12071 final long identity = Binder.clearCallingIdentity();
12072 try {
12073 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12074 } finally {
12075 Binder.restoreCallingIdentity(identity);
12076 }
12077 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012078
12079 /**
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012080 * Request to enable or disable the satellite modem. If the satellite modem is enabled, this
12081 * will also disable the cellular modem, and if the satellite modem is disabled, this will also
12082 * re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012083 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012084 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012085 * @param enable {@code true} to enable the satellite modem and {@code false} to disable.
12086 * @param callback The callback to get the error code of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012087 *
12088 * @throws SecurityException if the caller doesn't have the required permission.
12089 */
12090 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012091 public void requestSatelliteEnabled(
12092 int subId, boolean enable, @NonNull IIntegerConsumer callback) {
12093 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012094 mSatelliteController.requestSatelliteEnabled(subId, enable, callback);
Sarah Chin503828c2023-02-01 23:54:20 -080012095 }
12096
12097 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012098 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012099 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012100 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012101 * @param result The result receiver that returns whether the satellite modem is enabled
12102 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012103 *
12104 * @throws SecurityException if the caller doesn't have the required permission.
12105 */
12106 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012107 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12108 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012109 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012110 }
12111
12112 /**
Sarah Chin43457982023-02-15 17:50:38 -080012113 * Request to enable or disable the satellite service demo mode.
12114 *
12115 * @param subId The subId of the subscription to set the satellite demo mode enabled for.
12116 * @param enable {@code true} to enable the satellite demo mode and {@code false} to disable.
12117 * @param callback The callback to get the error code of the request.
12118 *
12119 * @throws SecurityException if the caller doesn't have the required permission.
12120 */
12121 @Override
12122 public void requestSatelliteDemoModeEnabled(
12123 int subId, boolean enable, @NonNull IIntegerConsumer callback) {
12124 enforceSatelliteCommunicationPermission("requestSatelliteDemoModeEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012125 mSatelliteController.requestSatelliteDemoModeEnabled(subId, enable, callback);
Sarah Chin43457982023-02-15 17:50:38 -080012126 }
12127
12128 /**
12129 * Request to get whether the satellite service demo mode is enabled.
12130 *
12131 * @param subId The subId of the subscription to check whether the satellite demo mode
12132 * is enabled for.
12133 * @param result The result receiver that returns whether the satellite demo mode is enabled
12134 * if the request is successful or an error code if the request failed.
12135 *
12136 * @throws SecurityException if the caller doesn't have the required permission.
12137 */
12138 @Override
12139 public void requestIsSatelliteDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
12140 enforceSatelliteCommunicationPermission("requestIsSatelliteDemoModeEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012141 mSatelliteController.requestIsSatelliteDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080012142 }
12143
12144 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012145 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012146 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012147 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012148 * @param result The result receiver that returns whether the satellite service is supported on
12149 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012150 */
12151 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012152 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012153 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012154 }
12155
12156 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012157 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012158 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012159 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012160 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12161 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012162 *
12163 * @throws SecurityException if the caller doesn't have required permission.
12164 */
12165 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012166 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12167 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012168 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012169 }
12170
12171 /**
Sarah Chineccfbd12023-01-20 19:00:35 -080012172 * Start receiving satellite position updates.
12173 * This can be called by the pointing UI when the user starts pointing to the satellite.
12174 * Modem should continue to report the pointing input as the device or satellite moves.
12175 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012176 * @param subId The subId of the subscription to start satellite position updates for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012177 * @param errorCallback The callback to get the error code of the request.
Sarah Chineccfbd12023-01-20 19:00:35 -080012178 * @param callback The callback to notify of changes in satellite position.
Sarah Chin503828c2023-02-01 23:54:20 -080012179 *
12180 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012181 */
12182 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012183 public void startSatellitePositionUpdates(int subId, @NonNull IIntegerConsumer errorCallback,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012184 @NonNull ISatellitePositionUpdateCallback callback) {
Sarah Chinf75afa72023-02-01 01:32:19 -080012185 enforceSatelliteCommunicationPermission("startSatellitePositionUpdates");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012186 mSatelliteController.startSatellitePositionUpdates(subId, errorCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080012187 }
12188
12189 /**
12190 * Stop receiving satellite position updates.
12191 * This can be called by the pointing UI when the user stops pointing to the satellite.
12192 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012193 * @param subId The subId of the subscription to stop satellite position updates for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012194 * @param errorCallback The callback to get the error code of the request.
12195 * @param callback The callback that was passed to {@link
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012196 * #startSatellitePositionUpdates(int, IIntegerConsumer, ISatellitePositionUpdateCallback)}
Sarah Chin503828c2023-02-01 23:54:20 -080012197 *
12198 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012199 */
12200 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012201 public void stopSatellitePositionUpdates(int subId, @NonNull IIntegerConsumer errorCallback,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012202 @NonNull ISatellitePositionUpdateCallback callback) {
Sarah Chinf75afa72023-02-01 01:32:19 -080012203 enforceSatelliteCommunicationPermission("stopSatellitePositionUpdates");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012204 mSatelliteController.stopSatellitePositionUpdates(subId, errorCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080012205 }
12206
12207 /**
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012208 * Request to get the maximum number of bytes per datagram that can be sent to satellite.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012209 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012210 * @param subId The subId of the subscription to get the maximum number of characters for.
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012211 * @param result The result receiver that returns the maximum number of bytes per datagram
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012212 * message on satellite if the request is successful or an error code
12213 * if the request failed.
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012214 *
12215 * @throws SecurityException if the caller doesn't have the required permission.
12216 */
12217 @Override
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012218 public void requestMaxSizePerSendingDatagram(int subId,
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012219 @NonNull ResultReceiver result) {
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012220 enforceSatelliteCommunicationPermission("requestMaxSizePerSendingDatagram");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012221 mSatelliteController.requestMaxSizePerSendingDatagram(subId, result);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012222 }
12223
12224 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012225 * Register the subscription with a satellite provider.
12226 * This is needed to register the subscription if the provider allows dynamic registration.
12227 *
12228 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012229 * @param token The token to be used as a unique identifier for provisioning with satellite
12230 * gateway.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012231 * @param callback The callback to get the error code of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012232 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012233 * @return The signal transport used by the caller to cancel the provision request,
12234 * or {@code null} if the request failed.
12235 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012236 * @throws SecurityException if the caller doesn't have the required permission.
12237 */
12238 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012239 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
12240 @NonNull String token, @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012241 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012242 return mSatelliteController.provisionSatelliteService(subId, token, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012243 }
12244
12245 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012246 * Unregister the device/subscription with the satellite provider.
12247 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012248 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012249 * should report as deprovisioned.
12250 *
12251 * @param subId The subId of the subscription to be deprovisioned.
12252 * @param token The token of the device/subscription to be deprovisioned.
12253 * @param callback The callback to get the error code of the request.
12254 *
12255 * @throws SecurityException if the caller doesn't have the required permission.
12256 */
12257 @Override
12258 public void deprovisionSatelliteService(int subId,
12259 @NonNull String token, @NonNull IIntegerConsumer callback) {
12260 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012261 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012262 }
12263
12264 /**
Sarah Chin43457982023-02-15 17:50:38 -080012265 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012266 *
Sarah Chin43457982023-02-15 17:50:38 -080012267 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012268 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012269 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012270 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12271 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012272 * @throws SecurityException if the caller doesn't have the required permission.
12273 */
12274 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080012275 @SatelliteManager.SatelliteError public int registerForSatelliteProvisionStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012276 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012277 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012278 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012279 }
12280
12281 /**
Sarah Chin43457982023-02-15 17:50:38 -080012282 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012283 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012284 *
Sarah Chin43457982023-02-15 17:50:38 -080012285 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012286 * @param callback The callback that was passed to
12287 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012288 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012289 * @throws SecurityException if the caller doesn't have the required permission.
12290 */
12291 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012292 public void unregisterForSatelliteProvisionStateChanged(
12293 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012294 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012295 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012296 }
12297
12298 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012299 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012300 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012301 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012302 * @param result The result receiver that returns whether the device is provisioned with a
12303 * satellite provider if the request is successful or an error code if the
12304 * request failed.
12305 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012306 * @throws SecurityException if the caller doesn't have the required permission.
12307 */
12308 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012309 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
12310 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012311 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012312 }
12313
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012314 /**
Sarah Chin43457982023-02-15 17:50:38 -080012315 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012316 *
Sarah Chin43457982023-02-15 17:50:38 -080012317 * @param subId The subId of the subscription to register for satellite modem state changed.
12318 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080012319 *
12320 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12321 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012322 * @throws SecurityException if the caller doesn't have the required permission.
12323 */
12324 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012325 @SatelliteManager.SatelliteError public int registerForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012326 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012327 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012328 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012329 }
12330
12331 /**
Sarah Chin43457982023-02-15 17:50:38 -080012332 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012333 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012334 *
Sarah Chin43457982023-02-15 17:50:38 -080012335 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080012336 * @param callback The callback that was passed to
Sarah Chin43457982023-02-15 17:50:38 -080012337 * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012338 *
12339 * @throws SecurityException if the caller doesn't have the required permission.
12340 */
12341 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012342 public void unregisterForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012343 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012344 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012345 mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012346 }
12347
12348 /**
12349 * Register to receive incoming datagrams over satellite.
12350 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012351 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012352 * @param datagramType datagram type indicating whether the datagram is of type
12353 * SOS_SMS or LOCATION_SHARING.
Sarah Chindf715ec2023-02-13 13:46:24 -080012354 * @param callback The callback to handle incoming datagrams over satellite.
12355 *
12356 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12357 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012358 * @throws SecurityException if the caller doesn't have the required permission.
12359 */
12360 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080012361 @SatelliteManager.SatelliteError public int registerForSatelliteDatagram(int subId,
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012362 @SatelliteManager.DatagramType int datagramType,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012363 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012364 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012365 return mSatelliteController.registerForSatelliteDatagram(subId, datagramType, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012366 }
12367
12368 /**
12369 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012370 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012371 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012372 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
12373 * @param callback The callback that was passed to
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012374 * {@link #registerForSatelliteDatagram(int, int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012375 *
12376 * @throws SecurityException if the caller doesn't have the required permission.
12377 */
12378 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012379 public void unregisterForSatelliteDatagram(int subId,
12380 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012381 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012382 mSatelliteController.unregisterForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012383 }
12384
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012385 /**
12386 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012387 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012388 * This method requests modem to check if there are any pending datagrams to be received over
12389 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012390 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int,
12391 * ISatelliteDatagramReceiverAck)}
Sarah Chindf715ec2023-02-13 13:46:24 -080012392 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012393 * @param subId The subId of the subscription used for receiving datagrams.
12394 * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012395 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012396 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012397 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012398 @Override
12399 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012400 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012401 mSatelliteController.pollPendingSatelliteDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012402 }
12403
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012404 /**
12405 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012406 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012407 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
12408 * input to this method. Datagram received here will be passed down to modem without any
12409 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080012410 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012411 * @param subId The subId of the subscription to send satellite datagrams for.
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012412 * @param datagramId An id that uniquely identifies datagram requested to be sent.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012413 * @param datagramType datagram type indicating whether the datagram is of type
12414 * SOS_SMS or LOCATION_SHARING.
12415 * @param datagram encoded gateway datagram which is encrypted by the caller.
12416 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000012417 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
12418 * full screen mode.
12419 * @param result The result receiver that returns datagramId if datagram is sent successfully
12420 * or {@link SatelliteManager.SatelliteError} of the request if it is failed.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012421 *
12422 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012423 */
12424 @Override
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012425 public void sendSatelliteDatagram(int subId, long datagramId,
12426 @SatelliteManager.DatagramType int datagramType, SatelliteDatagram datagram,
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000012427 boolean needFullScreenPointingUI, @NonNull ResultReceiver result) {
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012428 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012429 mSatelliteController.sendSatelliteDatagram(subId, datagramId, datagramType, datagram,
12430 needFullScreenPointingUI, result);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012431 }
12432
Sarah Chindf715ec2023-02-13 13:46:24 -080012433 /**
12434 * Request to get whether satellite communication is allowed for the current location.
12435 *
12436 * @param subId The subId of the subscription to check whether satellite communication is
12437 * allowed for the current location for.
12438 * @param result The result receiver that returns whether satellite communication is allowed
12439 * for the current location if the request is successful or an error code
12440 * if the request failed.
12441 *
12442 * @throws SecurityException if the caller doesn't have the required permission.
12443 */
12444 @Override
12445 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
12446 @NonNull ResultReceiver result) {
12447 enforceSatelliteCommunicationPermission(
12448 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012449 mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId,
12450 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080012451 }
12452
12453 /**
Sarah Chin5f57c582023-02-14 04:16:10 -080012454 * Request to get the time after which the satellite will be visible
Sarah Chindf715ec2023-02-13 13:46:24 -080012455 *
Sarah Chin5f57c582023-02-14 04:16:10 -080012456 * @param subId The subId to get the time after which the satellite will be visible for.
12457 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080012458 * be visible if the request is successful or an error code if the request failed.
12459 *
12460 * @throws SecurityException if the caller doesn't have the required permission.
12461 */
12462 @Override
12463 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
12464 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012465 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012466 }
12467
12468 private Phone getPhoneOrDefault(int subId, String caller) {
12469 Phone phone = getPhone(subId);
12470 if (phone == null) {
12471 loge(caller + " called with invalid subId: " + subId
12472 + ". Retrying with default phone.");
12473 phone = getDefaultPhone();
12474 if (phone == null) {
12475 loge(caller + " failed with no phone object.");
12476 }
12477 }
12478 return phone;
12479 }
12480
12481 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000012482 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
12483 *
12484 * <p>This method behaves in one of the following ways:
12485 * <ul>
12486 * <li>return true : if the calling package has the appop permission {@link
12487 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
12488 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
12489 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
12490 * Owner device identifier access check, or the calling package has carrier privileges</>
12491 * <li>throw SecurityException: if the caller does not meet any of the requirements.
12492 * </ul>
12493 */
12494 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
12495 String callingPackage, @Nullable String callingFeatureId, String message) {
12496 for (Phone phone : PhoneFactory.getPhones()) {
12497 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
12498 phone.getSubId(), callingPackage, callingFeatureId, message)) {
12499 return true;
12500 }
12501 }
12502 return false;
12503 }
arunvoddud7401012022-12-15 16:08:12 +000012504
12505 /**
Jack Yufa8ed012023-02-11 15:42:28 -080012506 * @return The subscription manager service instance.
12507 */
12508 public SubscriptionManagerService getSubscriptionManagerService() {
12509 return SubscriptionManagerService.getInstance();
12510 }
12511
12512 /**
arunvoddud7401012022-12-15 16:08:12 +000012513 * Class binds the consumer[callback] and carrierId.
12514 */
12515 private static class CallerCallbackInfo {
12516 private final Consumer<Integer> mConsumer;
12517 private final int mCarrierId;
12518
12519 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
12520 mConsumer = consumer;
12521 mCarrierId = carrierId;
12522 }
12523
12524 public Consumer<Integer> getConsumer() {
12525 return mConsumer;
12526 }
12527
12528 public int getCarrierId() {
12529 return mCarrierId;
12530 }
12531 }
Jack Yufa8ed012023-02-11 15:42:28 -080012532}