blob: d9dd3bfee423c77d1a005aba162fd2a4e3158f6f [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000020import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080021import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Hall Liud892bec2018-11-30 14:51:45 -080022
Shuo Qianccbaf742021-02-22 18:32:21 -080023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
24import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070025import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000027import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070028
Brad Ebinger34c09a52021-02-17 23:23:21 +000029import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080030import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080031import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070032import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000033import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080034import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080036import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070037import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000038import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080039import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000040import android.compat.annotation.ChangeId;
41import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070042import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070043import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.content.Context;
45import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070046import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070047import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070048import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.net.Uri;
50import android.os.AsyncResult;
51import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080052import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.Bundle;
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080054import android.os.DropBoxManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070056import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080057import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080058import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import android.os.Looper;
60import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070061import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080062import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070063import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070064import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080065import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080066import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070067import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070068import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080069import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070071import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070072import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070073import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070074import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080075import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070076import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000077import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090078import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080079import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080080import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070081import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080082import android.telephony.AccessNetworkConstants;
83import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070084import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070085import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080086import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070087import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080088import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070089import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080090import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -060091import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -070092import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080093import android.telephony.CellIdentityCdma;
94import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070096import android.telephony.CellInfoGsm;
97import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070098import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080099import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700100import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700101import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700102import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800103import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700104import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800105import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700106import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800107import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800108import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700109import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800110import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800112import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800113import android.telephony.SignalStrengthUpdateRequest;
114import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800115import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800117import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700118import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700119import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800120import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800121import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800122import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800123import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000124import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000125import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000126import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700127import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700128import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800129import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800130import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700131import android.telephony.gba.GbaAuthRequest;
132import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700133import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800134import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000135import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000136import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700137import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000138import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700139import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800140import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700141import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800142import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700143import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000144import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700145import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800146import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800147import android.telephony.ims.stub.ImsRegistrationImplBase;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800148import android.telephony.satellite.ISatelliteDatagramCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800149import android.telephony.satellite.ISatelliteProvisionStateCallback;
150import android.telephony.satellite.ISatelliteStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800151import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800152import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000153import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800154import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800155import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800156import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800158import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700159import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700160import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800161import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800162
Andrew Lee312e8172014-10-23 17:01:36 -0700163import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800164import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800165import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800166import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800167import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700168import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700169import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700170import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800171import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800172import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700173import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700174import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800175import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700176import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800177import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800178import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800179import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700180import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000181import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700182import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800183import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700184import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800185import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800186import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800187import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700188import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700189import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700190import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700192import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800193import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700194import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700195import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700196import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700197import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800198import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800199import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700200import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000201import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700202import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700203import com.android.internal.telephony.SmsPermissions;
Peter Wang59571be2020-01-27 12:35:15 +0800204import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800205import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700206import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000207import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800208import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700209import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800210import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700211import com.android.internal.telephony.imsphone.ImsPhone;
212import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000213import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800214import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000215import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800216import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
217import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700218import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700219import com.android.internal.telephony.uicc.IccIoResult;
220import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800221import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700222import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800223import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700224import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000225import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800226import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000227import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800228import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000229import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700230import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700231import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800232import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800233import com.android.phone.callcomposer.CallComposerPictureManager;
234import com.android.phone.callcomposer.CallComposerPictureTransfer;
235import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700236import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700237import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000238import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700239import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800240import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700241import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700242import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800243import com.android.services.telephony.TelecomAccountRegistry;
244import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800245import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800246
Hall Liu82694d52020-12-11 18:22:04 -0800247import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700248import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800249import java.io.IOException;
250import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700251import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700252import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800253import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000254import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800255import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800256import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800257import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800258import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100259import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800260import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700261import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800262import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800263import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700264import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800265import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800266import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800267import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700268
269/**
270 * Implementation of the ITelephony interface.
271 */
Santos Cordon117fee72014-05-16 17:56:12 -0700272public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700273 private static final String LOG_TAG = "PhoneInterfaceManager";
274 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
275 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800276 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700277
278 // Message codes used with mMainThreadHandler
279 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700280 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
281 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700282 private static final int CMD_OPEN_CHANNEL = 9;
283 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
284 private static final int CMD_CLOSE_CHANNEL = 11;
285 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800286 private static final int CMD_NV_READ_ITEM = 13;
287 private static final int EVENT_NV_READ_ITEM_DONE = 14;
288 private static final int CMD_NV_WRITE_ITEM = 15;
289 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
290 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
291 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700292 private static final int CMD_RESET_MODEM_CONFIG = 19;
293 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800294 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
295 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800296 private static final int CMD_SEND_ENVELOPE = 25;
297 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000298 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
299 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700300 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
301 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
302 private static final int CMD_EXCHANGE_SIM_IO = 31;
303 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800304 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
305 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700306 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
307 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700308 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
309 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700310 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
311 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
312 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
313 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700314 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
315 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
316 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
317 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700318 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800319 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
320 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000321 private static final int CMD_SWITCH_SLOTS = 50;
322 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700323 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
324 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
325 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
326 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
327 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
328 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
329 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
330 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700331 private static final int CMD_GET_ALL_CELL_INFO = 60;
332 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
333 private static final int CMD_GET_CELL_LOCATION = 62;
334 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700335 private static final int CMD_MODEM_REBOOT = 64;
336 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700337 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
338 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800339 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
340 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700341 private static final int CMD_GET_MODEM_STATUS = 70;
342 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700343 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
344 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700345 private static final int CMD_ERASE_MODEM_CONFIG = 74;
346 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800347 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
348 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
349 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
350 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800351 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
352 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800353 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800354 private static final int CMD_GET_CALL_FORWARDING = 83;
355 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
356 private static final int CMD_SET_CALL_FORWARDING = 85;
357 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
358 private static final int CMD_GET_CALL_WAITING = 87;
359 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
360 private static final int CMD_SET_CALL_WAITING = 89;
361 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700362 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
363 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
364 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
365 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700366 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
367 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800368 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
369 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800370 private static final int CMD_SET_DATA_THROTTLING = 99;
371 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800372 private static final int CMD_SET_SIM_POWER = 101;
373 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800374 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
375 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
376 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
377 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800378 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
379 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000380 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800381 private static final int CMD_GET_SLICING_CONFIG = 110;
382 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800383 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700384 private static final int CMD_ENABLE_VONR = 113;
385 private static final int EVENT_ENABLE_VONR_DONE = 114;
386 private static final int CMD_IS_VONR_ENABLED = 115;
387 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700388 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
389 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000390
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800391 // Parameters of select command.
392 private static final int SELECT_COMMAND = 0xA4;
393 private static final int SELECT_P1 = 0x04;
394 private static final int SELECT_P2 = 0;
395 private static final int SELECT_P3 = 0x10;
396
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000397 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
398 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
399
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700400 /** The singleton instance. */
401 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800402 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700403
Sarah Chin4beb2b72023-02-14 14:47:54 -0800404 private final PhoneGlobals mApp;
405 private final CallManager mCM;
406 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000407
408 private final SatelliteController mSatelliteController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800409 private final UserManager mUserManager;
410 private final AppOpsManager mAppOps;
411 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800412 private final SharedPreferences mTelephonySharedPreferences;
413 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800414 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415
Peter Wangdafb9ac2020-01-15 14:13:38 -0800416 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800417 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800418 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
419
Sarah Chin4beb2b72023-02-14 14:47:54 -0800420 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800421
Derek Tan97ebb422014-09-05 16:55:38 -0700422 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
423 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800424 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800425 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700426
Michelecea4cf22018-12-21 15:00:11 -0800427 // String to store multi SIM allowed
428 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
429
Derek Tan740e1672017-06-27 14:56:27 -0700430 // The AID of ISD-R.
431 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
432
yinxub1bed742017-04-17 11:45:04 -0700433 private NetworkScanRequestTracker mNetworkScanRequestTracker;
434
David Kelly5e06a7f2018-03-12 14:10:59 +0000435 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
436 private static final int MANUFACTURER_CODE_LENGTH = 8;
437
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800438 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800439 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800440
Sarah Chin2ec39f62022-08-31 17:03:26 -0700441 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
442 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
443
Derek Tan89e89d42014-07-08 17:00:10 -0700444 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700445 * Experiment flag to enable erase modem config on reset network, default value is false
446 */
447 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
448 "reset_network_erase_modem_config_enabled";
449
Rambo Wang0f050d82021-02-12 11:43:36 -0800450 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800451
Gary Jian76280a42022-12-07 16:18:33 +0800452 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
453
sandeepjsb6c87872021-09-27 15:34:44 +0000454 /**
455 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
456 * one ICCID active at the same time.
457 * Apps should use below API signatures if targeting SDK is T and beyond.
458 *
459 * @hide
460 */
461 @ChangeId
462 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
463 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800464
Naina Nallurid63128d2019-09-17 14:10:30 -0700465 /**
Chen Xu540470b2021-12-14 17:15:47 -0800466 * Apps targeting on Android T and beyond will get exception whenever icc close channel
467 * operation fails.
468 */
469 @ChangeId
470 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
471 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
472
473 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700474 * A request object to use for transmitting data to an ICC.
475 */
476 private static final class IccAPDUArgument {
477 public int channel, cla, command, p1, p2, p3;
478 public String data;
479
480 public IccAPDUArgument(int channel, int cla, int command,
481 int p1, int p2, int p3, String data) {
482 this.channel = channel;
483 this.cla = cla;
484 this.command = command;
485 this.p1 = p1;
486 this.p2 = p2;
487 this.p3 = p3;
488 this.data = data;
489 }
490 }
491
492 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700493 * A request object to use for transmitting data to an ICC.
494 */
495 private static final class ManualNetworkSelectionArgument {
496 public OperatorInfo operatorInfo;
497 public boolean persistSelection;
498
499 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
500 this.operatorInfo = operatorInfo;
501 this.persistSelection = persistSelection;
502 }
503 }
504
Sarah Chin71b3a852022-09-28 15:54:19 -0700505 private static final class PurchasePremiumCapabilityArgument {
506 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700507 public @NonNull IIntegerConsumer callback;
508
509 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800510 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700511 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700512 this.callback = callback;
513 }
514 }
515
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700516 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700517 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
518 * request after sending. The main thread will notify the request when it is complete.
519 */
520 private static final class MainThreadRequest {
521 /** The argument to use for the request */
522 public Object argument;
523 /** The result of the request that is run on the main thread */
524 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800525 // The subscriber id that this request applies to. Defaults to
526 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
527 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700528
Nathan Harold92bed182018-10-12 18:16:49 -0700529 // In cases where subId is unavailable, the caller needs to specify the phone.
530 public Phone phone;
531
vagdeviaf9a5b92018-08-15 16:01:53 -0700532 public WorkSource workSource;
533
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700534 public MainThreadRequest(Object argument) {
535 this.argument = argument;
536 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800537
Nathan Harold92bed182018-10-12 18:16:49 -0700538 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
539 this.argument = argument;
540 if (phone != null) {
541 this.phone = phone;
542 }
543 this.workSource = workSource;
544 }
545
vagdeviaf9a5b92018-08-15 16:01:53 -0700546 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800547 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800548 if (subId != null) {
549 this.subId = subId;
550 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700551 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700553 }
554
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800555 private static final class IncomingThirdPartyCallArgs {
556 public final ComponentName component;
557 public final String callId;
558 public final String callerDisplayName;
559
560 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
561 String callerDisplayName) {
562 this.component = component;
563 this.callId = callId;
564 this.callerDisplayName = callerDisplayName;
565 }
566 }
567
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700568 /**
569 * A handler that processes messages on the main thread in the phone process. Since many
570 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
571 * inbound binder threads to the main thread in the phone process. The Binder thread
572 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
573 * on, which will be notified when the operation completes and will contain the result of the
574 * request.
575 *
576 * <p>If a MainThreadRequest object is provided in the msg.obj field,
577 * note that request.result must be set to something non-null for the calling thread to
578 * unblock.
579 */
580 private final class MainThreadHandler extends Handler {
581 @Override
582 public void handleMessage(Message msg) {
583 MainThreadRequest request;
584 Message onCompleted;
585 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000586 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800588 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700589
590 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700591 case CMD_HANDLE_USSD_REQUEST: {
592 request = (MainThreadRequest) msg.obj;
593 final Phone phone = getPhoneFromRequest(request);
594 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800595 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700596 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700597
Pengquan Menga1bb6272018-09-06 09:59:22 -0700598 if (!isUssdApiAllowed(request.subId)) {
599 // Carrier does not support use of this API, return failure.
600 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
601 UssdResponse response = new UssdResponse(ussdRequest, null);
602 Bundle returnData = new Bundle();
603 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
604 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700605
Pengquan Menga1bb6272018-09-06 09:59:22 -0700606 request.result = true;
607 notifyRequester(request);
608 return;
609 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700610
Pengquan Menga1bb6272018-09-06 09:59:22 -0700611 try {
612 request.result = phone != null
613 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
614 } catch (CallStateException cse) {
615 request.result = false;
616 }
617 // Wake up the requesting thread
618 notifyRequester(request);
619 break;
pkanwar32d516d2016-10-14 19:37:38 -0700620 }
621
Yorke Lee716f67e2015-06-17 15:39:16 -0700622 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700623 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700624 final Phone phone = getPhoneFromRequest(request);
625 request.result = phone != null ?
626 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
627 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700628 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700630 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700631 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700632
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700633 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700635 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000636 uiccPort = getUiccPortFromRequest(request);
637 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700638 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800639 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700640 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700641 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700642 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800643 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000644 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800645 iccArgument.channel, iccArgument.cla, iccArgument.command,
646 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
647 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700648 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 break;
650
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700651 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 ar = (AsyncResult) msg.obj;
653 request = (MainThreadRequest) ar.userObj;
654 if (ar.exception == null && ar.result != null) {
655 request.result = ar.result;
656 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800657 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700658 if (ar.result == null) {
659 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800660 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800662 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 } else {
664 loge("iccTransmitApduLogicalChannel: Unknown exception");
665 }
666 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700667 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700668 break;
669
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700670 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
671 request = (MainThreadRequest) msg.obj;
672 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000673 uiccPort = getUiccPortFromRequest(request);
674 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700675 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800676 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700677 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700678 } else {
679 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800680 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000681 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800682 iccArgument.cla, iccArgument.command, iccArgument.p1,
683 iccArgument.p2,
684 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700685 }
686 break;
687
688 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
689 ar = (AsyncResult) msg.obj;
690 request = (MainThreadRequest) ar.userObj;
691 if (ar.exception == null && ar.result != null) {
692 request.result = ar.result;
693 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800694 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700695 if (ar.result == null) {
696 loge("iccTransmitApduBasicChannel: Empty response");
697 } else if (ar.exception instanceof CommandException) {
698 loge("iccTransmitApduBasicChannel: CommandException: " +
699 ar.exception);
700 } else {
701 loge("iccTransmitApduBasicChannel: Unknown exception");
702 }
703 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700704 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700705 break;
706
707 case CMD_EXCHANGE_SIM_IO:
708 request = (MainThreadRequest) msg.obj;
709 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000710 uiccPort = getUiccPortFromRequest(request);
711 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700712 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800713 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700714 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700715 } else {
716 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
717 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000718 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700719 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
720 iccArgument.data, onCompleted);
721 }
722 break;
723
724 case EVENT_EXCHANGE_SIM_IO_DONE:
725 ar = (AsyncResult) msg.obj;
726 request = (MainThreadRequest) ar.userObj;
727 if (ar.exception == null && ar.result != null) {
728 request.result = ar.result;
729 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800730 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700731 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700732 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700733 break;
734
Derek Tan4d5e5c12014-02-04 11:54:58 -0800735 case CMD_SEND_ENVELOPE:
736 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000737 uiccPort = getUiccPortFromRequest(request);
738 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700739 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800740 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700741 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700742 } else {
743 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800744 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700745 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800746 break;
747
748 case EVENT_SEND_ENVELOPE_DONE:
749 ar = (AsyncResult) msg.obj;
750 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700751 if (ar.exception == null && ar.result != null) {
752 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800753 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800754 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700755 if (ar.result == null) {
756 loge("sendEnvelopeWithStatus: Empty response");
757 } else if (ar.exception instanceof CommandException) {
758 loge("sendEnvelopeWithStatus: CommandException: " +
759 ar.exception);
760 } else {
761 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
762 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800763 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700764 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800765 break;
766
Shishir Agrawal566b7612013-10-28 14:41:00 -0700767 case CMD_OPEN_CHANNEL:
768 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000769 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800770 IccLogicalChannelRequest openChannelRequest =
771 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000772 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700773 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800774 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800775 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700776 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700777 } else {
778 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800779 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
780 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700781 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700782 break;
783
784 case EVENT_OPEN_CHANNEL_DONE:
785 ar = (AsyncResult) msg.obj;
786 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700787 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700788 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700789 int[] result = (int[]) ar.result;
790 int channelId = result[0];
791 byte[] selectResponse = null;
792 if (result.length > 1) {
793 selectResponse = new byte[result.length - 1];
794 for (int i = 1; i < result.length; ++i) {
795 selectResponse[i - 1] = (byte) result[i];
796 }
797 }
798 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800799 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800800
801 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700802 if (uiccPort == null) {
803 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
804 } else {
805 IccLogicalChannelRequest channelRequest =
806 (IccLogicalChannelRequest) request.argument;
807 channelRequest.channel = channelId;
808 uiccPort.onLogicalChannelOpened(channelRequest);
809 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700810 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700811 if (ar.result == null) {
812 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700813 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700814 if (ar.exception != null) {
815 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
816 }
817
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700818 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700819 if (ar.exception instanceof CommandException) {
820 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800821 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700822 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700823 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700824 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700825 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700826 }
827 }
828 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800829 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700830 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700831 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700832 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700833 break;
834
835 case CMD_CLOSE_CHANNEL:
836 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000837 uiccPort = getUiccPortFromRequest(request);
838 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700839 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800840 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800841 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800842 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700843 } else {
844 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000845 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700846 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700847 break;
848
849 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800850 ar = (AsyncResult) msg.obj;
851 request = (MainThreadRequest) ar.userObj;
852 if (ar.exception == null) {
853 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800854 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700855 if (uiccPort == null) {
856 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
857 } else {
858 final int channelId = (Integer) request.argument;
859 uiccPort.onLogicalChannelClosed(channelId);
860 }
Chen Xu540470b2021-12-14 17:15:47 -0800861 } else {
862 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800863 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800864 if (ar.exception instanceof CommandException) {
865 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
866 CommandException.Error error =
867 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800868 if (error == CommandException.Error.INVALID_ARGUMENTS) {
869 // should only throw exceptions from the binder threads.
870 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800871 "iccCloseLogicalChannel: invalid argument ");
872 }
873 } else {
874 loge("iccCloseLogicalChannel: Unknown exception");
875 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800876 request.result = (exception != null) ? exception :
877 new IllegalStateException(
878 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800879 }
880 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800881 break;
882
883 case CMD_NV_READ_ITEM:
884 request = (MainThreadRequest) msg.obj;
885 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800886 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
887 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800888 break;
889
890 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700891 ar = (AsyncResult) msg.obj;
892 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800893 if (ar.exception == null && ar.result != null) {
894 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700895 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800896 request.result = "";
897 if (ar.result == null) {
898 loge("nvReadItem: Empty response");
899 } else if (ar.exception instanceof CommandException) {
900 loge("nvReadItem: CommandException: " +
901 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700902 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800903 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700904 }
905 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700906 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700907 break;
908
Jake Hambye994d462014-02-03 13:10:13 -0800909 case CMD_NV_WRITE_ITEM:
910 request = (MainThreadRequest) msg.obj;
911 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
912 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800913 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700914 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800915 break;
916
917 case EVENT_NV_WRITE_ITEM_DONE:
918 handleNullReturnEvent(msg, "nvWriteItem");
919 break;
920
921 case CMD_NV_WRITE_CDMA_PRL:
922 request = (MainThreadRequest) msg.obj;
923 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800924 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800925 break;
926
927 case EVENT_NV_WRITE_CDMA_PRL_DONE:
928 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
929 break;
930
chen xu6dac5ab2018-10-26 17:39:23 -0700931 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800932 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700933 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800934 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800935 break;
936
chen xu6dac5ab2018-10-26 17:39:23 -0700937 case EVENT_RESET_MODEM_CONFIG_DONE:
938 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800939 break;
940
Sooraj Sasindran37444802020-08-11 10:40:43 -0700941 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
942 request = (MainThreadRequest) msg.obj;
943 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
944 request);
945 Phone phone = getPhoneFromRequest(request);
946 if (phone != null) {
947 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
948 } else {
949 loge("isNRDualConnectivityEnabled: No phone object");
950 request.result = false;
951 notifyRequester(request);
952 }
953 break;
954 }
955
956 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
957 ar = (AsyncResult) msg.obj;
958 request = (MainThreadRequest) ar.userObj;
959 if (ar.exception == null && ar.result != null) {
960 request.result = ar.result;
961 } else {
962 // request.result must be set to something non-null
963 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700964 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700965 request.result = ar.result;
966 } else {
967 request.result = false;
968 }
969 if (ar.result == null) {
970 loge("isNRDualConnectivityEnabled: Empty response");
971 } else if (ar.exception instanceof CommandException) {
972 loge("isNRDualConnectivityEnabled: CommandException: "
973 + ar.exception);
974 } else {
975 loge("isNRDualConnectivityEnabled: Unknown exception");
976 }
977 }
978 notifyRequester(request);
979 break;
980
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700981 case CMD_IS_VONR_ENABLED: {
982 request = (MainThreadRequest) msg.obj;
983 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
984 request);
985 Phone phone = getPhoneFromRequest(request);
986 if (phone != null) {
987 phone.isVoNrEnabled(onCompleted, request.workSource);
988 } else {
989 loge("isVoNrEnabled: No phone object");
990 request.result = false;
991 notifyRequester(request);
992 }
993 break;
994 }
995
996 case EVENT_IS_VONR_ENABLED_DONE:
997 ar = (AsyncResult) msg.obj;
998 request = (MainThreadRequest) ar.userObj;
999 if (ar.exception == null && ar.result != null) {
1000 request.result = ar.result;
1001 } else {
1002 // request.result must be set to something non-null
1003 // for the calling thread to unblock
1004 if (ar.result != null) {
1005 request.result = ar.result;
1006 } else {
1007 request.result = false;
1008 }
1009 if (ar.result == null) {
1010 loge("isVoNrEnabled: Empty response");
1011 } else if (ar.exception instanceof CommandException) {
1012 loge("isVoNrEnabled: CommandException: "
1013 + ar.exception);
1014 } else {
1015 loge("isVoNrEnabled: Unknown exception");
1016 }
1017 }
1018 notifyRequester(request);
1019 break;
1020
Sooraj Sasindran37444802020-08-11 10:40:43 -07001021 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1022 request = (MainThreadRequest) msg.obj;
1023 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1024 Phone phone = getPhoneFromRequest(request);
1025 if (phone != null) {
1026 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1027 request.workSource);
1028 } else {
1029 loge("enableNrDualConnectivity: No phone object");
1030 request.result =
1031 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1032 notifyRequester(request);
1033 }
1034 break;
1035 }
1036
1037 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1038 ar = (AsyncResult) msg.obj;
1039 request = (MainThreadRequest) ar.userObj;
1040 if (ar.exception == null) {
1041 request.result =
1042 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1043 } else {
1044 request.result =
1045 TelephonyManager
1046 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1047 if (ar.exception instanceof CommandException) {
1048 CommandException.Error error =
1049 ((CommandException) (ar.exception)).getCommandError();
1050 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1051 request.result =
1052 TelephonyManager
1053 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001054 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1055 request.result =
1056 TelephonyManager
1057 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001058 }
1059 loge("enableNrDualConnectivity" + ": CommandException: "
1060 + ar.exception);
1061 } else {
1062 loge("enableNrDualConnectivity" + ": Unknown exception");
1063 }
1064 }
1065 notifyRequester(request);
1066 break;
1067 }
1068
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001069 case CMD_ENABLE_VONR: {
1070 request = (MainThreadRequest) msg.obj;
1071 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1072 Phone phone = getPhoneFromRequest(request);
1073 if (phone != null) {
1074 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1075 request.workSource);
1076 } else {
1077 loge("setVoNrEnabled: No phone object");
1078 request.result =
1079 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1080 notifyRequester(request);
1081 }
1082 break;
1083 }
1084
1085 case EVENT_ENABLE_VONR_DONE: {
1086 ar = (AsyncResult) msg.obj;
1087 request = (MainThreadRequest) ar.userObj;
1088 if (ar.exception == null) {
1089 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1090 } else {
1091 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1092 if (ar.exception instanceof CommandException) {
1093 CommandException.Error error =
1094 ((CommandException) (ar.exception)).getCommandError();
1095 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1096 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1097 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1098 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1099 } else {
1100 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1101 }
1102 loge("setVoNrEnabled" + ": CommandException: "
1103 + ar.exception);
1104 } else {
1105 loge("setVoNrEnabled" + ": Unknown exception");
1106 }
1107 }
1108 notifyRequester(request);
1109 break;
1110 }
1111
SongFerngWang3ef3e072020-12-21 16:41:52 +08001112 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001113 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001114 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1115 request);
1116 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001117 break;
1118
SongFerngWang3ef3e072020-12-21 16:41:52 +08001119 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001120 ar = (AsyncResult) msg.obj;
1121 request = (MainThreadRequest) ar.userObj;
1122 if (ar.exception == null && ar.result != null) {
1123 request.result = ar.result; // Integer
1124 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301125 // request.result must be set to something non-null
1126 // for the calling thread to unblock
1127 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001128 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001129 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001130 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001131 loge("getAllowedNetworkTypesBitmask: CommandException: "
1132 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001133 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001134 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001135 }
1136 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001137 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001138 break;
1139
SongFerngWang3ef3e072020-12-21 16:41:52 +08001140 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001141 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001142 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1143 request);
1144 Pair<Integer, Long> reasonWithNetworkTypes =
1145 (Pair<Integer, Long>) request.argument;
1146 getPhoneFromRequest(request).setAllowedNetworkTypes(
1147 reasonWithNetworkTypes.first,
1148 reasonWithNetworkTypes.second,
1149 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001150 break;
1151
SongFerngWang3ef3e072020-12-21 16:41:52 +08001152 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1153 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001154 break;
1155
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001156 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1157 request = (MainThreadRequest)msg.obj;
1158 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001159 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001160 break;
1161
1162 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1163 ar = (AsyncResult)msg.obj;
1164 request = (MainThreadRequest)ar.userObj;
1165 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001166 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001167 break;
1168
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001169 case CMD_SET_VOICEMAIL_NUMBER:
1170 request = (MainThreadRequest) msg.obj;
1171 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1172 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001173 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1174 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001175 break;
1176
1177 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1178 handleNullReturnEvent(msg, "setVoicemailNumber");
1179 break;
1180
Stuart Scott54788802015-03-30 13:18:01 -07001181 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1182 request = (MainThreadRequest) msg.obj;
1183 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1184 request);
1185 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1186 break;
1187
1188 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1189 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1190 break;
1191
Shishir Agrawal302c8692015-06-19 13:49:39 -07001192 case CMD_PERFORM_NETWORK_SCAN:
1193 request = (MainThreadRequest) msg.obj;
1194 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1195 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1196 break;
1197
Hall Liu27d24262020-09-18 19:04:59 -07001198 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001199 request = (MainThreadRequest) msg.obj;
1200 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001201 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1202 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1203 request.argument;
1204 int callForwardingReason = args.first;
1205 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001206 break;
Hall Liu27d24262020-09-18 19:04:59 -07001207 }
1208 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001209 ar = (AsyncResult) msg.obj;
1210 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001211 TelephonyManager.CallForwardingInfoCallback callback =
1212 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1213 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001214 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001215 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001216 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1217 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1218 // Service Class is a bit mask per 3gpp 27.007. Search for
1219 // any service for voice call.
1220 if ((callForwardInfo.serviceClass
1221 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001222 callForwardingInfo = new CallForwardingInfo(
1223 callForwardInfo.status
1224 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001225 callForwardInfo.reason,
1226 callForwardInfo.number,
1227 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001228 break;
1229 }
1230 }
1231 // Didn't find a call forward info for voice call.
1232 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001233 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1234 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001235 }
Hall Liu27d24262020-09-18 19:04:59 -07001236 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001237 } else {
1238 if (ar.result == null) {
1239 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1240 }
1241 if (ar.exception != null) {
1242 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1243 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001244 int errorCode = TelephonyManager
1245 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001246 if (ar.exception instanceof CommandException) {
1247 CommandException.Error error =
1248 ((CommandException) (ar.exception)).getCommandError();
1249 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001250 errorCode = TelephonyManager
1251 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001252 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001253 errorCode = TelephonyManager
1254 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001255 }
1256 }
Hall Liu27d24262020-09-18 19:04:59 -07001257 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001258 }
Shuo Qian4a594052020-01-23 11:59:30 -08001259 break;
Hall Liu27d24262020-09-18 19:04:59 -07001260 }
Shuo Qian4a594052020-01-23 11:59:30 -08001261
Hall Liu27d24262020-09-18 19:04:59 -07001262 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001263 request = (MainThreadRequest) msg.obj;
1264 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001265 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001266 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001267 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1268 request.argument).first;
1269 request.phone.setCallForwardingOption(
1270 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001271 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001272 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001273 callForwardingInfoToSet.getReason(),
1274 callForwardingInfoToSet.getNumber(),
1275 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1276 break;
Hall Liu27d24262020-09-18 19:04:59 -07001277 }
Shuo Qian4a594052020-01-23 11:59:30 -08001278
Hall Liu27d24262020-09-18 19:04:59 -07001279 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001280 ar = (AsyncResult) msg.obj;
1281 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001282 Consumer<Integer> callback =
1283 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1284 request.argument).second;
1285 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001286 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001287 int errorCode = TelephonyManager.CallForwardingInfoCallback
1288 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001289 if (ar.exception instanceof CommandException) {
1290 CommandException.Error error =
1291 ((CommandException) (ar.exception)).getCommandError();
1292 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001293 errorCode = TelephonyManager.CallForwardingInfoCallback
1294 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001295 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001296 errorCode = TelephonyManager.CallForwardingInfoCallback
1297 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001298 }
1299 }
1300 callback.accept(errorCode);
1301 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001302 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001303 }
Shuo Qian4a594052020-01-23 11:59:30 -08001304 break;
Hall Liu27d24262020-09-18 19:04:59 -07001305 }
Shuo Qian4a594052020-01-23 11:59:30 -08001306
Hall Liu27d24262020-09-18 19:04:59 -07001307 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001308 request = (MainThreadRequest) msg.obj;
1309 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1310 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1311 break;
Hall Liu27d24262020-09-18 19:04:59 -07001312 }
Shuo Qian4a594052020-01-23 11:59:30 -08001313
Hall Liu27d24262020-09-18 19:04:59 -07001314 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001315 ar = (AsyncResult) msg.obj;
1316 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001317 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001318 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001319 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001320 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001321 // Service Class is a bit mask per 3gpp 27.007.
1322 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001323 if (callForwardResults.length > 1
1324 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001325 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001326 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001327 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1328 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001329 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001330 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001331 }
1332 } else {
1333 if (ar.result == null) {
1334 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1335 }
1336 if (ar.exception != null) {
1337 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1338 }
1339 if (ar.exception instanceof CommandException) {
1340 CommandException.Error error =
1341 ((CommandException) (ar.exception)).getCommandError();
1342 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001343 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001344 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001345 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1346 callWaitingStatus =
1347 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001348 }
1349 }
1350 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001351 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001352 break;
Hall Liu27d24262020-09-18 19:04:59 -07001353 }
Shuo Qian4a594052020-01-23 11:59:30 -08001354
Hall Liu27d24262020-09-18 19:04:59 -07001355 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001356 request = (MainThreadRequest) msg.obj;
1357 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001358 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1359 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001360 break;
Hall Liu27d24262020-09-18 19:04:59 -07001361 }
Shuo Qian4a594052020-01-23 11:59:30 -08001362
Hall Liu27d24262020-09-18 19:04:59 -07001363 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001364 ar = (AsyncResult) msg.obj;
1365 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001366 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1367 Consumer<Integer> callback =
1368 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1369 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001370 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001371 if (ar.exception instanceof CommandException) {
1372 CommandException.Error error =
1373 ((CommandException) (ar.exception)).getCommandError();
1374 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1375 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001376 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1377 callback.accept(
1378 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001379 } else {
1380 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1381 }
1382 } else {
1383 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1384 }
1385 } else {
1386 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1387 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001388 }
Shuo Qian4a594052020-01-23 11:59:30 -08001389 break;
Hall Liu27d24262020-09-18 19:04:59 -07001390 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001391 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1392 ar = (AsyncResult) msg.obj;
1393 request = (MainThreadRequest) ar.userObj;
1394 CellNetworkScanResult cellScanResult;
1395 if (ar.exception == null && ar.result != null) {
1396 cellScanResult = new CellNetworkScanResult(
1397 CellNetworkScanResult.STATUS_SUCCESS,
1398 (List<OperatorInfo>) ar.result);
1399 } else {
1400 if (ar.result == null) {
1401 loge("getCellNetworkScanResults: Empty response");
1402 }
1403 if (ar.exception != null) {
1404 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1405 }
1406 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1407 if (ar.exception instanceof CommandException) {
1408 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001409 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001410 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1411 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1412 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1413 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1414 }
1415 }
1416 cellScanResult = new CellNetworkScanResult(errorCode, null);
1417 }
1418 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001419 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001420 break;
1421
1422 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1423 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001424 ManualNetworkSelectionArgument selArg =
1425 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001426 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1427 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001428 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1429 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001430 break;
1431
1432 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001433 ar = (AsyncResult) msg.obj;
1434 request = (MainThreadRequest) ar.userObj;
1435 if (ar.exception == null) {
1436 request.result = true;
1437 } else {
1438 request.result = false;
1439 loge("setNetworkSelectionModeManual " + ar.exception);
1440 }
1441 notifyRequester(request);
1442 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001443 break;
1444
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001445 case CMD_GET_MODEM_ACTIVITY_INFO:
1446 request = (MainThreadRequest) msg.obj;
1447 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001448 if (defaultPhone != null) {
1449 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001450 } else {
1451 ResultReceiver result = (ResultReceiver) request.argument;
1452 Bundle bundle = new Bundle();
1453 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001454 new ModemActivityInfo(0, 0, 0,
1455 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001456 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001457 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001458 break;
1459
Hall Liud0f208c2020-10-14 16:54:44 -07001460 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001461 ar = (AsyncResult) msg.obj;
1462 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001463 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001464 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001465 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001466 if (mLastModemActivityInfo == null) {
1467 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1468 mLastModemActivitySpecificInfo[0] =
1469 new ActivityStatsTechSpecificInfo(
1470 0,
1471 0,
1472 new int[ModemActivityInfo.getNumTxPowerLevels()],
1473 0);
1474 mLastModemActivityInfo =
1475 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1476 }
1477
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001478 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001479 // Update the last modem activity info and the result of the request.
1480 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1481 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001482 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001483 } else {
1484 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001485 }
Kai Shi917fdc62022-11-28 14:01:02 -08001486 // This is needed to decouple ret from mLastModemActivityInfo
1487 // We don't want to return mLastModemActivityInfo which is updated
1488 // inside mergeModemActivityInfo()
1489 ret = new ModemActivityInfo(
1490 mLastModemActivityInfo.getTimestampMillis(),
1491 mLastModemActivityInfo.getSleepTimeMillis(),
1492 mLastModemActivityInfo.getIdleTimeMillis(),
1493 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001494
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001495 } else {
1496 if (ar.result == null) {
1497 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001498 error = TelephonyManager.ModemActivityInfoException
1499 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001500 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001501 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001502 error = TelephonyManager.ModemActivityInfoException
1503 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001504 } else {
1505 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001506 error = TelephonyManager.ModemActivityInfoException
1507 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001508 }
1509 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001510 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001511 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001512 bundle.putParcelable(
1513 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001514 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001515 } else {
1516 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1517 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001518 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001519 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001520 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001521 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001522
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001523 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001524 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001525 CarrierRestrictionRules argument =
1526 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001527 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001528 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001529 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001530 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001531
1532 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1533 ar = (AsyncResult) msg.obj;
1534 request = (MainThreadRequest) ar.userObj;
1535 if (ar.exception == null && ar.result != null) {
1536 request.result = ar.result;
1537 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001538 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1539 if (ar.exception instanceof CommandException) {
1540 loge("setAllowedCarriers: CommandException: " + ar.exception);
1541 CommandException.Error error =
1542 ((CommandException) (ar.exception)).getCommandError();
1543 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1544 request.result =
1545 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1546 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001547 } else {
1548 loge("setAllowedCarriers: Unknown exception");
1549 }
1550 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001551 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001552 break;
1553
1554 case CMD_GET_ALLOWED_CARRIERS:
1555 request = (MainThreadRequest) msg.obj;
1556 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001557 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001558 break;
1559
1560 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1561 ar = (AsyncResult) msg.obj;
1562 request = (MainThreadRequest) ar.userObj;
1563 if (ar.exception == null && ar.result != null) {
1564 request.result = ar.result;
1565 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001566 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001567 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001568 if (ar.result == null) {
1569 loge("getAllowedCarriers: Empty response");
1570 } else if (ar.exception instanceof CommandException) {
1571 loge("getAllowedCarriers: CommandException: " +
1572 ar.exception);
1573 } else {
1574 loge("getAllowedCarriers: Unknown exception");
1575 }
1576 }
arunvoddud7401012022-12-15 16:08:12 +00001577 if (request.argument != null) {
1578 // This is for the implementation of carrierRestrictionStatus.
1579 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1580 Consumer<Integer> callback = callbackInfo.getConsumer();
1581 int callerCarrierId = callbackInfo.getCarrierId();
1582 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1583 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1584 CarrierRestrictionRules carrierRestrictionRules =
1585 (CarrierRestrictionRules) ar.result;
1586 int carrierId = -1;
1587 try {
1588 CarrierIdentifier carrierIdentifier =
1589 carrierRestrictionRules.getAllowedCarriers().get(0);
1590 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1591 carrierIdentifier);
1592 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1593 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1594 }
1595 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1596 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1597 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001598 lockStatus = TelephonyManager
1599 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001600 }
1601 } else {
1602 Rlog.e(LOG_TAG,
1603 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1604 }
1605 callback.accept(lockStatus);
1606 } else {
1607 // This is for the implementation of getAllowedCarriers.
1608 notifyRequester(request);
1609 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001610 break;
1611
Nathan Haroldb3014052017-01-25 15:57:32 -08001612 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1613 ar = (AsyncResult) msg.obj;
1614 request = (MainThreadRequest) ar.userObj;
1615 if (ar.exception == null && ar.result != null) {
1616 request.result = ar.result;
1617 } else {
1618 request.result = new IllegalArgumentException(
1619 "Failed to retrieve Forbidden Plmns");
1620 if (ar.result == null) {
1621 loge("getForbiddenPlmns: Empty response");
1622 } else {
1623 loge("getForbiddenPlmns: Unknown exception");
1624 }
1625 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001626 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001627 break;
1628
1629 case CMD_GET_FORBIDDEN_PLMNS:
1630 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001631 uiccPort = getUiccPortFromRequest(request);
1632 if (uiccPort == null) {
1633 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001634 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001635 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001636 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001637 break;
1638 }
1639 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001640 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001641 if (uiccApp == null) {
1642 loge("getForbiddenPlmns() no app with specified type -- "
1643 + appType);
1644 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001645 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001646 break;
1647 } else {
1648 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1649 + " specified type -- " + appType);
1650 }
1651 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1652 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001653 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001654 break;
1655
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001656 case CMD_SWITCH_SLOTS:
1657 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001658 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001659 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001660 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001661 break;
1662
1663 case EVENT_SWITCH_SLOTS_DONE:
1664 ar = (AsyncResult) msg.obj;
1665 request = (MainThreadRequest) ar.userObj;
1666 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001667 notifyRequester(request);
1668 break;
1669 case CMD_GET_NETWORK_SELECTION_MODE:
1670 request = (MainThreadRequest) msg.obj;
1671 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1672 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1673 break;
1674
1675 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1676 ar = (AsyncResult) msg.obj;
1677 request = (MainThreadRequest) ar.userObj;
1678 if (ar.exception != null) {
1679 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1680 } else {
1681 int mode = ((int[]) ar.result)[0];
1682 if (mode == 0) {
1683 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1684 } else {
1685 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1686 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001687 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001688 notifyRequester(request);
1689 break;
1690 case CMD_GET_CDMA_ROAMING_MODE:
1691 request = (MainThreadRequest) msg.obj;
1692 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1693 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1694 break;
1695 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1696 ar = (AsyncResult) msg.obj;
1697 request = (MainThreadRequest) ar.userObj;
1698 if (ar.exception != null) {
1699 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1700 } else {
1701 request.result = ((int[]) ar.result)[0];
1702 }
1703 notifyRequester(request);
1704 break;
1705 case CMD_SET_CDMA_ROAMING_MODE:
1706 request = (MainThreadRequest) msg.obj;
1707 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1708 int mode = (int) request.argument;
1709 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1710 break;
1711 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1712 ar = (AsyncResult) msg.obj;
1713 request = (MainThreadRequest) ar.userObj;
1714 request.result = ar.exception == null;
1715 notifyRequester(request);
1716 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001717 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1718 request = (MainThreadRequest) msg.obj;
1719 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1720 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1721 break;
1722 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1723 ar = (AsyncResult) msg.obj;
1724 request = (MainThreadRequest) ar.userObj;
1725 if (ar.exception != null) {
1726 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1727 } else {
1728 request.result = ((int[]) ar.result)[0];
1729 }
1730 notifyRequester(request);
1731 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001732 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1733 request = (MainThreadRequest) msg.obj;
1734 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1735 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001736 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1737 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001738 break;
1739 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1740 ar = (AsyncResult) msg.obj;
1741 request = (MainThreadRequest) ar.userObj;
1742 request.result = ar.exception == null;
1743 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001744 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001745 case CMD_GET_ALL_CELL_INFO:
1746 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001747 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001748 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001749 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001750 case EVENT_GET_ALL_CELL_INFO_DONE:
1751 ar = (AsyncResult) msg.obj;
1752 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001753 // If a timeout occurs, the response will be null
1754 request.result = (ar.exception == null && ar.result != null)
1755 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001756 synchronized (request) {
1757 request.notifyAll();
1758 }
1759 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001760 case CMD_REQUEST_CELL_INFO_UPDATE:
1761 request = (MainThreadRequest) msg.obj;
1762 request.phone.requestCellInfoUpdate(request.workSource,
1763 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1764 break;
1765 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1766 ar = (AsyncResult) msg.obj;
1767 request = (MainThreadRequest) ar.userObj;
1768 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1769 try {
1770 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001771 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001772 cb.onError(
1773 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1774 ar.exception.getClass().getName(),
1775 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001776 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001777 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001778 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001779 } else {
1780 // use the result as returned
1781 cb.onCellInfo((List<CellInfo>) ar.result);
1782 }
1783 } catch (RemoteException re) {
1784 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1785 }
1786 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001787 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001788 request = (MainThreadRequest) msg.obj;
1789 WorkSource ws = (WorkSource) request.argument;
1790 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001791 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001792 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001793 }
1794 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001795 ar = (AsyncResult) msg.obj;
1796 request = (MainThreadRequest) ar.userObj;
1797 if (ar.exception == null) {
1798 request.result = ar.result;
1799 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001800 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001801 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001802 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001803 }
1804
1805 synchronized (request) {
1806 request.notifyAll();
1807 }
1808 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001809 }
chen xu6dac5ab2018-10-26 17:39:23 -07001810 case CMD_MODEM_REBOOT:
1811 request = (MainThreadRequest) msg.obj;
1812 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001813 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001814 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001815 case EVENT_CMD_MODEM_REBOOT_DONE:
1816 handleNullReturnEvent(msg, "rebootModem");
1817 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001818 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001819 request = (MainThreadRequest) msg.obj;
1820 boolean enable = (boolean) request.argument;
1821 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001822 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001823 PhoneConfigurationManager.getInstance()
1824 .enablePhone(request.phone, enable, onCompleted);
1825 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001826 }
Michele Berionne5e411512020-11-13 02:36:59 +00001827 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001828 ar = (AsyncResult) msg.obj;
1829 request = (MainThreadRequest) ar.userObj;
1830 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001831 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001832 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001833 if ((boolean) request.result) {
1834 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1835 updateModemStateMetrics();
1836 } else {
1837 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1838 + ar.exception);
1839 }
1840 notifyRequester(request);
1841 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001842 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001843 case CMD_GET_MODEM_STATUS:
1844 request = (MainThreadRequest) msg.obj;
1845 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1846 PhoneConfigurationManager.getInstance()
1847 .getPhoneStatusFromModem(request.phone, onCompleted);
1848 break;
1849 case EVENT_GET_MODEM_STATUS_DONE:
1850 ar = (AsyncResult) msg.obj;
1851 request = (MainThreadRequest) ar.userObj;
1852 int id = request.phone.getPhoneId();
1853 if (ar.exception == null && ar.result != null) {
1854 request.result = ar.result;
1855 //update the cache as modem status has changed
1856 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1857 (boolean) request.result);
1858 } else {
1859 // Return true if modem status cannot be retrieved. For most cases,
1860 // modem status is on. And for older version modems, GET_MODEM_STATUS
1861 // and disable modem are not supported. Modem is always on.
1862 // TODO: this should be fixed in R to support a third
1863 // status UNKNOWN b/131631629
1864 request.result = true;
1865 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1866 + ar.exception);
1867 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001868 notifyRequester(request);
1869 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001870 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1871 request = (MainThreadRequest) msg.obj;
1872 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1873 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1874 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1875 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1876 break;
1877 }
1878 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1879 ar = (AsyncResult) msg.obj;
1880 request = (MainThreadRequest) ar.userObj;
1881 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1882 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1883 args.second.accept(ar.exception == null);
1884 notifyRequester(request);
1885 break;
1886 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001887 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1888 request = (MainThreadRequest) msg.obj;
1889 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1890 Phone phone = getPhoneFromRequest(request);
1891 if (phone != null) {
1892 phone.getSystemSelectionChannels(onCompleted);
1893 } else {
1894 loge("getSystemSelectionChannels: No phone object");
1895 request.result = new ArrayList<RadioAccessSpecifier>();
1896 notifyRequester(request);
1897 }
1898 break;
1899 }
1900 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1901 ar = (AsyncResult) msg.obj;
1902 request = (MainThreadRequest) ar.userObj;
1903 if (ar.exception == null && ar.result != null) {
1904 request.result = ar.result;
1905 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001906 request.result = new IllegalStateException(
1907 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001908 if (ar.result == null) {
1909 loge("getSystemSelectionChannels: Empty response");
1910 } else {
1911 loge("getSystemSelectionChannels: Unknown exception");
1912 }
1913 }
1914 notifyRequester(request);
1915 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001916 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1917 ar = (AsyncResult) msg.obj;
1918 request = (MainThreadRequest) ar.userObj;
1919 if (ar.exception == null && ar.result != null) {
1920 request.result = ar.result;
1921 } else {
1922 request.result = -1;
1923 loge("Failed to set Forbidden Plmns");
1924 if (ar.result == null) {
1925 loge("setForbidenPlmns: Empty response");
1926 } else if (ar.exception != null) {
1927 loge("setForbiddenPlmns: Exception: " + ar.exception);
1928 request.result = -1;
1929 } else {
1930 loge("setForbiddenPlmns: Unknown exception");
1931 }
1932 }
1933 notifyRequester(request);
1934 break;
1935 case CMD_SET_FORBIDDEN_PLMNS:
1936 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001937 uiccPort = getUiccPortFromRequest(request);
1938 if (uiccPort == null) {
1939 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001940 request.result = -1;
1941 notifyRequester(request);
1942 break;
1943 }
1944 Pair<Integer, List<String>> setFplmnsArgs =
1945 (Pair<Integer, List<String>>) request.argument;
1946 appType = setFplmnsArgs.first;
1947 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001948 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001949 if (uiccApp == null) {
1950 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1951 request.result = -1;
1952 loge("Failed to get UICC App");
1953 notifyRequester(request);
1954 } else {
1955 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1956 ((SIMRecords) uiccApp.getIccRecords())
1957 .setForbiddenPlmns(onCompleted, fplmns);
1958 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001959 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001960 case CMD_ERASE_MODEM_CONFIG:
1961 request = (MainThreadRequest) msg.obj;
1962 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1963 defaultPhone.eraseModemConfig(onCompleted);
1964 break;
1965 case EVENT_ERASE_MODEM_CONFIG_DONE:
1966 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001967 break;
zoey chene02881a2019-12-30 16:11:23 +08001968
Kai Shif70f46f2021-03-03 13:59:46 -08001969 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1970 request = (MainThreadRequest) msg.obj;
1971 request.result = defaultPhone.eraseDataInSharedPreferences();
1972 notifyRequester(request);
1973 break;
1974
zoey chene02881a2019-12-30 16:11:23 +08001975 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1976 request = (MainThreadRequest) msg.obj;
1977 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1978 Pair<String, String> changed = (Pair<String, String>) request.argument;
1979 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1980 changed.first, changed.second, onCompleted);
1981 break;
1982 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1983 ar = (AsyncResult) msg.obj;
1984 request = (MainThreadRequest) ar.userObj;
1985 if (ar.exception == null) {
1986 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001987 // If the operation is successful, update the PIN storage
1988 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1989 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001990 UiccController.getInstance().getPinStorage()
1991 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001992 } else {
1993 request.result = msg.arg1;
1994 }
1995 notifyRequester(request);
1996 break;
1997
Michele Berionne5e411512020-11-13 02:36:59 +00001998 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001999 request = (MainThreadRequest) msg.obj;
2000 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2001 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2002 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2003 enabled.first, enabled.second, onCompleted);
2004 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002005 }
zoey chene02881a2019-12-30 16:11:23 +08002006 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2007 ar = (AsyncResult) msg.obj;
2008 request = (MainThreadRequest) ar.userObj;
2009 if (ar.exception == null) {
2010 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002011 // If the operation is successful, update the PIN storage
2012 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2013 int phoneId = getPhoneFromRequest(request).getPhoneId();
2014 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002015 UiccController.getInstance().getPinStorage()
2016 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002017 } else {
2018 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2019 }
zoey chene02881a2019-12-30 16:11:23 +08002020 } else {
2021 request.result = msg.arg1;
2022 }
Michele Berionne5e411512020-11-13 02:36:59 +00002023
2024
zoey chene02881a2019-12-30 16:11:23 +08002025 notifyRequester(request);
2026 break;
2027
Peter Wangdafb9ac2020-01-15 14:13:38 -08002028 case MSG_NOTIFY_USER_ACTIVITY:
2029 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002030 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002031 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2032 getDefaultPhone().getContext().sendBroadcastAsUser(
2033 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2034 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002035
2036 case CMD_SET_DATA_THROTTLING: {
2037 request = (MainThreadRequest) msg.obj;
2038 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2039 DataThrottlingRequest dataThrottlingRequest =
2040 (DataThrottlingRequest) request.argument;
2041 Phone phone = getPhoneFromRequest(request);
2042 if (phone != null) {
2043 phone.setDataThrottling(onCompleted,
2044 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2045 dataThrottlingRequest.getCompletionDurationMillis());
2046 } else {
2047 loge("setDataThrottling: No phone object");
2048 request.result =
2049 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2050 notifyRequester(request);
2051 }
2052
2053 break;
2054 }
2055 case EVENT_SET_DATA_THROTTLING_DONE:
2056 ar = (AsyncResult) msg.obj;
2057 request = (MainThreadRequest) ar.userObj;
2058
2059 if (ar.exception == null) {
2060 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2061 } else if (ar.exception instanceof CommandException) {
2062 loge("setDataThrottling: CommandException: " + ar.exception);
2063 CommandException.Error error =
2064 ((CommandException) (ar.exception)).getCommandError();
2065
2066 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2067 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002068 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002069 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2070 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002071 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2072 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002073 } else {
2074 request.result =
2075 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2076 }
2077 } else {
2078 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2079 }
2080 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2081 notifyRequester(request);
2082 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002083
2084 case CMD_SET_SIM_POWER: {
2085 request = (MainThreadRequest) msg.obj;
2086 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2087 request = (MainThreadRequest) msg.obj;
2088 int stateToSet =
2089 ((Pair<Integer, IIntegerConsumer>)
2090 request.argument).first;
2091 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2092 break;
2093 }
2094 case EVENT_SET_SIM_POWER_DONE: {
2095 ar = (AsyncResult) msg.obj;
2096 request = (MainThreadRequest) ar.userObj;
2097 IIntegerConsumer callback =
2098 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2099 if (ar.exception != null) {
2100 loge("setSimPower exception: " + ar.exception);
2101 int errorCode = TelephonyManager.CallForwardingInfoCallback
2102 .RESULT_ERROR_UNKNOWN;
2103 if (ar.exception instanceof CommandException) {
2104 CommandException.Error error =
2105 ((CommandException) (ar.exception)).getCommandError();
2106 if (error == CommandException.Error.SIM_ERR) {
2107 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2108 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2109 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2110 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2111 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2112 } else {
2113 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2114 }
2115 }
2116 try {
2117 callback.accept(errorCode);
2118 } catch (RemoteException e) {
2119 // Ignore if the remote process is no longer available to call back.
2120 Log.w(LOG_TAG, "setSimPower: callback not available.");
2121 }
2122 } else {
2123 try {
2124 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2125 } catch (RemoteException e) {
2126 // Ignore if the remote process is no longer available to call back.
2127 Log.w(LOG_TAG, "setSimPower: callback not available.");
2128 }
2129 }
2130 break;
2131 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002132 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2133 request = (MainThreadRequest) msg.obj;
2134
2135 final Phone phone = getPhoneFromRequest(request);
2136 if (phone == null || phone.getServiceStateTracker() == null) {
2137 request.result = new IllegalStateException("Phone or SST is null");
2138 notifyRequester(request);
2139 break;
2140 }
2141
2142 Pair<Integer, SignalStrengthUpdateRequest> pair =
2143 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2144 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2145 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002146 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002147 request.subId, pair.first /*callingUid*/,
2148 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002149 break;
2150 }
2151 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2152 ar = (AsyncResult) msg.obj;
2153 request = (MainThreadRequest) ar.userObj;
2154 // request.result will be the exception of ar if present, true otherwise.
2155 // Be cautious not to leave result null which will wait() forever
2156 request.result = ar.exception != null ? ar.exception : true;
2157 notifyRequester(request);
2158 break;
2159 }
2160 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2161 request = (MainThreadRequest) msg.obj;
2162
2163 Phone phone = getPhoneFromRequest(request);
2164 if (phone == null || phone.getServiceStateTracker() == null) {
2165 request.result = new IllegalStateException("Phone or SST is null");
2166 notifyRequester(request);
2167 break;
2168 }
2169
2170 Pair<Integer, SignalStrengthUpdateRequest> pair =
2171 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2172 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2173 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002174 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002175 request.subId, pair.first /*callingUid*/,
2176 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002177 break;
2178 }
2179 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2180 ar = (AsyncResult) msg.obj;
2181 request = (MainThreadRequest) ar.userObj;
2182 request.result = ar.exception != null ? ar.exception : true;
2183 notifyRequester(request);
2184 break;
2185 }
Jordan Liu109698e2020-11-24 14:50:34 -08002186
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002187 case CMD_GET_SLICING_CONFIG: {
2188 request = (MainThreadRequest) msg.obj;
2189 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2190 request.phone.getSlicingConfig(onCompleted);
2191 break;
2192 }
2193 case EVENT_GET_SLICING_CONFIG_DONE: {
2194 ar = (AsyncResult) msg.obj;
2195 request = (MainThreadRequest) ar.userObj;
2196 ResultReceiver result = (ResultReceiver) request.argument;
2197
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002198 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002199 Bundle bundle = new Bundle();
2200 int resultCode = 0;
2201 if (ar.exception != null) {
2202 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2203 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002204 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002205 } else if (ar.result == null) {
2206 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002207 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002208 } else {
2209 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002210 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2211 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002212 }
2213
2214 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002215 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002216 }
2217 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2218 result.send(resultCode, bundle);
2219 notifyRequester(request);
2220 break;
2221 }
2222
Sarah Chin71b3a852022-09-28 15:54:19 -07002223 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002224 request = (MainThreadRequest) msg.obj;
2225 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002226 PurchasePremiumCapabilityArgument arg =
2227 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002228 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chinb8218c22023-01-04 13:35:29 -08002229 arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002230 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002231 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002232
Sarah Chin71b3a852022-09-28 15:54:19 -07002233 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002234 ar = (AsyncResult) msg.obj;
2235 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002236 PurchasePremiumCapabilityArgument arg =
2237 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002238 try {
2239 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002240 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002241 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002242 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002243 + ", result= "
2244 + TelephonyManager.convertPurchaseResultToString(result));
2245 } catch (RemoteException e) {
2246 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002247 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002248 + " failed: " + e;
2249 if (DBG) log(logStr);
2250 AnomalyReporter.reportAnomaly(
2251 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2252 }
2253 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002254 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002255
Michele Berionne5e411512020-11-13 02:36:59 +00002256 case CMD_PREPARE_UNATTENDED_REBOOT:
2257 request = (MainThreadRequest) msg.obj;
2258 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002259 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002260 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002261 notifyRequester(request);
2262 break;
2263
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002264 default:
2265 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2266 break;
2267 }
2268 }
Jake Hambye994d462014-02-03 13:10:13 -08002269
Pengquan Menga1bb6272018-09-06 09:59:22 -07002270 private void notifyRequester(MainThreadRequest request) {
2271 synchronized (request) {
2272 request.notifyAll();
2273 }
2274 }
2275
Jake Hambye994d462014-02-03 13:10:13 -08002276 private void handleNullReturnEvent(Message msg, String command) {
2277 AsyncResult ar = (AsyncResult) msg.obj;
2278 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2279 if (ar.exception == null) {
2280 request.result = true;
2281 } else {
2282 request.result = false;
2283 if (ar.exception instanceof CommandException) {
2284 loge(command + ": CommandException: " + ar.exception);
2285 } else {
2286 loge(command + ": Unknown exception");
2287 }
2288 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002289 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002290 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002291 }
2292
2293 /**
2294 * Posts the specified command to be executed on the main thread,
2295 * waits for the request to complete, and returns the result.
2296 * @see #sendRequestAsync
2297 */
2298 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002299 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2300 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002301 }
2302
2303 /**
2304 * Posts the specified command to be executed on the main thread,
2305 * waits for the request to complete, and returns the result.
2306 * @see #sendRequestAsync
2307 */
2308 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2309 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002310 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002311 }
2312
2313 /**
2314 * Posts the specified command to be executed on the main thread,
2315 * waits for the request to complete, and returns the result.
2316 * @see #sendRequestAsync
2317 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002318 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002319 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2320 }
2321
2322 /**
2323 * Posts the specified command to be executed on the main thread,
2324 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2325 * if not timeout or null otherwise.
2326 * @see #sendRequestAsync
2327 */
2328 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2329 long timeoutInMs) {
2330 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002331 }
2332
2333 /**
2334 * Posts the specified command to be executed on the main thread,
2335 * waits for the request to complete, and returns the result.
2336 * @see #sendRequestAsync
2337 */
Nathan Harold92bed182018-10-12 18:16:49 -07002338 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002339 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002340 }
2341
2342 /**
2343 * Posts the specified command to be executed on the main thread,
2344 * waits for the request to complete, and returns the result.
2345 * @see #sendRequestAsync
2346 */
2347 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002348 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2349 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002350 }
2351
2352 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002353 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2354 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2355 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002356 * @see #sendRequestAsync
2357 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002358 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2359 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2361 throw new RuntimeException("This method will deadlock if called from the main thread.");
2362 }
2363
Nathan Harold92bed182018-10-12 18:16:49 -07002364 MainThreadRequest request = null;
2365 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2366 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2367 } else if (phone != null) {
2368 request = new MainThreadRequest(argument, phone, workSource);
2369 } else {
2370 request = new MainThreadRequest(argument, subId, workSource);
2371 }
2372
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002373 Message msg = mMainThreadHandler.obtainMessage(command, request);
2374 msg.sendToTarget();
2375
Rambo Wang0f050d82021-02-12 11:43:36 -08002376
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002377 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002378 if (timeoutInMs >= 0) {
2379 // Wait for at least timeoutInMs before returning null request result
2380 long now = SystemClock.elapsedRealtime();
2381 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002382 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002383 try {
2384 request.wait(deadline - now);
2385 } catch (InterruptedException e) {
2386 // Do nothing, go back and check if request is completed or timeout
2387 } finally {
2388 now = SystemClock.elapsedRealtime();
2389 }
2390 }
2391 } else {
2392 // Wait for the request to complete
2393 while (request.result == null) {
2394 try {
2395 request.wait();
2396 } catch (InterruptedException e) {
2397 // Do nothing, go back and wait until the request is complete
2398 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399 }
2400 }
2401 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002402 if (request.result == null) {
2403 Log.wtf(LOG_TAG,
2404 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2405 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002406 return request.result;
2407 }
2408
2409 /**
2410 * Asynchronous ("fire and forget") version of sendRequest():
2411 * Posts the specified command to be executed on the main thread, and
2412 * returns immediately.
2413 * @see #sendRequest
2414 */
2415 private void sendRequestAsync(int command) {
2416 mMainThreadHandler.sendEmptyMessage(command);
2417 }
2418
2419 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002420 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002421 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002422 */
2423 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002424 sendRequestAsync(command, argument, null, null);
2425 }
2426
2427 /**
2428 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2429 * @see {@link #sendRequest(int,Object)}
2430 */
2431 private void sendRequestAsync(
2432 int command, Object argument, Phone phone, WorkSource workSource) {
2433 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002434 Message msg = mMainThreadHandler.obtainMessage(command, request);
2435 msg.sendToTarget();
2436 }
2437
2438 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002439 * Initialize the singleton PhoneInterfaceManager instance.
2440 * This is only done once, at startup, from PhoneApp.onCreate().
2441 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002442 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 synchronized (PhoneInterfaceManager.class) {
2444 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002445 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002446 } else {
2447 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2448 }
2449 return sInstance;
2450 }
2451 }
2452
2453 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002454 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002455 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002457 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002458 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002459 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002460 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2461 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002462 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002463 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002464 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002465 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002466 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002467 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 publish();
arunvoddud7401012022-12-15 16:08:12 +00002469 CarrierAllowListInfo.loadInstance(mApp);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002470 }
2471
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002472 @VisibleForTesting
2473 public SharedPreferences getSharedPreferences() {
2474 return mTelephonySharedPreferences;
2475 }
2476
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002477 /**
2478 * Get the default phone for this device.
2479 */
2480 @VisibleForTesting
2481 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002482 Phone thePhone = getPhone(getDefaultSubscription());
2483 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2484 }
2485
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002486 private void publish() {
2487 if (DBG) log("publish: " + this);
2488
Peter Wangc035ce42020-01-08 21:00:22 -08002489 TelephonyFrameworkInitializer
2490 .getTelephonyServiceManager()
2491 .getTelephonyServiceRegisterer()
2492 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493 }
2494
Stuart Scott584921c2015-01-15 17:10:34 -08002495 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002496 if (request.phone != null) {
2497 return request.phone;
2498 } else {
2499 return getPhoneFromSubId(request.subId);
2500 }
2501 }
2502
2503 private Phone getPhoneFromSubId(int subId) {
2504 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2505 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002506 }
2507
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002508 /**
2509 * Get phone object associated with a subscription.
2510 * Return default phone if phone object associated with subscription is null
2511 * @param subId - subscriptionId
2512 * @return phone object associated with a subscription or default phone if null.
2513 */
Ling Mac28f0212023-03-24 16:07:15 -07002514 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002515 Phone phone = getPhoneFromSubId(subId);
2516 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002517 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002518 phone = getDefaultPhone();
2519 }
2520 return phone;
2521 }
2522
Rambo Wange53e07d2022-05-10 13:01:13 -07002523 @Nullable
2524 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002525 Phone phone = getPhoneFromRequest(request);
2526 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002527 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002528 }
2529
Ling Mac28f0212023-03-24 16:07:15 -07002530 /**
2531 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2532 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2533 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2534 * @return The Phone associated the sub Id
2535 */
2536 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002537 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002538 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002539
Kai Shif70f46f2021-03-03 13:59:46 -08002540 private void sendEraseModemConfig(@NonNull Phone phone) {
2541 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2542 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2543 }
2544
2545 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2546 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2547 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002548 }
2549
Peter Wang44b186e2020-01-13 23:33:09 -08002550 private boolean isImsAvailableOnDevice() {
2551 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2552 if (pm == null) {
2553 // For some reason package manger is not available.. This will fail internally anyway,
2554 // so do not throw error and allow.
2555 return true;
2556 }
2557 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2558 }
2559
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002560 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002561 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002562 }
2563
Wink Savilleb564aae2014-10-23 10:18:09 -07002564 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002565 if (DBG) log("dial: " + number);
2566 // No permission check needed here: This is just a wrapper around the
2567 // ACTION_DIAL intent, which is available to any app since it puts up
2568 // the UI before it does anything.
2569
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002570 final long identity = Binder.clearCallingIdentity();
2571 try {
2572 String url = createTelUrl(number);
2573 if (url == null) {
2574 return;
2575 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002576
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002577 // PENDING: should we just silently fail if phone is offhook or ringing?
2578 PhoneConstants.State state = mCM.getState(subId);
2579 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2580 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2581 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2582 mApp.startActivity(intent);
2583 }
2584 } finally {
2585 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002586 }
2587 }
2588
2589 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002590 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002591 }
2592
Wink Savilleb564aae2014-10-23 10:18:09 -07002593 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002594 if (DBG) log("call: " + number);
2595
2596 // This is just a wrapper around the ACTION_CALL intent, but we still
2597 // need to do a permission check since we're calling startActivity()
2598 // from the context of the phone app.
2599 enforceCallPermission();
2600
Jordan Liu1617b712019-07-10 15:06:26 -07002601 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002602 != AppOpsManager.MODE_ALLOWED) {
2603 return;
2604 }
2605
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002606 final long identity = Binder.clearCallingIdentity();
2607 try {
2608 String url = createTelUrl(number);
2609 if (url == null) {
2610 return;
2611 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002612
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613 boolean isValid = false;
2614 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2615 if (slist != null) {
2616 for (SubscriptionInfo subInfoRecord : slist) {
2617 if (subInfoRecord.getSubscriptionId() == subId) {
2618 isValid = true;
2619 break;
2620 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002621 }
Wink Saville08874612014-08-31 19:19:58 -07002622 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623 if (!isValid) {
2624 return;
2625 }
Wink Saville08874612014-08-31 19:19:58 -07002626
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002627 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2628 intent.putExtra(SUBSCRIPTION_KEY, subId);
2629 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2630 mApp.startActivity(intent);
2631 } finally {
2632 Binder.restoreCallingIdentity(identity);
2633 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002634 }
2635
Wink Savilleb564aae2014-10-23 10:18:09 -07002636 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002637 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002638 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2639 }
2640
Wink Savilleb564aae2014-10-23 10:18:09 -07002641 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002642 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, 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 int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002647 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002648
2649 final long identity = Binder.clearCallingIdentity();
2650 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002651 Phone phone = getPhone(subId);
2652 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002653 checkSimPin.start();
2654 return checkSimPin.unlockSim(null, pin);
2655 } finally {
2656 Binder.restoreCallingIdentity(identity);
2657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002658 }
2659
Wink Savilleb564aae2014-10-23 10:18:09 -07002660 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002661 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002662
2663 final long identity = Binder.clearCallingIdentity();
2664 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002665 Phone phone = getPhone(subId);
2666 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002667 checkSimPuk.start();
2668 return checkSimPuk.unlockSim(puk, pin);
2669 } finally {
2670 Binder.restoreCallingIdentity(identity);
2671 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002672 }
2673
2674 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002675 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002676 * a synchronous one.
2677 */
2678 private static class UnlockSim extends Thread {
2679
2680 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002681 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002682
2683 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002684 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2685 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002686
2687 // For replies from SimCard interface
2688 private Handler mHandler;
2689
2690 // For async handler to identify request type
2691 private static final int SUPPLY_PIN_COMPLETE = 100;
2692
Michele Berionne5e411512020-11-13 02:36:59 +00002693 UnlockSim(int phoneId, IccCard simCard) {
2694 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695 mSimCard = simCard;
2696 }
2697
2698 @Override
2699 public void run() {
2700 Looper.prepare();
2701 synchronized (UnlockSim.this) {
2702 mHandler = new Handler() {
2703 @Override
2704 public void handleMessage(Message msg) {
2705 AsyncResult ar = (AsyncResult) msg.obj;
2706 switch (msg.what) {
2707 case SUPPLY_PIN_COMPLETE:
2708 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2709 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002710 mRetryCount = msg.arg1;
2711 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002712 CommandException.Error error = null;
2713 if (ar.exception instanceof CommandException) {
2714 error = ((CommandException) (ar.exception))
2715 .getCommandError();
2716 }
2717 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002718 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002719 } else if (error == CommandException.Error.ABORTED) {
2720 /* When UiccCardApp dispose, handle message and return
2721 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002722 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002723 } else {
2724 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2725 }
2726 } else {
2727 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2728 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002729 mDone = true;
2730 UnlockSim.this.notifyAll();
2731 }
2732 break;
2733 }
2734 }
2735 };
2736 UnlockSim.this.notifyAll();
2737 }
2738 Looper.loop();
2739 }
2740
2741 /*
2742 * Use PIN or PUK to unlock SIM card
2743 *
2744 * If PUK is null, unlock SIM card with PIN
2745 *
2746 * If PUK is not null, unlock SIM card with PUK and set PIN code
2747 */
Wink Saville9de0f752013-10-22 19:04:03 -07002748 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002749
2750 while (mHandler == null) {
2751 try {
2752 wait();
2753 } catch (InterruptedException e) {
2754 Thread.currentThread().interrupt();
2755 }
2756 }
2757 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2758
2759 if (puk == null) {
2760 mSimCard.supplyPin(pin, callback);
2761 } else {
2762 mSimCard.supplyPuk(puk, pin, callback);
2763 }
2764
2765 while (!mDone) {
2766 try {
2767 Log.d(LOG_TAG, "wait for done");
2768 wait();
2769 } catch (InterruptedException e) {
2770 // Restore the interrupted status
2771 Thread.currentThread().interrupt();
2772 }
2773 }
2774 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002775 int[] resultArray = new int[2];
2776 resultArray[0] = mResult;
2777 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002778
2779 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002780 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002781 }
2782
Wink Saville9de0f752013-10-22 19:04:03 -07002783 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002784 }
2785 }
2786
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002787 /**
2788 * This method has been removed due to privacy and stability concerns.
2789 */
2790 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002791 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002792 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2793 return;
Wink Saville36469e72014-06-11 15:17:00 -07002794 }
2795
Nathan Harold1f889d82020-06-04 17:05:26 -07002796 @Override
2797 public void updateServiceLocationWithPackageName(String callingPackage) {
2798 mApp.getSystemService(AppOpsManager.class)
2799 .checkPackage(Binder.getCallingUid(), callingPackage);
2800
Nathan Haroldf096d982020-11-18 17:18:06 -08002801 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002802 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2803 // Callers targeting S have no business invoking this method.
2804 return;
2805 }
2806
2807 LocationAccessPolicy.LocationPermissionResult locationResult =
2808 LocationAccessPolicy.checkLocationPermission(mApp,
2809 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2810 .setCallingPackage(callingPackage)
2811 .setCallingFeatureId(null)
2812 .setCallingPid(Binder.getCallingPid())
2813 .setCallingUid(Binder.getCallingUid())
2814 .setMethod("updateServiceLocation")
2815 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2816 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2817 .build());
2818 // Apps that lack location permission have no business calling this method;
2819 // however, because no permission was declared in the public API, denials must
2820 // all be "soft".
2821 switch (locationResult) {
2822 case DENIED_HARD: /* fall through */
2823 case DENIED_SOFT:
2824 return;
2825 }
2826
2827 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002828 final long identity = Binder.clearCallingIdentity();
2829 try {
Ling Mac28f0212023-03-24 16:07:15 -07002830 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002831 } finally {
2832 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002833 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002834 }
2835
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002836 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002837 @Override
2838 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002839 return isRadioOnWithFeature(callingPackage, null);
2840 }
2841
2842
2843 @Override
2844 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2845 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2846 callingFeatureId);
2847 }
2848
2849 @Deprecated
2850 @Override
2851 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2852 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002853 }
2854
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002855 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002856 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2857 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002858 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002859 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002860 return false;
2861 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002862
2863 final long identity = Binder.clearCallingIdentity();
2864 try {
2865 return isRadioOnForSubscriber(subId);
2866 } finally {
2867 Binder.restoreCallingIdentity(identity);
2868 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002869 }
2870
2871 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002872 final long identity = Binder.clearCallingIdentity();
2873 try {
2874 final Phone phone = getPhone(subId);
2875 if (phone != null) {
2876 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2877 } else {
2878 return false;
2879 }
2880 } finally {
2881 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002882 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002883 }
2884
2885 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002886 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002887 }
Wink Saville36469e72014-06-11 15:17:00 -07002888
Wink Savilleb564aae2014-10-23 10:18:09 -07002889 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002890 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002891
2892 final long identity = Binder.clearCallingIdentity();
2893 try {
2894 final Phone phone = getPhone(subId);
2895 if (phone != null) {
2896 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2897 }
2898 } finally {
2899 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002900 }
Wink Saville36469e72014-06-11 15:17:00 -07002901 }
2902
2903 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002904 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002905 }
2906
Wink Savilleb564aae2014-10-23 10:18:09 -07002907 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002908 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002909
2910 final long identity = Binder.clearCallingIdentity();
2911 try {
2912 final Phone phone = getPhone(subId);
2913 if (phone == null) {
2914 return false;
2915 }
2916 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2917 toggleRadioOnOffForSubscriber(subId);
2918 }
2919 return true;
2920 } finally {
2921 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002922 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002923 }
Wink Saville36469e72014-06-11 15:17:00 -07002924
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002925 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002926 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002927 /*
2928 * If any of the Radios are available, it will need to be
2929 * shutdown. So return true if any Radio is available.
2930 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002931 final long identity = Binder.clearCallingIdentity();
2932 try {
2933 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2934 Phone phone = PhoneFactory.getPhone(i);
2935 if (phone != null && phone.isRadioAvailable()) return true;
2936 }
2937 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2938 return false;
2939 } finally {
2940 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002941 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002942 }
2943
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002944 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002945 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002946 enforceModifyPermission();
2947
2948 final long identity = Binder.clearCallingIdentity();
2949 try {
2950 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2951 logv("Shutting down Phone " + i);
2952 shutdownRadioUsingPhoneId(i);
2953 }
2954 } finally {
2955 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002956 }
2957 }
2958
2959 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002960 Phone phone = PhoneFactory.getPhone(phoneId);
2961 if (phone != null && phone.isRadioAvailable()) {
2962 phone.shutdownRadio();
2963 }
2964 }
2965
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002966 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002967 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002968
Ling Ma83dc5ea2023-01-12 15:06:04 -08002969 if (!turnOn) {
2970 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
2971 }
2972
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002973 final long identity = Binder.clearCallingIdentity();
2974 try {
2975 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2976 if (defaultPhone != null) {
2977 defaultPhone.setRadioPower(turnOn);
2978 return true;
2979 } else {
2980 loge("There's no default phone.");
2981 return false;
2982 }
2983 } finally {
2984 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002985 }
Wink Saville36469e72014-06-11 15:17:00 -07002986 }
2987
Wink Savilleb564aae2014-10-23 10:18:09 -07002988 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002989 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002990
Ling Ma83dc5ea2023-01-12 15:06:04 -08002991 if (!turnOn) {
2992 log("setRadioPowerForSubscriber off: subId=" + subId
2993 + ",callingPackage=" + getCurrentPackageName());
2994 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002995 final long identity = Binder.clearCallingIdentity();
2996 try {
2997 final Phone phone = getPhone(subId);
2998 if (phone != null) {
2999 phone.setRadioPower(turnOn);
3000 return true;
3001 } else {
3002 return false;
3003 }
3004 } finally {
3005 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003006 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003007 }
3008
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003009 /**
3010 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3011 * no reason to power it off. When any of the voters want to power it off, it will be turned
3012 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3013 * powering it off, and these radio off votes will be cleared.
3014 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3015 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3016 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3017 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3018 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3019 * check its vote.
3020 *
3021 * @param subId The subscription ID.
3022 * @param reason The reason for powering off radio.
3023 * @return true on success and false on failure.
3024 */
3025 public boolean requestRadioPowerOffForReason(int subId,
3026 @TelephonyManager.RadioPowerReason int reason) {
3027 enforceModifyPermission();
3028
Ling Ma83dc5ea2023-01-12 15:06:04 -08003029 log("requestRadioPowerOffForReason: subId=" + subId
3030 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003031 final long identity = Binder.clearCallingIdentity();
3032 try {
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003033 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003034 if (phone != null) {
3035 phone.setRadioPowerForReason(false, reason);
3036 return true;
3037 } else {
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003038 loge("requestRadioPowerOffForReason: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003039 return false;
3040 }
3041 } finally {
3042 Binder.restoreCallingIdentity(identity);
3043 }
3044 }
3045
3046 /**
3047 * Remove the vote on powering off the radio for a reason, as requested by
3048 * {@link requestRadioPowerOffForReason}.
3049 *
3050 * @param subId The subscription ID.
3051 * @param reason The reason for powering off radio.
3052 * @return true on success and false on failure.
3053 */
3054 public boolean clearRadioPowerOffForReason(int subId,
3055 @TelephonyManager.RadioPowerReason int reason) {
3056 enforceModifyPermission();
3057
3058 final long identity = Binder.clearCallingIdentity();
3059 try {
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003060 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003061 if (phone != null) {
3062 phone.setRadioPowerForReason(true, reason);
3063 return true;
3064 } else {
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003065 loge("clearRadioPowerOffForReason: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003066 return false;
3067 }
3068 } finally {
3069 Binder.restoreCallingIdentity(identity);
3070 }
3071 }
3072
3073 /**
3074 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3075 *
3076 * @param subId The subscription ID.
3077 * @param callingPackage The package making the call.
3078 * @param callingFeatureId The feature in the package.
3079 * @return List of reasons for powering off radio.
3080 */
3081 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3082 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3083
3084 final long identity = Binder.clearCallingIdentity();
3085 List result = new ArrayList();
3086 try {
3087 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3088 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3089 return result;
3090 }
3091
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003092 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003093 if (phone != null) {
3094 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003095 } else {
3096 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003097 }
3098 } finally {
3099 Binder.restoreCallingIdentity(identity);
3100 }
3101 return result;
3102 }
3103
Wink Saville36469e72014-06-11 15:17:00 -07003104 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003105 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003106 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003107 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003108
3109 final long identity = Binder.clearCallingIdentity();
3110 try {
Jack Yu285100e2022-12-02 22:48:35 -08003111 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003112 final Phone phone = getPhone(subId);
3113 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003114 phone.getDataSettingsManager().setDataEnabled(
3115 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003116 return true;
3117 } else {
3118 return false;
3119 }
3120 } finally {
3121 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003122 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003123 }
3124
Wink Saville36469e72014-06-11 15:17:00 -07003125 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003126 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003127 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003128 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003129
3130 final long identity = Binder.clearCallingIdentity();
3131 try {
Jack Yu285100e2022-12-02 22:48:35 -08003132 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003133 final Phone phone = getPhone(subId);
3134 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003135 phone.getDataSettingsManager().setDataEnabled(
3136 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003137 return true;
3138 } else {
3139 return false;
3140 }
3141 } finally {
3142 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003143 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003144 }
3145
Sanket Padawe356d7632015-06-22 14:03:32 -07003146 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003147 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003148 final long identity = Binder.clearCallingIdentity();
3149 try {
3150 final Phone phone = getPhone(subId);
3151 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003152 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003153 } else {
3154 return false;
3155 }
3156 } finally {
3157 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003158 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003159 }
3160
3161 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003162 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003163 }
3164
pkanwarae03a6b2016-11-06 20:37:09 -08003165 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003166 enforceCallPermission();
3167
3168 final long identity = Binder.clearCallingIdentity();
3169 try {
3170 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3171 return;
3172 }
3173 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3174 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3175 } finally {
3176 Binder.restoreCallingIdentity(identity);
3177 }
pkanwar32d516d2016-10-14 19:37:38 -07003178 };
3179
Wink Savilleb564aae2014-10-23 10:18:09 -07003180 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003181 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003182
3183 final long identity = Binder.clearCallingIdentity();
3184 try {
3185 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3186 return false;
3187 }
3188 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3189 } finally {
3190 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003191 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003192 }
3193
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003194 /**
3195 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3196 * tag on getCallState Binder call.
3197 */
3198 @Deprecated
3199 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003200 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003201 if (CompatChanges.isChangeEnabled(
3202 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3203 Binder.getCallingUid())) {
3204 // Do not allow this API to be called on API version 31+, it should only be
3205 // called on old apps using this Binder call directly.
3206 throw new SecurityException("This method can only be used for applications "
3207 + "targeting API version 30 or less.");
3208 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003209 final long identity = Binder.clearCallingIdentity();
3210 try {
Ling Mac28f0212023-03-24 16:07:15 -07003211 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3212 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003213 } finally {
3214 Binder.restoreCallingIdentity(identity);
3215 }
3216 }
3217
3218 @Override
3219 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3220 if (CompatChanges.isChangeEnabled(
3221 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3222 Binder.getCallingUid())) {
3223 // Check READ_PHONE_STATE for API version 31+
3224 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3225 featureId, "getCallStateForSubscription")) {
3226 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3227 + "targeting API level 31+.");
3228 }
3229 }
3230 final long identity = Binder.clearCallingIdentity();
3231 try {
3232 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003233 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3234 PhoneConstantConversions.convertCallState(phone.getState());
3235 } finally {
3236 Binder.restoreCallingIdentity(identity);
3237 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003238 }
3239
Sanket Padawe356d7632015-06-22 14:03:32 -07003240 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003241 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003242 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003243 }
3244
3245 @Override
3246 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003247 final long identity = Binder.clearCallingIdentity();
3248 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003249 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003250 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003251 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003252 } else {
3253 return PhoneConstantConversions.convertDataState(
3254 PhoneConstants.DataState.DISCONNECTED);
3255 }
3256 } finally {
3257 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003259 }
3260
Sanket Padawe356d7632015-06-22 14:03:32 -07003261 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003262 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003263 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003264 }
3265
3266 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003267 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003268 final long identity = Binder.clearCallingIdentity();
3269 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003270 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003271 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003272 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003273 } else {
3274 return TelephonyManager.DATA_ACTIVITY_NONE;
3275 }
3276 } finally {
3277 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003278 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003279 }
3280
3281 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003282 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003283 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003284 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003285
3286 LocationAccessPolicy.LocationPermissionResult locationResult =
3287 LocationAccessPolicy.checkLocationPermission(mApp,
3288 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3289 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003290 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003291 .setCallingPid(Binder.getCallingPid())
3292 .setCallingUid(Binder.getCallingUid())
3293 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003294 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003295 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3296 .build());
3297 switch (locationResult) {
3298 case DENIED_HARD:
3299 throw new SecurityException("Not allowed to access cell location");
3300 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003301 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3302 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003303 }
3304
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003305 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003306 final long identity = Binder.clearCallingIdentity();
3307 try {
3308 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003309 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003310 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003311 } finally {
3312 Binder.restoreCallingIdentity(identity);
3313 }
Svetoslav64fad262015-04-14 14:35:21 -07003314 }
3315
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003316 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003317 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003318 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3319 // registered cell info, so return a NULL country instead.
3320 final long identity = Binder.clearCallingIdentity();
3321 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003322 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3323 // Get default phone in this case.
3324 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3325 }
Jack Yu285100e2022-12-02 22:48:35 -08003326 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003327 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003328 if (phone == null) return "";
3329 ServiceStateTracker sst = phone.getServiceStateTracker();
3330 if (sst == null) return "";
3331 LocaleTracker lt = sst.getLocaleTracker();
3332 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003333 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003334 } finally {
3335 Binder.restoreCallingIdentity(identity);
3336 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003337 }
3338
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003339 /**
3340 * This method was removed due to potential issues caused by performing partial
3341 * updates of service state, and lack of a credible use case.
3342 *
3343 * This has the ability to break the telephony implementation by disabling notification of
3344 * changes in device connectivity. DO NOT USE THIS!
3345 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003346 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003347 public void enableLocationUpdates() {
3348 mApp.enforceCallingOrSelfPermission(
3349 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003350 }
3351
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003352 /**
3353 * This method was removed due to potential issues caused by performing partial
3354 * updates of service state, and lack of a credible use case.
3355 *
3356 * This has the ability to break the telephony implementation by disabling notification of
3357 * changes in device connectivity. DO NOT USE THIS!
3358 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003359 @Override
3360 public void disableLocationUpdates() {
3361 mApp.enforceCallingOrSelfPermission(
3362 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003363 }
3364
3365 @Override
3366 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003367 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3368 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003369 try {
3370 mApp.getSystemService(AppOpsManager.class)
3371 .checkPackage(Binder.getCallingUid(), callingPackage);
3372 } catch (SecurityException e) {
3373 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3374 throw e;
3375 }
3376
Nathan Haroldf096d982020-11-18 17:18:06 -08003377 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003378 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3379 throw new SecurityException(
3380 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3381 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003382
Jordan Liu1617b712019-07-10 15:06:26 -07003383 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003384 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3385 return null;
3386 }
Svetoslav64fad262015-04-14 14:35:21 -07003387
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003388 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003389
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003390 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003391 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003392
Nathan Haroldf180aac2018-06-01 18:43:55 -07003393 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3394 for (CellInfo ci : info) {
3395 if (ci instanceof CellInfoGsm) {
3396 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3397 } else if (ci instanceof CellInfoWcdma) {
3398 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3399 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003400 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003401 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003402 }
3403
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003404 private List<CellInfo> getCachedCellInfo() {
3405 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3406 for (Phone phone : PhoneFactory.getPhones()) {
3407 List<CellInfo> info = phone.getAllCellInfo();
3408 if (info != null) cellInfos.addAll(info);
3409 }
3410 return cellInfos;
3411 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003412
3413 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003414 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003415 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003416 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003417
3418 LocationAccessPolicy.LocationPermissionResult locationResult =
3419 LocationAccessPolicy.checkLocationPermission(mApp,
3420 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3421 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003422 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003423 .setCallingPid(Binder.getCallingPid())
3424 .setCallingUid(Binder.getCallingUid())
3425 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003426 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003427 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3428 .build());
3429 switch (locationResult) {
3430 case DENIED_HARD:
3431 throw new SecurityException("Not allowed to access cell info");
3432 case DENIED_SOFT:
3433 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003434 }
3435
Nathan Haroldf096d982020-11-18 17:18:06 -08003436 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003437 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3438 return getCachedCellInfo();
3439 }
3440
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003441 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003442 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003443 final long identity = Binder.clearCallingIdentity();
3444 try {
3445 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3446 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003447 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003448 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003449 if (info != null) cellInfos.addAll(info);
3450 }
3451 return cellInfos;
3452 } finally {
3453 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003454 }
3455 }
3456
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003457 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003458 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3459 String callingFeatureId) {
3460 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3461 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003462 }
3463
3464 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003465 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3466 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003467 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003468 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003469 }
3470
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003471 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3472 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003473 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003474 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003475
3476 LocationAccessPolicy.LocationPermissionResult locationResult =
3477 LocationAccessPolicy.checkLocationPermission(mApp,
3478 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3479 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003480 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003481 .setCallingPid(Binder.getCallingPid())
3482 .setCallingUid(Binder.getCallingUid())
3483 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003484 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3485 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003486 .build());
3487 switch (locationResult) {
3488 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003489 if (TelephonyPermissions
3490 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003491 // Safetynet logging for b/154934934
3492 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3493 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003494 throw new SecurityException("Not allowed to access cell info");
3495 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003496 if (TelephonyPermissions
3497 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003498 // Safetynet logging for b/154934934
3499 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3500 }
Nathan Harold5320c422019-05-09 10:26:08 -07003501 try {
3502 cb.onCellInfo(new ArrayList<CellInfo>());
3503 } catch (RemoteException re) {
3504 // Drop without consequences
3505 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003506 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003507 }
3508
Nathan Harolda939a962019-05-09 10:13:47 -07003509
3510 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003511 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3512
3513 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3514 }
3515
3516 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003517 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003518 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003519 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003520
3521 final long identity = Binder.clearCallingIdentity();
3522 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003523 Phone phone = getPhone(subId);
3524 if (phone == null) {
3525 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3526 } else {
3527 phone.setCellInfoListRate(rateInMillis, workSource);
3528 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003529 } finally {
3530 Binder.restoreCallingIdentity(identity);
3531 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003532 }
3533
Shishir Agrawala9f32182016-04-12 12:00:16 -07003534 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003535 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003536 Phone phone = PhoneFactory.getPhone(slotIndex);
3537 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003538 return null;
3539 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003540 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003541 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003542 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003543 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003544 return null;
3545 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003546
3547 final long identity = Binder.clearCallingIdentity();
3548 try {
3549 return phone.getImei();
3550 } finally {
3551 Binder.restoreCallingIdentity(identity);
3552 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003553 }
3554
3555 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003556 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3557 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3558 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3559 callingFeatureId, "getPrimaryImei")) {
3560 throw new SecurityException("Caller does not have permission");
3561 }
3562 final long identity = Binder.clearCallingIdentity();
3563 try {
3564 for (Phone phone : PhoneFactory.getPhones()) {
3565 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3566 return phone.getImei();
3567 }
3568 }
3569 throw new UnsupportedOperationException("Operation not supported");
3570 } finally {
3571 Binder.restoreCallingIdentity(identity);
3572 }
3573 }
3574
3575 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003576 public String getTypeAllocationCodeForSlot(int slotIndex) {
3577 Phone phone = PhoneFactory.getPhone(slotIndex);
3578 String tac = null;
3579 if (phone != null) {
3580 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003581 try {
3582 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3583 } catch (IndexOutOfBoundsException e) {
3584 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3585 return null;
3586 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003587 }
3588 return tac;
3589 }
3590
3591 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003592 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003593 try {
3594 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3595 } catch (SecurityException se) {
3596 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3597 throw new SecurityException("Package " + callingPackage + " does not belong to "
3598 + Binder.getCallingUid());
3599 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003600 Phone phone = PhoneFactory.getPhone(slotIndex);
3601 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003602 return null;
3603 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003604
Jeff Davidson913390f2018-02-23 17:11:49 -08003605 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003606 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003607 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003608 return null;
3609 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003610
3611 final long identity = Binder.clearCallingIdentity();
3612 try {
3613 return phone.getMeid();
3614 } finally {
3615 Binder.restoreCallingIdentity(identity);
3616 }
Jack Yu2af8d712017-03-15 17:14:14 -07003617 }
3618
3619 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003620 public String getManufacturerCodeForSlot(int slotIndex) {
3621 Phone phone = PhoneFactory.getPhone(slotIndex);
3622 String manufacturerCode = null;
3623 if (phone != null) {
3624 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003625 try {
3626 manufacturerCode =
3627 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3628 } catch (IndexOutOfBoundsException e) {
3629 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3630 return null;
3631 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003632 }
3633 return manufacturerCode;
3634 }
3635
3636 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003637 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3638 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003639 Phone phone = PhoneFactory.getPhone(slotIndex);
3640 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003641 return null;
3642 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003643 int subId = phone.getSubId();
3644 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003645 mApp, subId, callingPackage, callingFeatureId,
3646 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003647 return null;
3648 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003649
3650 final long identity = Binder.clearCallingIdentity();
3651 try {
3652 return phone.getDeviceSvn();
3653 } finally {
3654 Binder.restoreCallingIdentity(identity);
3655 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003656 }
3657
fionaxu43304da2017-11-27 22:51:16 -08003658 @Override
3659 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003660 final long identity = Binder.clearCallingIdentity();
3661 try {
3662 final Phone phone = getPhone(subId);
3663 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3664 } finally {
3665 Binder.restoreCallingIdentity(identity);
3666 }
fionaxu43304da2017-11-27 22:51:16 -08003667 }
3668
3669 @Override
3670 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003671 final long identity = Binder.clearCallingIdentity();
3672 try {
3673 final Phone phone = getPhone(subId);
3674 return phone == null ? null : phone.getCarrierName();
3675 } finally {
3676 Binder.restoreCallingIdentity(identity);
3677 }
fionaxu43304da2017-11-27 22:51:16 -08003678 }
3679
calvinpanffe225e2018-11-01 19:43:06 +08003680 @Override
chen xu0026ca62019-03-06 15:28:50 -08003681 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003682 final long identity = Binder.clearCallingIdentity();
3683 try {
3684 final Phone phone = getPhone(subId);
3685 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003686 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003687 } finally {
3688 Binder.restoreCallingIdentity(identity);
3689 }
3690 }
3691
3692 @Override
chen xu0026ca62019-03-06 15:28:50 -08003693 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003694 final long identity = Binder.clearCallingIdentity();
3695 try {
3696 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003697 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003698 } finally {
3699 Binder.restoreCallingIdentity(identity);
3700 }
3701 }
3702
chen xu651eec72018-11-11 19:03:44 -08003703 @Override
chen xu864e11c2018-12-06 22:10:03 -08003704 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3705 if (!isSubscriptionMccMnc) {
3706 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3707 }
chen xu651eec72018-11-11 19:03:44 -08003708 final Phone phone = PhoneFactory.getPhone(slotIndex);
3709 if (phone == null) {
3710 return TelephonyManager.UNKNOWN_CARRIER_ID;
3711 }
3712 final long identity = Binder.clearCallingIdentity();
3713 try {
3714 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3715 } finally {
3716 Binder.restoreCallingIdentity(identity);
3717 }
3718 }
3719
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003720 //
3721 // Internal helper methods.
3722 //
3723
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003724 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003725 * Make sure the caller is the calling package itself
3726 *
3727 * @throws SecurityException if the caller is not the calling package
3728 */
3729 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3730 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003731 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3732 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003733 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003734 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003735 } catch (PackageManager.NameNotFoundException e) {
3736 // packageUid is -1
3737 }
3738 if (packageUid != callingUid) {
3739 throw new SecurityException(message + ": Package " + callingPackage
3740 + " does not belong to " + callingUid);
3741 }
3742 }
3743
3744 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003745 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3746 *
3747 * @throws SecurityException if the caller does not have the required permission
3748 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003749 @VisibleForTesting
3750 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003751 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3752 }
3753
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003754 /**
arunvoddud7401012022-12-15 16:08:12 +00003755 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003756 *
3757 * @throws SecurityException if the caller does not have the required permission
3758 */
3759 @VisibleForTesting
3760 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003761 enforceReadPermission(null);
3762 }
3763
3764 /**
3765 * Make sure the caller has the READ_PHONE_STATE permissions.
3766 *
3767 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3768 */
3769 @VisibleForTesting
3770 public void enforceReadPermission(String msg) {
3771 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003772 }
3773
Shuo Qian3b6ee772019-11-13 17:43:31 -08003774 private void enforceActiveEmergencySessionPermission() {
3775 mApp.enforceCallingOrSelfPermission(
3776 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3777 }
3778
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003779 /**
3780 * Make sure the caller has the CALL_PHONE permission.
3781 *
3782 * @throws SecurityException if the caller does not have the required permission
3783 */
3784 private void enforceCallPermission() {
3785 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3786 }
3787
paulhu5a773602019-08-23 19:17:33 +08003788 private void enforceSettingsPermission() {
3789 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003790 }
3791
Michele Berionne5e411512020-11-13 02:36:59 +00003792 private void enforceRebootPermission() {
3793 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3794 }
3795
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003796 /**
3797 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3798 * @param message - log message to print.
3799 * @throws SecurityException if the caller does not have the required permission
3800 */
3801 private void enforceSatelliteCommunicationPermission(String message) {
3802 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3803 }
3804
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003805 private String createTelUrl(String number) {
3806 if (TextUtils.isEmpty(number)) {
3807 return null;
3808 }
3809
Jake Hambye994d462014-02-03 13:10:13 -08003810 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003811 }
3812
Ihab Awadf9e92732013-12-05 18:02:52 -08003813 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003814 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003815 }
3816
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003817 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003818 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003819 }
3820
Ihab Awadf9e92732013-12-05 18:02:52 -08003821 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003822 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003823 }
3824
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003825 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003826 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003827 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003828 }
3829
Sanket Padawe356d7632015-06-22 14:03:32 -07003830 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003831 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003832 final long identity = Binder.clearCallingIdentity();
3833 try {
3834 final Phone phone = PhoneFactory.getPhone(slotIndex);
3835 if (phone == null) {
3836 return PhoneConstants.PHONE_TYPE_NONE;
3837 } else {
3838 return phone.getPhoneType();
3839 }
3840 } finally {
3841 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003842 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003843 }
3844
3845 /**
3846 * Returns the CDMA ERI icon index to display
3847 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003848 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003849 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3850 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3851 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003852 }
3853
Sanket Padawe356d7632015-06-22 14:03:32 -07003854 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003855 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3856 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003857 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003858 mApp, subId, callingPackage, callingFeatureId,
3859 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003860 return -1;
3861 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003862
3863 final long identity = Binder.clearCallingIdentity();
3864 try {
3865 final Phone phone = getPhone(subId);
3866 if (phone != null) {
3867 return phone.getCdmaEriIconIndex();
3868 } else {
3869 return -1;
3870 }
3871 } finally {
3872 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003873 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003874 }
3875
3876 /**
3877 * Returns the CDMA ERI icon mode,
3878 * 0 - ON
3879 * 1 - FLASHING
3880 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003881 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003882 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3883 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3884 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003885 }
3886
Sanket Padawe356d7632015-06-22 14:03:32 -07003887 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003888 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3889 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003890 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003891 mApp, subId, callingPackage, callingFeatureId,
3892 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003893 return -1;
3894 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003895
3896 final long identity = Binder.clearCallingIdentity();
3897 try {
3898 final Phone phone = getPhone(subId);
3899 if (phone != null) {
3900 return phone.getCdmaEriIconMode();
3901 } else {
3902 return -1;
3903 }
3904 } finally {
3905 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003906 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003907 }
3908
3909 /**
3910 * Returns the CDMA ERI text,
3911 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003912 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003913 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3914 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3915 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003916 }
3917
Sanket Padawe356d7632015-06-22 14:03:32 -07003918 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003919 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3920 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003921 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003922 mApp, subId, callingPackage, callingFeatureId,
3923 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003924 return null;
3925 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003926
3927 final long identity = Binder.clearCallingIdentity();
3928 try {
3929 final Phone phone = getPhone(subId);
3930 if (phone != null) {
3931 return phone.getCdmaEriText();
3932 } else {
3933 return null;
3934 }
3935 } finally {
3936 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003937 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003938 }
3939
3940 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003941 * Returns the CDMA MDN.
3942 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003943 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003944 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003945 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3946 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003947
3948 final long identity = Binder.clearCallingIdentity();
3949 try {
3950 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003951 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003952 return phone.getLine1Number();
3953 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003954 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003955 return null;
3956 }
3957 } finally {
3958 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003959 }
3960 }
3961
3962 /**
3963 * Returns the CDMA MIN.
3964 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003965 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003966 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003967 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3968 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003969
3970 final long identity = Binder.clearCallingIdentity();
3971 try {
3972 final Phone phone = getPhone(subId);
3973 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3974 return phone.getCdmaMin();
3975 } else {
3976 return null;
3977 }
3978 } finally {
3979 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003980 }
3981 }
3982
Hall Liud892bec2018-11-30 14:51:45 -08003983 @Override
3984 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3985 INumberVerificationCallback callback, String callingPackage) {
3986 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3987 != PERMISSION_GRANTED) {
3988 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3989 }
3990 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3991
3992 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3993 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003994 throw new SecurityException("Calling package must be configured in the device config: "
3995 + "calling package: " + callingPackage
3996 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003997 }
3998
3999 if (range == null) {
4000 throw new NullPointerException("Range must be non-null");
4001 }
4002
4003 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004004 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004005
4006 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4007 }
4008
Junda Liuca05d5d2014-08-14 22:36:34 -07004009 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004010 * Returns true if CDMA provisioning needs to run.
4011 */
4012 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004013 final long identity = Binder.clearCallingIdentity();
4014 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004015 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004016 } finally {
4017 Binder.restoreCallingIdentity(identity);
4018 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004019 }
4020
4021 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004022 * Sets the voice mail number of a given subId.
4023 */
4024 @Override
4025 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004026 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4027 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004028
4029 final long identity = Binder.clearCallingIdentity();
4030 try {
4031 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4032 new Pair<String, String>(alphaTag, number), new Integer(subId));
4033 return success;
4034 } finally {
4035 Binder.restoreCallingIdentity(identity);
4036 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004037 }
4038
Ta-wei Yen87c49842016-05-13 21:19:52 -07004039 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004040 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4041 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004042 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4043 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004044 if (!TextUtils.equals(callingPackage, systemDialer)) {
4045 throw new SecurityException("caller must be system dialer");
4046 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004047
4048 final long identity = Binder.clearCallingIdentity();
4049 try {
4050 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4051 if (phoneAccountHandle == null) {
4052 return null;
4053 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004054 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004055 } finally {
4056 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004057 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004058 }
4059
4060 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004061 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4062 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004063 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004064 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004065 mApp, subId, callingPackage, callingFeatureId,
4066 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004067 return null;
4068 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004069
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004070 final long identity = Binder.clearCallingIdentity();
4071 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004072 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004073 } finally {
4074 Binder.restoreCallingIdentity(identity);
4075 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004076 }
4077
4078 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004079 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4080 VisualVoicemailSmsFilterSettings settings) {
4081 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004082
4083 final long identity = Binder.clearCallingIdentity();
4084 try {
4085 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004086 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004087 } finally {
4088 Binder.restoreCallingIdentity(identity);
4089 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004090 }
4091
4092 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004093 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4094 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004095
4096 final long identity = Binder.clearCallingIdentity();
4097 try {
4098 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004099 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004100 } finally {
4101 Binder.restoreCallingIdentity(identity);
4102 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004103 }
4104
4105 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004106 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4107 String callingPackage, int subId) {
4108 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004109
4110 final long identity = Binder.clearCallingIdentity();
4111 try {
4112 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004113 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004114 } finally {
4115 Binder.restoreCallingIdentity(identity);
4116 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004117 }
4118
4119 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004120 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004121 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004122
4123 final long identity = Binder.clearCallingIdentity();
4124 try {
4125 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004126 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004127 } finally {
4128 Binder.restoreCallingIdentity(identity);
4129 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004130 }
4131
4132 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004133 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4134 String callingAttributionTag, int subId, String number, int port, String text,
4135 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004136 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004137 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004138 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004139 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004140 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4141 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004142 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004143
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004144 /**
fionaxu0152e512016-11-14 13:36:14 -08004145 * Sets the voice activation state of a given subId.
4146 */
4147 @Override
4148 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004149 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4150 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004151
4152 final long identity = Binder.clearCallingIdentity();
4153 try {
4154 final Phone phone = getPhone(subId);
4155 if (phone != null) {
4156 phone.setVoiceActivationState(activationState);
4157 } else {
4158 loge("setVoiceActivationState fails with invalid subId: " + subId);
4159 }
4160 } finally {
4161 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004162 }
4163 }
4164
4165 /**
4166 * Sets the data activation state of a given subId.
4167 */
4168 @Override
4169 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004170 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4171 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004172
4173 final long identity = Binder.clearCallingIdentity();
4174 try {
4175 final Phone phone = getPhone(subId);
4176 if (phone != null) {
4177 phone.setDataActivationState(activationState);
4178 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004179 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004180 }
4181 } finally {
4182 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004183 }
4184 }
4185
4186 /**
4187 * Returns the voice activation state of a given subId.
4188 */
4189 @Override
4190 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004191 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004192
fionaxu0152e512016-11-14 13:36:14 -08004193 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004194 final long identity = Binder.clearCallingIdentity();
4195 try {
4196 if (phone != null) {
4197 return phone.getVoiceActivationState();
4198 } else {
4199 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4200 }
4201 } finally {
4202 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004203 }
4204 }
4205
4206 /**
4207 * Returns the data activation state of a given subId.
4208 */
4209 @Override
4210 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004211 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004212
fionaxu0152e512016-11-14 13:36:14 -08004213 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004214 final long identity = Binder.clearCallingIdentity();
4215 try {
4216 if (phone != null) {
4217 return phone.getDataActivationState();
4218 } else {
4219 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4220 }
4221 } finally {
4222 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004223 }
4224 }
4225
4226 /**
Wink Saville36469e72014-06-11 15:17:00 -07004227 * Returns the unread count of voicemails for a subId
4228 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004229 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004230 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4231 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004232 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004233 mApp, subId, callingPackage, callingFeatureId,
4234 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004235 return 0;
4236 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004237 final long identity = Binder.clearCallingIdentity();
4238 try {
4239 final Phone phone = getPhone(subId);
4240 if (phone != null) {
4241 return phone.getVoiceMessageCount();
4242 } else {
4243 return 0;
4244 }
4245 } finally {
4246 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004247 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004248 }
4249
4250 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004251 * returns true, if the device is in a state where both voice and data
4252 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004253 */
4254 @Override
4255 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004256 final long identity = Binder.clearCallingIdentity();
4257 try {
Ling Mac28f0212023-03-24 16:07:15 -07004258 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004259 } finally {
4260 Binder.restoreCallingIdentity(identity);
4261 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004262 }
4263
4264 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004265 * Send the dialer code if called from the current default dialer or the caller has
4266 * carrier privilege.
4267 * @param inputCode The dialer code to send
4268 */
4269 @Override
4270 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004271 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004272 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004273 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4274 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004275 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004276 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004277 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004278 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004279
4280 final long identity = Binder.clearCallingIdentity();
4281 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004282 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004283 } finally {
4284 Binder.restoreCallingIdentity(identity);
4285 }
fionaxu235cc5e2017-03-06 22:25:57 -08004286 }
4287
Pengquan Menga1bb6272018-09-06 09:59:22 -07004288 @Override
4289 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004290 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004291 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4292 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08004293 final long identity = Binder.clearCallingIdentity();
4294 try {
4295 if (!isActiveSubscription(subId)) {
4296 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4297 }
4298 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4299 } finally {
4300 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004301 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004302 }
4303
Brad Ebinger35c841c2018-10-01 10:40:55 -07004304 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004305 public boolean isInEmergencySmsMode() {
4306 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4307 final long identity = Binder.clearCallingIdentity();
4308 try {
4309 for (Phone phone : PhoneFactory.getPhones()) {
4310 if (phone.isInEmergencySmsMode()) {
4311 return true;
4312 }
4313 }
4314 } finally {
4315 Binder.restoreCallingIdentity(identity);
4316 }
4317 return false;
4318 }
4319
shilu366312e2019-12-17 09:28:10 -08004320 /**
4321 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4322 * @param subId The subscription to use to check the configuration.
4323 * @param c The callback that will be used to send the result.
4324 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004325 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004326 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4327 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004328 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004329 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004330
4331 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4332 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4333 "IMS not available on device.");
4334 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004335 final long token = Binder.clearCallingIdentity();
4336 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004337 int slotId = getSlotIndexOrException(subId);
4338 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004339
4340 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4341 if (controller != null) {
4342 ImsManager imsManager = controller.getImsManager(subId);
4343 if (imsManager != null) {
4344 imsManager.addRegistrationCallbackForSubscription(c, subId);
4345 } else {
4346 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4347 }
4348 } else {
4349 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4350 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004351 } catch (ImsException e) {
4352 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004353 } finally {
4354 Binder.restoreCallingIdentity(token);
4355 }
4356 }
4357
shilu366312e2019-12-17 09:28:10 -08004358 /**
4359 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4360 * @param subId The subscription to use to check the configuration.
4361 * @param c The callback that will be used to send the result.
4362 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004363 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004364 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004365 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004366 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004367 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4368 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4369 }
Meng Wangafbc5852019-09-19 17:37:13 -07004370 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004371
Meng Wangafbc5852019-09-19 17:37:13 -07004372 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004373 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4374 if (controller != null) {
4375 ImsManager imsManager = controller.getImsManager(subId);
4376 if (imsManager != null) {
4377 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4378 } else {
4379 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4380 + "is inactive, ignoring unregister.");
4381 // If the ImsManager is not valid, just return, since the callback
4382 // will already have been removed internally.
4383 }
4384 }
Meng Wangafbc5852019-09-19 17:37:13 -07004385 } finally {
4386 Binder.restoreCallingIdentity(token);
4387 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004388 }
4389
Brad Ebingera34a6c22019-10-22 17:36:18 -07004390 /**
4391 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4392 */
4393 @Override
4394 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4395 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4396 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4397 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4398 "IMS not available on device.");
4399 }
4400 final long token = Binder.clearCallingIdentity();
4401 try {
4402 Phone phone = getPhone(subId);
4403 if (phone == null) {
4404 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4405 + subId + "'");
4406 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4407 }
4408 phone.getImsRegistrationState(regState -> {
4409 try {
4410 consumer.accept((regState == null)
4411 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4412 } catch (RemoteException e) {
4413 // Ignore if the remote process is no longer available to call back.
4414 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4415 }
4416 });
4417 } finally {
4418 Binder.restoreCallingIdentity(token);
4419 }
4420 }
4421
4422 /**
4423 * Get the transport type for the IMS service registration state.
4424 */
4425 @Override
4426 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004427 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004428 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004429 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4430 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4431 "IMS not available on device.");
4432 }
4433 final long token = Binder.clearCallingIdentity();
4434 try {
4435 Phone phone = getPhone(subId);
4436 if (phone == null) {
4437 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4438 + subId + "'");
4439 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4440 }
4441 phone.getImsRegistrationTech(regTech -> {
4442 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4443 int regTechConverted = (regTech == null)
4444 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4445 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4446 regTechConverted);
4447 try {
4448 consumer.accept(regTechConverted);
4449 } catch (RemoteException e) {
4450 // Ignore if the remote process is no longer available to call back.
4451 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4452 }
4453 });
4454 } finally {
4455 Binder.restoreCallingIdentity(token);
4456 }
4457 }
4458
shilu366312e2019-12-17 09:28:10 -08004459 /**
4460 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4461 * @param subId The subscription to use to check the configuration.
4462 * @param c The callback that will be used to send the result.
4463 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004464 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004465 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4466 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004467 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004468 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004469 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4470 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4471 "IMS not available on device.");
4472 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004473 final long token = Binder.clearCallingIdentity();
4474 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004475 int slotId = getSlotIndexOrException(subId);
4476 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004477
4478 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4479 if (controller != null) {
4480 ImsManager imsManager = controller.getImsManager(subId);
4481 if (imsManager != null) {
4482 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4483 } else {
4484 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4485 }
4486 } else {
4487 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4488 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004489 } catch (ImsException e) {
4490 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004491 } finally {
4492 Binder.restoreCallingIdentity(token);
4493 }
4494 }
4495
shilu366312e2019-12-17 09:28:10 -08004496 /**
4497 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4498 * @param subId The subscription to use to check the configuration.
4499 * @param c The callback that will be used to send the result.
4500 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004501 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004502 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004503 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004504 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004505 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4506 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4507 }
Meng Wangafbc5852019-09-19 17:37:13 -07004508
4509 final long token = Binder.clearCallingIdentity();
4510 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004511 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4512 if (controller != null) {
4513 ImsManager imsManager = controller.getImsManager(subId);
4514 if (imsManager != null) {
4515 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4516 } else {
4517 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4518 + " is inactive, ignoring unregister.");
4519 // If the ImsManager is not valid, just return, since the callback
4520 // will already have been removed internally.
4521 }
4522 }
Meng Wangafbc5852019-09-19 17:37:13 -07004523 } finally {
4524 Binder.restoreCallingIdentity(token);
4525 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004526 }
4527
4528 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004529 public boolean isCapable(int subId, int capability, int regTech) {
4530 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004531 final long token = Binder.clearCallingIdentity();
4532 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004533 int slotId = getSlotIndexOrException(subId);
4534 verifyImsMmTelConfiguredOrThrow(slotId);
4535 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4536 } catch (com.android.ims.ImsException e) {
4537 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4538 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004539 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004540 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4541 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004542 } finally {
4543 Binder.restoreCallingIdentity(token);
4544 }
4545 }
4546
4547 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004548 public boolean isAvailable(int subId, int capability, int regTech) {
4549 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004550 final long token = Binder.clearCallingIdentity();
4551 try {
4552 Phone phone = getPhone(subId);
4553 if (phone == null) return false;
4554 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004555 } catch (com.android.ims.ImsException e) {
4556 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4557 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004558 } finally {
4559 Binder.restoreCallingIdentity(token);
4560 }
4561 }
4562
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004563 /**
4564 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4565 * subscription.
4566 * @param subId The subscription to use to check the configuration.
4567 * @param callback The callback that will be used to send the result.
4568 * @param capability The MmTelFeature capability that will be used to send the result.
4569 * @param transportType The transport type of the MmTelFeature capability.
4570 */
4571 @Override
4572 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4573 int transportType) {
4574 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004575 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4576 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4577 "IMS not available on device.");
4578 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004579 final long token = Binder.clearCallingIdentity();
4580 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004581 int slotId = getSlotIndex(subId);
4582 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4583 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4584 + subId + "'");
4585 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4586 }
4587 verifyImsMmTelConfiguredOrThrow(slotId);
4588 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4589 transportType, aBoolean -> {
4590 try {
4591 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4592 } catch (RemoteException e) {
4593 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4594 + "running. Ignore");
4595 }
4596 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004597 } catch (ImsException e) {
4598 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004599 } finally {
4600 Binder.restoreCallingIdentity(token);
4601 }
4602 }
4603
shilu366312e2019-12-17 09:28:10 -08004604 /**
4605 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4606 * @param subId The subscription to use to check the configuration.
4607 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004608 @Override
4609 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004610 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004611 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004612
Brad Ebinger35c841c2018-10-01 10:40:55 -07004613 final long token = Binder.clearCallingIdentity();
4614 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004615 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004616 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004617 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004618 } catch (ImsException e) {
4619 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004620 } finally {
4621 Binder.restoreCallingIdentity(token);
4622 }
4623 }
4624
4625 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004626 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004628 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004629 final long identity = Binder.clearCallingIdentity();
4630 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004631 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004632 // This setting doesn't require an active ImsService connection, so do not verify. The
4633 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004634 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004635 } catch (ImsException e) {
4636 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004637 } finally {
4638 Binder.restoreCallingIdentity(identity);
4639 }
4640 }
4641
shilu366312e2019-12-17 09:28:10 -08004642 /**
4643 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4644 * @param subId The subscription to use to check the configuration.
4645 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004646 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004647 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004648 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004649 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004650 final long identity = Binder.clearCallingIdentity();
4651 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004652 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004653 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004654 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004655 } catch (ImsException e) {
4656 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004657 } finally {
4658 Binder.restoreCallingIdentity(identity);
4659 }
4660 }
4661
4662 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004663 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004664 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004665 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004666 final long identity = Binder.clearCallingIdentity();
4667 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004668 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004669 // This setting doesn't require an active ImsService connection, so do not verify. The
4670 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004671 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004672 } catch (ImsException e) {
4673 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004674 } finally {
4675 Binder.restoreCallingIdentity(identity);
4676 }
4677 }
4678
shilu366312e2019-12-17 09:28:10 -08004679 /**
4680 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4681 * @param subId The subscription to use to check the configuration.
4682 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004683 @Override
4684 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004685 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004686 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004687 final long identity = Binder.clearCallingIdentity();
4688 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004689 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004690 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004691 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004692 } catch (ImsException e) {
4693 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004694 } finally {
4695 Binder.restoreCallingIdentity(identity);
4696 }
4697 }
4698
4699 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004700 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004701 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004702 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004703 final long identity = Binder.clearCallingIdentity();
4704 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004705 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004706 // This setting doesn't require an active ImsService connection, so do not verify. The
4707 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004708 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004709 } catch (ImsException e) {
4710 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004711 } finally {
4712 Binder.restoreCallingIdentity(identity);
4713 }
4714 }
4715
shilu366312e2019-12-17 09:28:10 -08004716 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004717 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4718 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4719 * @param subId The subscription to use to check the configuration.
4720 */
4721 @Override
4722 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004723 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004724 mApp, subId, "isCrossSimCallingEnabledByUser");
4725 final long identity = Binder.clearCallingIdentity();
4726 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004727 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004728 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004729 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004730 } catch (ImsException e) {
4731 throw new ServiceSpecificException(e.getCode());
4732 } finally {
4733 Binder.restoreCallingIdentity(identity);
4734 }
4735 }
4736
4737 /**
4738 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4739 * Requires MODIFY_PHONE_STATE permission.
4740 * @param subId The subscription to use to check the configuration.
4741 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4742 * false otherwise
4743 */
4744 @Override
4745 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4746 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4747 "setCrossSimCallingEnabled");
4748 final long identity = Binder.clearCallingIdentity();
4749 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004750 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004751 // This setting doesn't require an active ImsService connection, so do not verify. The
4752 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004753 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004754 } catch (ImsException e) {
4755 throw new ServiceSpecificException(e.getCode());
4756 } finally {
4757 Binder.restoreCallingIdentity(identity);
4758 }
4759 }
4760
4761 /**
shilu366312e2019-12-17 09:28:10 -08004762 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4763 * @param subId The subscription to use to check the configuration.
4764 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004765 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004766
Brad Ebinger35c841c2018-10-01 10:40:55 -07004767 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004768 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004769 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004770 final long identity = Binder.clearCallingIdentity();
4771 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004772 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004773 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004774 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004775 } catch (ImsException e) {
4776 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004777 } finally {
4778 Binder.restoreCallingIdentity(identity);
4779 }
4780 }
4781
4782 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004783 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004784 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004785 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004786 final long identity = Binder.clearCallingIdentity();
4787 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004788 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004789 // This setting doesn't require an active ImsService connection, so do not verify. The
4790 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004791 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004792 } catch (ImsException e) {
4793 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004794 } finally {
4795 Binder.restoreCallingIdentity(identity);
4796 }
4797 }
4798
4799 @Override
4800 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4801 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4802 "setVoWiFiNonPersistent");
4803 final long identity = Binder.clearCallingIdentity();
4804 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004805 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004806 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004807 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004808 } catch (ImsException e) {
4809 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004810 } finally {
4811 Binder.restoreCallingIdentity(identity);
4812 }
4813 }
4814
shilu366312e2019-12-17 09:28:10 -08004815 /**
4816 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4817 * @param subId The subscription to use to check the configuration.
4818 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004819 @Override
4820 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004821 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004822 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004823 final long identity = Binder.clearCallingIdentity();
4824 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004825 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004826 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004827 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004828 } catch (ImsException e) {
4829 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004830 } finally {
4831 Binder.restoreCallingIdentity(identity);
4832 }
4833 }
4834
4835 @Override
4836 public void setVoWiFiModeSetting(int subId, int mode) {
4837 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4838 "setVoWiFiModeSetting");
4839 final long identity = Binder.clearCallingIdentity();
4840 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004841 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004842 // This setting doesn't require an active ImsService connection, so do not verify. The
4843 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004844 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004845 } catch (ImsException e) {
4846 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004847 } finally {
4848 Binder.restoreCallingIdentity(identity);
4849 }
4850 }
4851
4852 @Override
4853 public int getVoWiFiRoamingModeSetting(int subId) {
4854 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4855 final long identity = Binder.clearCallingIdentity();
4856 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004857 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004858 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004859 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004860 } catch (ImsException e) {
4861 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004862 } finally {
4863 Binder.restoreCallingIdentity(identity);
4864 }
4865 }
4866
4867 @Override
4868 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4870 "setVoWiFiRoamingModeSetting");
4871 final long identity = Binder.clearCallingIdentity();
4872 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004873 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004874 // This setting doesn't require an active ImsService connection, so do not verify. The
4875 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004876 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004877 } catch (ImsException e) {
4878 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004879 } finally {
4880 Binder.restoreCallingIdentity(identity);
4881 }
4882 }
4883
4884 @Override
4885 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4886 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4887 "setRttCapabilityEnabled");
4888 final long identity = Binder.clearCallingIdentity();
4889 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004890 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004891 // This setting doesn't require an active ImsService connection, so do not verify. The
4892 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004893 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004894 } catch (ImsException e) {
4895 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004896 } finally {
4897 Binder.restoreCallingIdentity(identity);
4898 }
4899 }
4900
shilu366312e2019-12-17 09:28:10 -08004901 /**
4902 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4903 * @param subId The subscription to use to check the configuration.
4904 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004905 @Override
4906 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004907 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004908 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004909 final long identity = Binder.clearCallingIdentity();
4910 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004911 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004912 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004913 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004914 } catch (ImsException e) {
4915 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004916 } finally {
4917 Binder.restoreCallingIdentity(identity);
4918 }
4919 }
4920
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004921 @Override
4922 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4923 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004924
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004925 final long identity = Binder.clearCallingIdentity();
4926 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004927 if (!isImsAvailableOnDevice()) {
4928 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4929 "IMS not available on device.");
4930 }
4931 int slotId = getSlotIndexOrException(subId);
4932 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004933
4934 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4935 if (controller != null) {
4936 ImsManager imsManager = controller.getImsManager(subId);
4937 if (imsManager != null) {
4938 imsManager.addProvisioningCallbackForSubscription(callback, subId);
4939 } else {
4940 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4941 }
4942 } else {
4943 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4944 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004945 } catch (ImsException e) {
4946 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004947 } finally {
4948 Binder.restoreCallingIdentity(identity);
4949 }
4950 }
4951
4952 @Override
4953 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4954 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004955
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004956 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004957 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4958 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4959 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004960 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004961 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4962 if (controller != null) {
4963 ImsManager imsManager = controller.getImsManager(subId);
4964 if (imsManager != null) {
4965 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
4966 } else {
4967 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4968 + " is inactive, ignoring unregister.");
4969 // If the ImsManager is not valid, just return, since the callback will already
4970 // have been removed internally.
4971 }
4972 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004973 } finally {
4974 Binder.restoreCallingIdentity(identity);
4975 }
4976 }
4977
joonhunshincffb7fc2021-11-28 07:32:01 +00004978 @Override
4979 public void registerFeatureProvisioningChangedCallback(int subId,
4980 IFeatureProvisioningCallback callback) {
4981 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4982 mApp, subId, "registerFeatureProvisioningChangedCallback");
4983
4984 final long identity = Binder.clearCallingIdentity();
4985 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4986 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4987 }
4988
joonhunshin91bc1952022-04-29 08:47:15 +00004989 try {
4990 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4991 if (controller == null) {
4992 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4993 "Device does not support IMS");
4994 }
4995 controller.addFeatureProvisioningChangedCallback(subId, callback);
4996 } finally {
4997 Binder.restoreCallingIdentity(identity);
4998 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004999 }
5000
5001 @Override
5002 public void unregisterFeatureProvisioningChangedCallback(int subId,
5003 IFeatureProvisioningCallback callback) {
5004 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5005 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5006
5007 final long identity = Binder.clearCallingIdentity();
5008 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5009 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5010 }
5011
joonhunshin91bc1952022-04-29 08:47:15 +00005012 try {
5013 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5014 if (controller == null) {
5015 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5016 return;
5017 }
5018 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5019 } finally {
5020 Binder.restoreCallingIdentity(identity);
5021 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005022 }
allenwtsu99c623b2020-01-03 18:24:23 +08005023
5024 private void checkModifyPhoneStatePermission(int subId, String message) {
5025 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5026 message);
5027 }
5028
allenwtsu99c623b2020-01-03 18:24:23 +08005029 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005030 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005031 boolean isProvisioned) {
5032 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5033
5034 final long identity = Binder.clearCallingIdentity();
5035 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005036 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5037 if (controller == null) {
5038 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5039 return;
5040 }
5041 controller.setRcsProvisioningStatusForCapability(
5042 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005043 } finally {
5044 Binder.restoreCallingIdentity(identity);
5045 }
allenwtsu99c623b2020-01-03 18:24:23 +08005046 }
5047
5048
5049 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005050 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5051 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5052 mApp, subId, "getRcsProvisioningStatusForCapability");
5053
allenwtsu99c623b2020-01-03 18:24:23 +08005054 final long identity = Binder.clearCallingIdentity();
5055 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005056 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5057 if (controller == null) {
5058 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5059
5060 // device does not support IMS, this method will return true always.
5061 return true;
5062 }
5063 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005064 } finally {
5065 Binder.restoreCallingIdentity(identity);
5066 }
5067 }
5068
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005069 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005070 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5071 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005072 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005073
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005074 final long identity = Binder.clearCallingIdentity();
5075 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005076 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5077 if (controller == null) {
5078 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5079 return;
5080 }
5081 controller.setImsProvisioningStatusForCapability(
5082 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005083 } finally {
5084 Binder.restoreCallingIdentity(identity);
5085 }
5086 }
5087
5088 @Override
5089 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005090 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5091 mApp, subId, "getProvisioningStatusForCapability");
5092
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005093 final long identity = Binder.clearCallingIdentity();
5094 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005095 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5096 if (controller == null) {
5097 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005098
joonhunshin91bc1952022-04-29 08:47:15 +00005099 // device does not support IMS, this method will return true always.
5100 return true;
5101 }
5102 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005103 } finally {
5104 Binder.restoreCallingIdentity(identity);
5105 }
5106 }
5107
5108 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005109 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5110 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5111 mApp, subId, "isProvisioningRequiredForCapability");
5112
5113 final long identity = Binder.clearCallingIdentity();
5114 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005115 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5116 if (controller == null) {
5117 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5118
5119 // device does not support IMS, this method will return false
5120 return false;
5121 }
5122 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005123 } finally {
5124 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005125 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005126 }
5127
5128 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005129 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5130 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5131 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005132
joonhunshincffb7fc2021-11-28 07:32:01 +00005133 final long identity = Binder.clearCallingIdentity();
5134 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005135 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5136 if (controller == null) {
5137 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5138
5139 // device does not support IMS, this method will return false
5140 return false;
5141 }
5142 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005143 } finally {
5144 Binder.restoreCallingIdentity(identity);
5145 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005146 }
5147
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005148 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005149 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005150 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5151 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5152 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005153 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5154 mApp, subId, "getImsProvisioningInt");
5155
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005156 final long identity = Binder.clearCallingIdentity();
5157 try {
5158 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005159 int slotId = getSlotIndex(subId);
5160 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5161 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5162 + subId + "' for key:" + key);
5163 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5164 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005165
joonhunshin91bc1952022-04-29 08:47:15 +00005166 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5167 if (controller == null) {
5168 loge("getImsProvisioningInt: Device does not support IMS");
5169
5170 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5171 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5172 }
5173 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005174 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5175 return retVal;
5176 }
5177
calvinpanb5a34062021-02-08 19:59:36 +08005178 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005179 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005180 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5181 + subId + "' for key:" + key);
5182 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005183 } finally {
5184 Binder.restoreCallingIdentity(identity);
5185 }
5186 }
5187
5188 @Override
5189 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005190 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5191 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5192 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005193 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5194 mApp, subId, "getImsProvisioningString");
5195
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005196 final long identity = Binder.clearCallingIdentity();
5197 try {
5198 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005199 int slotId = getSlotIndex(subId);
5200 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5201 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5202 + subId + "' for key:" + key);
5203 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5204 }
calvinpanb5a34062021-02-08 19:59:36 +08005205 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005206 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005207 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5208 + subId + "' for key:" + key);
5209 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005210 } finally {
5211 Binder.restoreCallingIdentity(identity);
5212 }
5213 }
5214
5215 @Override
5216 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005217 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5218 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5219 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5221 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005222
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005223 final long identity = Binder.clearCallingIdentity();
5224 try {
5225 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005226 int slotId = getSlotIndex(subId);
5227 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5228 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5229 + subId + "' for key:" + key);
5230 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5231 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005232
joonhunshin91bc1952022-04-29 08:47:15 +00005233 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5234 if (controller == null) {
5235 loge("setImsProvisioningInt: Device does not support IMS");
5236
5237 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5238 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5239 }
5240 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005241 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5242 return retVal;
5243 }
5244
calvinpanb5a34062021-02-08 19:59:36 +08005245 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5246 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005247 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005248 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005249 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005250 } finally {
5251 Binder.restoreCallingIdentity(identity);
5252 }
5253 }
5254
5255 @Override
5256 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005257 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5258 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5259 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005260 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5261 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005262 final long identity = Binder.clearCallingIdentity();
5263 try {
5264 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005265 int slotId = getSlotIndex(subId);
5266 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5267 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5268 + subId + "' for key:" + key);
5269 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5270 }
calvinpanb5a34062021-02-08 19:59:36 +08005271 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5272 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005273 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005274 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005275 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005276 } finally {
5277 Binder.restoreCallingIdentity(identity);
5278 }
5279 }
5280
Brad Ebinger919631e2021-06-02 17:46:35 -07005281 /**
5282 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5283 * for the given slot ID or no ImsResolver instance has been created.
5284 * @param slotId The slot ID that the IMS service is created for.
5285 * @throws ImsException If there is no ImsService configured for this slot.
5286 */
5287 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5288 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5289 ImsFeature.FEATURE_MMTEL)) {
5290 throw new ImsException("This subscription does not support MMTEL over IMS",
5291 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5292 }
5293 }
5294
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005295 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005296 int slotId = SubscriptionManager.getSlotIndex(subId);
5297 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005298 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5299 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005300 }
5301 return slotId;
5302 }
5303
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005304 private int getSlotIndex(int subId) {
5305 int slotId = SubscriptionManager.getSlotIndex(subId);
5306 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5307 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5308 }
5309 return slotId;
5310 }
5311
Wink Saville36469e72014-06-11 15:17:00 -07005312 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005313 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005314 */
5315 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005316 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5317 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005318 try {
5319 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5320 } catch (SecurityException se) {
5321 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5322 throw new SecurityException("Package " + callingPackage + " does not belong to "
5323 + Binder.getCallingUid());
5324 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005325 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005326 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005327 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005328 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005329 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005330 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005331 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005332 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5333 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005334
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005335 final long identity = Binder.clearCallingIdentity();
5336 try {
5337 final Phone phone = getPhone(subId);
5338 if (phone != null) {
5339 return phone.getServiceState().getDataNetworkType();
5340 } else {
5341 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5342 }
5343 } finally {
5344 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005345 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005346 }
5347
5348 /**
5349 * Returns the data network type
5350 */
5351 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005352 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005353 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005354 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005355 }
5356
5357 /**
5358 * Returns the data network type for a subId
5359 */
5360 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005361 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5362 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005363 String functionName = "getDataNetworkTypeForSubscriber";
5364 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5365 mApp, functionName)) {
5366 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5367 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5368 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5369 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005370 }
5371
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005372 final long identity = Binder.clearCallingIdentity();
5373 try {
5374 final Phone phone = getPhone(subId);
5375 if (phone != null) {
5376 return phone.getServiceState().getDataNetworkType();
5377 } else {
5378 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5379 }
5380 } finally {
5381 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005382 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005383 }
5384
5385 /**
Wink Saville36469e72014-06-11 15:17:00 -07005386 * Returns the Voice network type for a subId
5387 */
5388 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005389 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5390 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005391 String functionName = "getVoiceNetworkTypeForSubscriber";
5392 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5393 mApp, functionName)) {
5394 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5395 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5396 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5397 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005398 }
5399
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005400 final long identity = Binder.clearCallingIdentity();
5401 try {
5402 final Phone phone = getPhone(subId);
5403 if (phone != null) {
5404 return phone.getServiceState().getVoiceNetworkType();
5405 } else {
5406 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5407 }
5408 } finally {
5409 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005410 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005411 }
5412
5413 /**
5414 * @return true if a ICC card is present
5415 */
5416 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005417 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005418 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005419 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005420 }
5421
5422 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005423 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005424 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005425 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005426 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005427 final long identity = Binder.clearCallingIdentity();
5428 try {
5429 final Phone phone = PhoneFactory.getPhone(slotIndex);
5430 if (phone != null) {
5431 return phone.getIccCard().hasIccCard();
5432 } else {
5433 return false;
5434 }
5435 } finally {
5436 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005437 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005438 }
5439
5440 /**
5441 * Return if the current radio is LTE on CDMA. This
5442 * is a tri-state return value as for a period of time
5443 * the mode may be unknown.
5444 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005445 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005446 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005447 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005448 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005449 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005450 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5451 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5452 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005453 }
5454
Sanket Padawe356d7632015-06-22 14:03:32 -07005455 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005456 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5457 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005458 try {
5459 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5460 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005461 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5462 }
5463
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005464 final long identity = Binder.clearCallingIdentity();
5465 try {
5466 final Phone phone = getPhone(subId);
5467 if (phone == null) {
5468 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5469 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005470 return TelephonyProperties.lte_on_cdma_device()
5471 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005472 }
5473 } finally {
5474 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005475 }
Wink Saville36469e72014-06-11 15:17:00 -07005476 }
5477
Wink Saville36469e72014-06-11 15:17:00 -07005478 /**
5479 * {@hide}
5480 * Returns Default subId, 0 in the case of single standby.
5481 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005482 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005483 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005484 }
5485
Shishir Agrawala9f32182016-04-12 12:00:16 -07005486 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005487 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005488 }
5489
Wink Savilleb564aae2014-10-23 10:18:09 -07005490 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005491 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005492 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005493
Pengquan Menge92a50d2018-09-21 15:54:48 -07005494 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005495 return getSubscriptionManagerService().isActiveSubId(subId,
5496 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005497 }
5498
Ihab Awadf2177b72013-11-25 13:33:23 -08005499 /**
5500 * @see android.telephony.TelephonyManager.WifiCallingChoices
5501 */
5502 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005503 final long identity = Binder.clearCallingIdentity();
5504 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005505 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5507 getWhenToMakeWifiCallsDefaultPreference());
5508 } finally {
5509 Binder.restoreCallingIdentity(identity);
5510 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005511 }
5512
5513 /**
5514 * @see android.telephony.TelephonyManager.WifiCallingChoices
5515 */
5516 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005517 final long identity = Binder.clearCallingIdentity();
5518 try {
5519 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005520 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5522 } finally {
5523 Binder.restoreCallingIdentity(identity);
5524 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005525 }
5526
Sailesh Nepald1e68152013-12-12 19:08:02 -08005527 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005528 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005529 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005530 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005531
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005532 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5533 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5534 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005535 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005536 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005537 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005538 }
5539 return PhoneFactory.getPhone(phoneId);
5540 }
5541
Shishir Agrawal566b7612013-10-28 14:41:00 -07005542 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005543 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005544 @NonNull IccLogicalChannelRequest request) {
5545 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5546 /*message=*/ "iccOpenLogicalChannel");
5547
5548 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5549 // Verify that the callingPackage in the request belongs to the calling UID
5550 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5551
5552 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005553 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005554
Rambo Wanga1782702021-11-10 20:15:19 -08005555 private Phone getPhoneFromValidIccLogicalChannelRequest(
5556 @NonNull IccLogicalChannelRequest request, String message) {
5557 Phone phone;
5558 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5559 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5560 mApp, request.subId, message);
5561 phone = getPhoneFromSubId(request.subId);
5562 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5563 enforceModifyPermission();
5564 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5565 } else {
5566 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005567 }
Rambo Wanga1782702021-11-10 20:15:19 -08005568 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005569 }
5570
5571 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005572 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005573 final long identity = Binder.clearCallingIdentity();
5574 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005575 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005576 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005577 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5578 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005579 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5580 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005581 loge("The calling package is not allowed to access ISD-R.");
5582 throw new SecurityException(
5583 "The calling package is not allowed to access ISD-R.");
5584 }
Derek Tan740e1672017-06-27 14:56:27 -07005585 }
Derek Tan740e1672017-06-27 14:56:27 -07005586
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005588 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5589 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005590 return response;
5591 } finally {
5592 Binder.restoreCallingIdentity(identity);
5593 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005594 }
5595
5596 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005597 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5598 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5599 /*message=*/"iccCloseLogicalChannel");
5600
5601 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5602
5603 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005604 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005605
Rambo Wanga1782702021-11-10 20:15:19 -08005606 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5607 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005608 // before this feature is enabled, this API should only return false if
5609 // the operation fails instead of throwing runtime exception for
5610 // backward-compatibility.
5611 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5612 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005613 final long identity = Binder.clearCallingIdentity();
5614 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005615 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005616 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005617 }
Chen Xue9d737e2022-01-01 23:41:31 -08005618 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005619 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005620 Boolean success = false;
5621 if (result instanceof RuntimeException) {
5622 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005623 if (shouldThrowExceptionOnFailure) {
5624 throw (RuntimeException) result;
5625 } else {
5626 return false;
5627 }
Chen Xue9d737e2022-01-01 23:41:31 -08005628 } else if (result instanceof Boolean) {
5629 success = (Boolean) result;
5630 } else {
5631 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5632 }
Rambo Wanga1782702021-11-10 20:15:19 -08005633 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005634 return success;
5635 } finally {
5636 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005637 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005638 }
5639
5640 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005641 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005642 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005643 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5644 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005645 if (DBG) {
5646 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5647 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5648 + p3 + " data=" + data);
5649 }
5650 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5651 command, p1, p2, p3, data);
5652 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005653
Jordan Liu4c733742019-02-28 12:03:40 -08005654 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005655 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005656 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005657 enforceModifyPermission();
5658 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005659 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005660 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5661 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005662 }
5663 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005664 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5665 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005666 }
5667
5668 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5669 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005670 final long identity = Binder.clearCallingIdentity();
5671 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005672 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673 return "";
5674 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005675
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005676 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005677 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5678 null /* workSource */);
5679 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005680
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681 // Append the returned status code to the end of the response payload.
5682 String s = Integer.toHexString(
5683 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5684 if (response.payload != null) {
5685 s = IccUtils.bytesToHexString(response.payload) + s;
5686 }
5687 return s;
5688 } finally {
5689 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005690 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005691 }
Jake Hambye994d462014-02-03 13:10:13 -08005692
Evan Charltonc66da362014-05-16 14:06:40 -07005693 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005694 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5695 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005696 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5697 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005698 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005699 if (DBG) {
5700 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5701 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5702 }
5703 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5704 cla, command, p1, p2, p3, data);
5705 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005706
Jordan Liu4c733742019-02-28 12:03:40 -08005707 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005708 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005709 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005710 enforceModifyPermission();
5711 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5712 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005713 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005714 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5715 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005716 }
5717
5718 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005719 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5720 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005721 }
5722
5723 // open APDU basic channel assuming the caller has sufficient permissions
5724 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5725 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005726 final long identity = Binder.clearCallingIdentity();
5727 try {
5728 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5729 && TextUtils.equals(ISDR_AID, data)) {
5730 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005731 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5732 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005733 if (bestComponent == null
5734 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5735 loge("The calling package is not allowed to select ISD-R.");
5736 throw new SecurityException(
5737 "The calling package is not allowed to select ISD-R.");
5738 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005739 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005740
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005741 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005742 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5743 null /* workSource */);
5744 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005745
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005746 // Append the returned status code to the end of the response payload.
5747 String s = Integer.toHexString(
5748 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5749 if (response.payload != null) {
5750 s = IccUtils.bytesToHexString(response.payload) + s;
5751 }
5752 return s;
5753 } finally {
5754 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005755 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005756 }
5757
5758 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005759 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005760 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005761 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5762 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005763
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005764 final long identity = Binder.clearCallingIdentity();
5765 try {
5766 if (DBG) {
5767 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5768 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5769 }
5770
5771 IccIoResult response =
5772 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5773 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5774 subId);
5775
5776 if (DBG) {
5777 log("Exchange SIM_IO [R]" + response);
5778 }
5779
5780 byte[] result = null;
5781 int length = 2;
5782 if (response.payload != null) {
5783 length = 2 + response.payload.length;
5784 result = new byte[length];
5785 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5786 } else {
5787 result = new byte[length];
5788 }
5789
5790 result[length - 1] = (byte) response.sw2;
5791 result[length - 2] = (byte) response.sw1;
5792 return result;
5793 } finally {
5794 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005795 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005796 }
5797
Nathan Haroldb3014052017-01-25 15:57:32 -08005798 /**
5799 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5800 * on a particular subscription
5801 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005802 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5803 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005804 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005805 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005806 return null;
5807 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005808
5809 final long identity = Binder.clearCallingIdentity();
5810 try {
5811 if (appType != TelephonyManager.APPTYPE_USIM
5812 && appType != TelephonyManager.APPTYPE_SIM) {
5813 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5814 return null;
5815 }
5816 Object response = sendRequest(
5817 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5818 if (response instanceof String[]) {
5819 return (String[]) response;
5820 }
yincheng zhao2737e882019-09-06 17:06:54 -07005821 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005822 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005823 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005824 } finally {
5825 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005826 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005827 }
5828
yincheng zhao2737e882019-09-06 17:06:54 -07005829 /**
5830 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5831 * subscription.
5832 *
5833 * @param subId the id of the subscription.
5834 * @param appType the uicc app type, must be USIM or SIM.
5835 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5836 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005837 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005838 * @return number of fplmns that is successfully written to the SIM.
5839 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005840 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5841 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005842 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5843 mApp, subId, "setForbiddenPlmns");
5844
yincheng zhao2737e882019-09-06 17:06:54 -07005845 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5846 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5847 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5848 }
5849 if (fplmns == null) {
5850 throw new IllegalArgumentException("Fplmn List provided is null");
5851 }
5852 for (String fplmn : fplmns) {
5853 if (!CellIdentity.isValidPlmn(fplmn)) {
5854 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5855 }
5856 }
5857 final long identity = Binder.clearCallingIdentity();
5858 try {
5859 Object response = sendRequest(
5860 CMD_SET_FORBIDDEN_PLMNS,
5861 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5862 subId);
5863 return (int) response;
5864 } finally {
5865 Binder.restoreCallingIdentity(identity);
5866 }
5867 }
5868
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005869 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005870 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5872 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005873
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005874 final long identity = Binder.clearCallingIdentity();
5875 try {
5876 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5877 if (response.payload == null) {
5878 return "";
5879 }
Evan Charltonc66da362014-05-16 14:06:40 -07005880
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005881 // Append the returned status code to the end of the response payload.
5882 String s = Integer.toHexString(
5883 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5884 s = IccUtils.bytesToHexString(response.payload) + s;
5885 return s;
5886 } finally {
5887 Binder.restoreCallingIdentity(identity);
5888 }
Evan Charltonc66da362014-05-16 14:06:40 -07005889 }
5890
Jake Hambye994d462014-02-03 13:10:13 -08005891 /**
5892 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5893 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5894 *
5895 * @param itemID the ID of the item to read
5896 * @return the NV item as a String, or null on error.
5897 */
5898 @Override
5899 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005900 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005901 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5902 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005903
5904 final long identity = Binder.clearCallingIdentity();
5905 try {
5906 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005907 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005908 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5909 return value;
5910 } finally {
5911 Binder.restoreCallingIdentity(identity);
5912 }
Jake Hambye994d462014-02-03 13:10:13 -08005913 }
5914
5915 /**
5916 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5917 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5918 *
5919 * @param itemID the ID of the item to read
5920 * @param itemValue the value to write, as a String
5921 * @return true on success; false on any failure
5922 */
5923 @Override
5924 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005925 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005926 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5927 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005928
5929 final long identity = Binder.clearCallingIdentity();
5930 try {
5931 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5932 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005933 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005934 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5935 return success;
5936 } finally {
5937 Binder.restoreCallingIdentity(identity);
5938 }
Jake Hambye994d462014-02-03 13:10:13 -08005939 }
5940
5941 /**
5942 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5943 * Used for device configuration by some CDMA operators.
5944 *
5945 * @param preferredRoamingList byte array containing the new PRL
5946 * @return true on success; false on any failure
5947 */
5948 @Override
5949 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5951 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005952
5953 final long identity = Binder.clearCallingIdentity();
5954 try {
5955 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5956 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5957 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5958 return success;
5959 } finally {
5960 Binder.restoreCallingIdentity(identity);
5961 }
Jake Hambye994d462014-02-03 13:10:13 -08005962 }
5963
5964 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005965 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005966 * Used for device configuration by some CDMA operators.
5967 *
chen xu6dac5ab2018-10-26 17:39:23 -07005968 * @param slotIndex - device slot.
5969 *
Jake Hambye994d462014-02-03 13:10:13 -08005970 * @return true on success; false on any failure
5971 */
5972 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005973 public boolean resetModemConfig(int slotIndex) {
5974 Phone phone = PhoneFactory.getPhone(slotIndex);
5975 if (phone != null) {
5976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5977 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005978
chen xu6dac5ab2018-10-26 17:39:23 -07005979 final long identity = Binder.clearCallingIdentity();
5980 try {
5981 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5982 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5983 return success;
5984 } finally {
5985 Binder.restoreCallingIdentity(identity);
5986 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005987 }
chen xu6dac5ab2018-10-26 17:39:23 -07005988 return false;
5989 }
5990
5991 /**
5992 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5993 *
5994 * @param slotIndex - device slot.
5995 *
5996 * @return true on success; false on any failure
5997 */
5998 @Override
5999 public boolean rebootModem(int slotIndex) {
6000 Phone phone = PhoneFactory.getPhone(slotIndex);
6001 if (phone != null) {
6002 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6003 mApp, phone.getSubId(), "rebootModem");
6004
6005 final long identity = Binder.clearCallingIdentity();
6006 try {
6007 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6008 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6009 return success;
6010 } finally {
6011 Binder.restoreCallingIdentity(identity);
6012 }
6013 }
6014 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006015 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006016
Brad Ebinger51f743a2017-01-23 13:50:20 -08006017 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006018 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6019 * {@link #disableIms(int)}.
6020 * @param slotIndex device slot.
6021 */
6022 public void resetIms(int slotIndex) {
6023 enforceModifyPermission();
6024
6025 final long identity = Binder.clearCallingIdentity();
6026 try {
6027 if (mImsResolver == null) {
6028 // may happen if the does not support IMS.
6029 return;
6030 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006031 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006032 } finally {
6033 Binder.restoreCallingIdentity(identity);
6034 }
6035 }
6036
6037 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006038 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6039 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006040 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006041 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006042 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006043
6044 final long identity = Binder.clearCallingIdentity();
6045 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006046 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006047 // may happen if the device does not support IMS.
6048 return;
6049 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006050 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006051 } finally {
6052 Binder.restoreCallingIdentity(identity);
6053 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006054 }
6055
6056 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006057 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6058 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006059 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006060 public void disableIms(int slotId) {
6061 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006062
6063 final long identity = Binder.clearCallingIdentity();
6064 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006065 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006066 // may happen if the device does not support IMS.
6067 return;
6068 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006069 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006070 } finally {
6071 Binder.restoreCallingIdentity(identity);
6072 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006073 }
6074
6075 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006076 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6077 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006078 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006079 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006080 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006081 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006082
6083 final long identity = Binder.clearCallingIdentity();
6084 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006085 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006086 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6087 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006088 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006089 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006090 } finally {
6091 Binder.restoreCallingIdentity(identity);
6092 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006093 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006094 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006095 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6096 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006097 @Override
6098 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006099 enforceModifyPermission();
6100
6101 final long identity = Binder.clearCallingIdentity();
6102 try {
6103 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006104 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006105 } finally {
6106 Binder.restoreCallingIdentity(identity);
6107 }
6108 }
6109
6110 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006111 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006112 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006113 */
6114 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6115 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006116
6117 final long identity = Binder.clearCallingIdentity();
6118 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006119 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006120 // may happen if the device does not support IMS.
6121 return null;
6122 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006123 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006124 } finally {
6125 Binder.restoreCallingIdentity(identity);
6126 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006127 }
6128
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006129 /**
6130 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006131 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006132 */
6133 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6134 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135
6136 final long identity = Binder.clearCallingIdentity();
6137 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006138 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006139 // may happen if the device does not support IMS.
6140 return null;
6141 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006142 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006143 } finally {
6144 Binder.restoreCallingIdentity(identity);
6145 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006146 }
6147
Brad Ebinger884c07b2018-02-15 16:17:40 -08006148 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006149 * Sets the ImsService Package Name that Telephony will bind to.
6150 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006151 * @param slotIndex the slot ID that the ImsService should bind for.
6152 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006153 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006154 * @param featureTypes An integer array of feature types associated with a packageName.
6155 * @param packageName The name of the package that the current configuration will be replaced
6156 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006157 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006158 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006159 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6160 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006161 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006163 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006164
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006165 final long identity = Binder.clearCallingIdentity();
6166 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006167 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006168 // may happen if the device does not support IMS.
6169 return false;
6170 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006171 Map<Integer, String> featureConfig = new HashMap<>();
6172 for (int featureType : featureTypes) {
6173 featureConfig.put(featureType, packageName);
6174 }
6175 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6176 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006177 } finally {
6178 Binder.restoreCallingIdentity(identity);
6179 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006180 }
6181
6182 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006183 * Clears any carrier ImsService overrides for the slot index specified that were previously
6184 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6185 *
6186 * This should only be used for testing.
6187 *
6188 * @param slotIndex the slot ID that the ImsService should bind for.
6189 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6190 */
6191 @Override
6192 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006193 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6194 "clearCarrierImsServiceOverride");
6195 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006196 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006197
6198 final long identity = Binder.clearCallingIdentity();
6199 try {
6200 if (mImsResolver == null) {
6201 // may happen if the device does not support IMS.
6202 return false;
6203 }
6204 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6205 } finally {
6206 Binder.restoreCallingIdentity(identity);
6207 }
6208 }
6209
6210 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006211 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006212 *
6213 * @param slotId The slot that the ImsService is associated with.
6214 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6215 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006216 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006217 * @return the package name of the ImsService configuration.
6218 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006219 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6220 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006221 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006222 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6223 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006224
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006225 final long identity = Binder.clearCallingIdentity();
6226 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006227 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006228 // may happen if the device does not support IMS.
6229 return "";
6230 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006231 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006232 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6233 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006234 } finally {
6235 Binder.restoreCallingIdentity(identity);
6236 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006237 }
6238
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006239 /**
6240 * Get the MmTelFeature state associated with the requested subscription id.
6241 * @param subId The subscription that the MmTelFeature is associated with.
6242 * @param callback A callback with an integer containing the
6243 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6244 */
6245 @Override
6246 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6247 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006248 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6249 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6250 "IMS not available on device.");
6251 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006252 final long token = Binder.clearCallingIdentity();
6253 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006254 int slotId = getSlotIndex(subId);
6255 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6256 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6257 + subId + "'");
6258 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6259 }
6260 verifyImsMmTelConfiguredOrThrow(slotId);
6261 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6262 try {
6263 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6264 } catch (RemoteException e) {
6265 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6266 + "Ignore");
6267 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006268 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006269 } catch (ImsException e) {
6270 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006271 } finally {
6272 Binder.restoreCallingIdentity(token);
6273 }
6274 }
6275
Daniel Brightbb5840b2021-01-12 15:48:18 -08006276 /**
6277 * Sets the ims registration state on all valid {@link Phone}s.
6278 */
6279 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006280 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006281
6282 final long identity = Binder.clearCallingIdentity();
6283 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006284 // NOTE: Before S, this method only set the default phone.
6285 for (final Phone phone : PhoneFactory.getPhones()) {
6286 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6287 phone.setImsRegistrationState(registered);
6288 }
6289 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006290 } finally {
6291 Binder.restoreCallingIdentity(identity);
6292 }
Wink Saville36469e72014-06-11 15:17:00 -07006293 }
6294
6295 /**
Stuart Scott54788802015-03-30 13:18:01 -07006296 * Set the network selection mode to automatic.
6297 *
6298 */
6299 @Override
6300 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006301 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6302 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006303
6304 final long identity = Binder.clearCallingIdentity();
6305 try {
shilufc958392020-01-20 11:36:01 -08006306 if (!isActiveSubscription(subId)) {
6307 return;
6308 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006309 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006310 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6311 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006312 } finally {
6313 Binder.restoreCallingIdentity(identity);
6314 }
Stuart Scott54788802015-03-30 13:18:01 -07006315 }
6316
Jack Yud10cdd42020-09-28 20:28:01 -07006317 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006318 * Ask the radio to connect to the input network and change selection mode to manual.
6319 *
6320 * @param subId the id of the subscription.
6321 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6322 * the operator to attach to.
6323 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6324 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6325 * normal network selection next time.
6326 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006327 */
6328 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006329 public boolean setNetworkSelectionModeManual(
6330 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6332 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006333
Jack Yu285100e2022-12-02 22:48:35 -08006334 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006335 if (!isActiveSubscription(subId)) {
6336 return false;
6337 }
6338
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006339 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006340 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006341 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006342 if (DBG) {
6343 log("setNetworkSelectionModeManual: subId: " + subId
6344 + " operator: " + operatorInfo);
6345 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006346 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6347 } finally {
6348 Binder.restoreCallingIdentity(identity);
6349 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006350 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006351 /**
shilu84f6e8b2019-12-19 13:58:01 -08006352 * Get the manual network selection
6353 *
6354 * @param subId the id of the subscription.
6355 *
6356 * @return the previously saved user selected PLMN
6357 */
6358 @Override
6359 public String getManualNetworkSelectionPlmn(int subId) {
6360 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006361 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6362 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006363
6364 final long identity = Binder.clearCallingIdentity();
6365 try {
6366 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006367 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006368 }
6369
6370 final Phone phone = getPhone(subId);
6371 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006372 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006373 }
6374 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6375 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006376 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006377 } finally {
6378 Binder.restoreCallingIdentity(identity);
6379 }
6380 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006381
6382 /**
6383 * Scans for available networks.
6384 */
6385 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006386 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6387 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006388 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6389 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006390 LocationAccessPolicy.LocationPermissionResult locationResult =
6391 LocationAccessPolicy.checkLocationPermission(mApp,
6392 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6393 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006394 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006395 .setCallingPid(Binder.getCallingPid())
6396 .setCallingUid(Binder.getCallingUid())
6397 .setMethod("getCellNetworkScanResults")
6398 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006399 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6400 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006401 .build());
6402 switch (locationResult) {
6403 case DENIED_HARD:
6404 throw new SecurityException("Not allowed to access scan results -- location");
6405 case DENIED_SOFT:
6406 return null;
6407 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006408
Pengquan Menga1bb6272018-09-06 09:59:22 -07006409 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006410 try {
6411 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006412 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006413 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006414 } finally {
6415 Binder.restoreCallingIdentity(identity);
6416 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006417 }
6418
6419 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006420 * Get the call forwarding info, given the call forwarding reason.
6421 */
6422 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006423 public void getCallForwarding(int subId, int callForwardingReason,
6424 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006425 enforceReadPrivilegedPermission("getCallForwarding");
6426 long identity = Binder.clearCallingIdentity();
6427 try {
6428 if (DBG) {
6429 log("getCallForwarding: subId " + subId
6430 + " callForwardingReason" + callForwardingReason);
6431 }
Hall Liu27d24262020-09-18 19:04:59 -07006432
6433 Phone phone = getPhone(subId);
6434 if (phone == null) {
6435 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006436 callback.onError(
6437 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006438 } catch (RemoteException e) {
6439 // ignore
6440 }
6441 return;
6442 }
6443
6444 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6445 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6446 @Override
6447 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6448 try {
6449 callback.onCallForwardingInfoAvailable(info);
6450 } catch (RemoteException e) {
6451 // ignore
6452 }
6453 }
6454
6455 @Override
6456 public void onError(int error) {
6457 try {
6458 callback.onError(error);
6459 } catch (RemoteException e) {
6460 // ignore
6461 }
6462 }
6463 });
6464 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006465 } finally {
6466 Binder.restoreCallingIdentity(identity);
6467 }
6468 }
6469
6470 /**
6471 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6472 * reason, the number to forward, and the timeout before the forwarding is attempted.
6473 */
6474 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006475 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6476 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006477 enforceModifyPermission();
6478 long identity = Binder.clearCallingIdentity();
6479 try {
6480 if (DBG) {
6481 log("setCallForwarding: subId " + subId
6482 + " callForwardingInfo" + callForwardingInfo);
6483 }
Hall Liu27d24262020-09-18 19:04:59 -07006484
6485 Phone phone = getPhone(subId);
6486 if (phone == null) {
6487 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006488 callback.accept(
6489 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006490 } catch (RemoteException e) {
6491 // ignore
6492 }
6493 return;
6494 }
6495
6496 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6497 FunctionalUtils.ignoreRemoteException(callback::accept));
6498
6499 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006500 } finally {
6501 Binder.restoreCallingIdentity(identity);
6502 }
6503 }
6504
6505 /**
Hall Liu27d24262020-09-18 19:04:59 -07006506 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006507 */
6508 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006509 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006510 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006511 long identity = Binder.clearCallingIdentity();
6512 try {
Hall Liu27d24262020-09-18 19:04:59 -07006513 Phone phone = getPhone(subId);
6514 if (phone == null) {
6515 try {
6516 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6517 } catch (RemoteException e) {
6518 // ignore
6519 }
6520 return;
6521 }
SongFerngWang0e767992021-03-31 22:08:45 +08006522 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6523 PersistableBundle c = configManager.getConfigForSubId(subId);
6524 boolean requireUssd = c.getBoolean(
6525 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006526
Shuo Qian4a594052020-01-23 11:59:30 -08006527 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006528 if (requireUssd) {
6529 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6530 getSubscriptionCarrierId(subId));
6531 String newUssdCommand = "";
6532 try {
6533 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006534 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006535 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6536 } catch (NullPointerException e) {
6537 loge("Failed to generate USSD number" + e);
6538 }
6539 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6540 mMainThreadHandler, callback, carrierXmlParser,
6541 CarrierXmlParser.SsEntry.SSAction.QUERY);
6542 final String ussdCommand = newUssdCommand;
6543 Executors.newSingleThreadExecutor().execute(() -> {
6544 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6545 });
6546 } else {
6547 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6548 callback::accept);
6549 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6550 }
Shuo Qian4a594052020-01-23 11:59:30 -08006551 } finally {
6552 Binder.restoreCallingIdentity(identity);
6553 }
6554 }
6555
6556 /**
Hall Liu27d24262020-09-18 19:04:59 -07006557 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006558 */
6559 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006560 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006561 enforceModifyPermission();
6562 long identity = Binder.clearCallingIdentity();
6563 try {
Hall Liu27d24262020-09-18 19:04:59 -07006564 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6565
6566 Phone phone = getPhone(subId);
6567 if (phone == null) {
6568 try {
6569 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6570 } catch (RemoteException e) {
6571 // ignore
6572 }
6573 return;
6574 }
6575
SongFerngWang0e767992021-03-31 22:08:45 +08006576 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6577 PersistableBundle c = configManager.getConfigForSubId(subId);
6578 boolean requireUssd = c.getBoolean(
6579 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006580
SongFerngWang0e767992021-03-31 22:08:45 +08006581 if (DBG) log("getCallWaitingStatus: subId " + subId);
6582 if (requireUssd) {
6583 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6584 getSubscriptionCarrierId(subId));
6585 CarrierXmlParser.SsEntry.SSAction ssAction =
6586 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6587 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6588 String newUssdCommand = "";
6589 try {
6590 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006591 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006592 .makeCommand(ssAction, null);
6593 } catch (NullPointerException e) {
6594 loge("Failed to generate USSD number" + e);
6595 }
6596 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6597 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6598 final String ussdCommand = newUssdCommand;
6599 Executors.newSingleThreadExecutor().execute(() -> {
6600 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6601 });
6602 } else {
6603 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6604 FunctionalUtils.ignoreRemoteException(callback::accept));
6605
6606 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6607 }
Shuo Qian4a594052020-01-23 11:59:30 -08006608 } finally {
6609 Binder.restoreCallingIdentity(identity);
6610 }
6611 }
6612
6613 /**
yinxub1bed742017-04-17 11:45:04 -07006614 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006615 *
yinxub1bed742017-04-17 11:45:04 -07006616 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006617 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6618 * location related information which will be sent if the caller already possess
6619 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006620 * @param request contains the radio access networks with bands/channels to scan
6621 * @param messenger callback messenger for scan results or errors
6622 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006623 * @return the id of the requested scan which can be used to stop the scan.
6624 */
6625 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006626 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6627 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006628 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006629 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6630 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006631 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006632 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6633 if (!renounceFineLocationAccess) {
6634 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006635 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6636 .setCallingPackage(callingPackage)
6637 .setCallingFeatureId(callingFeatureId)
6638 .setCallingPid(Binder.getCallingPid())
6639 .setCallingUid(Binder.getCallingUid())
6640 .setMethod("requestNetworkScan")
6641 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6642 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6643 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6644 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006645 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006646 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006647 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6648 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006649 if (e != null) {
6650 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6651 throw e;
6652 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006653 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006654 return TelephonyScanManager.INVALID_SCAN_ID;
6655 }
6656 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006657 }
Hall Liu912dfd32019-04-25 14:02:26 -07006658 int callingUid = Binder.getCallingUid();
6659 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006660 final long identity = Binder.clearCallingIdentity();
6661 try {
6662 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07006663 renounceFineLocationAccess, request, messenger, binder,
6664 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006665 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006666 } finally {
6667 Binder.restoreCallingIdentity(identity);
6668 }
yinxu504e1392017-04-12 16:03:22 -07006669 }
6670
Hall Liub2ac8ef2019-02-28 15:56:23 -08006671 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006672 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006673 boolean hasCarrierPriv;
6674 final long identity = Binder.clearCallingIdentity();
6675 try {
6676 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6677 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6678 } finally {
6679 Binder.restoreCallingIdentity(identity);
6680 }
Hall Liu558027f2019-05-15 19:14:05 -07006681 boolean hasNetworkScanPermission =
6682 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006683 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07006684
6685 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6686 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6687 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006688 }
6689
6690 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6691 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006692 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6693 return new SecurityException("Specific channels must not be"
6694 + " scanned without location access.");
6695 }
6696 }
6697 }
6698
Hall Liub2ac8ef2019-02-28 15:56:23 -08006699 return null;
6700 }
6701
yinxu504e1392017-04-12 16:03:22 -07006702 /**
6703 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006704 *
6705 * @param subId id of the subscription
6706 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006707 */
6708 @Override
6709 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006710 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6711 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006712
Hall Liu912dfd32019-04-25 14:02:26 -07006713 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006714 final long identity = Binder.clearCallingIdentity();
6715 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006716 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006717 } finally {
6718 Binder.restoreCallingIdentity(identity);
6719 }
yinxu504e1392017-04-12 16:03:22 -07006720 }
6721
6722 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006723 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006724 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006725 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006726 */
6727 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006728 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006729 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006730 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006731 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006732
6733 final long identity = Binder.clearCallingIdentity();
6734 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006735 if (DBG) log("getAllowedNetworkTypesBitmask");
6736 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6737 int networkTypesBitmask = (result != null ? result[0] : -1);
6738 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6739 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006740 } finally {
6741 Binder.restoreCallingIdentity(identity);
6742 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006743 }
6744
6745 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006746 * Get the allowed network types for certain reason.
6747 *
6748 * @param subId the id of the subscription.
6749 * @param reason the reason the allowed network type change is taking place
6750 * @return the allowed network types.
6751 */
6752 @Override
6753 public long getAllowedNetworkTypesForReason(int subId,
6754 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006755 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006756 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006757 final long identity = Binder.clearCallingIdentity();
6758 try {
Jack Yu7247ac82023-03-02 23:52:10 -08006759 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006760 } finally {
6761 Binder.restoreCallingIdentity(identity);
6762 }
6763 }
6764
6765 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006766 * Enable/Disable E-UTRA-NR Dual Connectivity
6767 * @param subId subscription id of the sim card
6768 * @param nrDualConnectivityState expected NR dual connectivity state
6769 * This can be passed following states
6770 * <ol>
6771 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6772 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6773 * <li>Disable NR dual connectivity and force secondary cell to be released
6774 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6775 * </ol>
6776 * @return operation result.
6777 */
6778 @Override
6779 public int setNrDualConnectivityState(int subId,
6780 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6781 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6782 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006783 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006784 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6785 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6786 }
6787
Sooraj Sasindran37444802020-08-11 10:40:43 -07006788 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6789 final long identity = Binder.clearCallingIdentity();
6790 try {
6791 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6792 nrDualConnectivityState, subId,
6793 workSource);
6794 if (DBG) log("enableNRDualConnectivity result: " + result);
6795 return result;
6796 } finally {
6797 Binder.restoreCallingIdentity(identity);
6798 }
6799 }
6800
6801 /**
6802 * Is E-UTRA-NR Dual Connectivity enabled
6803 * @return true if dual connectivity is enabled else false
6804 */
6805 @Override
6806 public boolean isNrDualConnectivityEnabled(int subId) {
6807 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006808 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006809 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006810 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006811 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6812 return false;
6813 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006814 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6815 final long identity = Binder.clearCallingIdentity();
6816 try {
6817 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6818 null, subId, workSource);
6819 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6820 return isEnabled;
6821 } finally {
6822 Binder.restoreCallingIdentity(identity);
6823 }
6824 }
6825
6826 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006827 * Set the allowed network types of the device and
6828 * provide the reason triggering the allowed network change.
6829 *
6830 * @param subId the id of the subscription.
6831 * @param reason the reason the allowed network type change is taking place
6832 * @param allowedNetworkTypes the allowed network types.
6833 * @return true on success; false on any failure.
6834 */
6835 @Override
6836 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006837 @TelephonyManager.AllowedNetworkTypesReason int reason,
6838 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6840 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006841 // If the caller only has carrier privileges, then they should not be able to override
6842 // any network types which were set for security reasons.
6843 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6844 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006845 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006846 throw new SecurityException(
6847 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006848 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006849 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006850 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006851 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08006852 return false;
6853 }
6854 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6855 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006856 return false;
6857 }
6858
Jack Yu5b494332023-01-23 18:18:04 +00006859 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
6860 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006861
Jack Yue37dd262022-12-16 11:53:37 -08006862 Phone phone = getPhone(subId);
6863 if (phone == null) {
6864 return false;
6865 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006866
Jack Yue37dd262022-12-16 11:53:37 -08006867 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006868 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006869 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006870 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006871
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006872 final long identity = Binder.clearCallingIdentity();
6873 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006874 Boolean success = (Boolean) sendRequest(
6875 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6876 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6877
6878 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6879 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006880 } finally {
6881 Binder.restoreCallingIdentity(identity);
6882 }
6883 }
6884
6885 /**
Miaoa84611c2019-03-15 09:21:10 +08006886 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006887 *
Miaoa84611c2019-03-15 09:21:10 +08006888 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006889 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006890 * @hide
6891 */
6892 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006893 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006894 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006895 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006896 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006897 try {
Miaoa84611c2019-03-15 09:21:10 +08006898 if (phone != null) {
6899 return phone.hasMatchedTetherApnSetting();
6900 } else {
6901 return false;
6902 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006903 } finally {
6904 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006905 }
Junda Liu475951f2014-11-07 16:45:03 -08006906 }
6907
6908 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006909 * Get the user enabled state of Mobile Data.
6910 *
6911 * TODO: remove and use isUserDataEnabled.
6912 * This can't be removed now because some vendor codes
6913 * calls through ITelephony directly while they should
6914 * use TelephonyManager.
6915 *
6916 * @return true on enabled
6917 */
6918 @Override
6919 public boolean getDataEnabled(int subId) {
6920 return isUserDataEnabled(subId);
6921 }
6922
6923 /**
6924 * Get whether mobile data is enabled per user setting.
6925 *
6926 * There are other factors deciding whether mobile data is actually enabled, but they are
6927 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006928 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006929 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6930 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006931 *
6932 * @return {@code true} if data is enabled else {@code false}
6933 */
6934 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006935 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006936 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006937 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006938 try {
6939 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6940 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006941 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006942 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6943 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006944 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006945 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006946 mApp, subId, functionName);
6947
Robert Greenwalt646120a2014-05-23 11:54:03 -07006948 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006949
6950 final long identity = Binder.clearCallingIdentity();
6951 try {
Jack Yu285100e2022-12-02 22:48:35 -08006952 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006953 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6954 Phone phone = PhoneFactory.getPhone(phoneId);
6955 if (phone != null) {
6956 boolean retVal = phone.isUserDataEnabled();
6957 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6958 return retVal;
6959 } else {
6960 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6961 return false;
6962 }
6963 } finally {
6964 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006965 }
6966 }
6967
6968 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006969 * Checks if the device is capable of mobile data by considering whether whether the
6970 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6971 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006972 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006973 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006974 */
6975 @Override
6976 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006977 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006978 try {
6979 try {
6980 mApp.enforceCallingOrSelfPermission(
6981 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006982 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006983 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006984 try {
6985 mApp.enforceCallingOrSelfPermission(
6986 android.Manifest.permission.READ_PHONE_STATE,
6987 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006988 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006989 mApp.enforceCallingOrSelfPermission(
6990 permission.READ_BASIC_PHONE_STATE, functionName);
6991 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006992 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006993 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006994 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006995 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006996
6997 final long identity = Binder.clearCallingIdentity();
6998 try {
Jack Yu285100e2022-12-02 22:48:35 -08006999 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007000 Phone phone = PhoneFactory.getPhone(phoneId);
7001 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007002 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007003 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007004 return retVal;
7005 } else {
7006 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7007 return false;
7008 }
7009 } finally {
7010 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007011 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007012 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007013
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007014 /**
7015 * Check if data is enabled for a specific reason
7016 * @param subId Subscription index
7017 * @param reason the reason the data enable change is taking place
7018 * @return {@code true} if the overall data is enabled; {@code false} if not.
7019 */
7020 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007021 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007022 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007023 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007024 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007025 try {
7026 mApp.enforceCallingOrSelfPermission(
7027 android.Manifest.permission.ACCESS_NETWORK_STATE,
7028 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007029 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007030 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7031 functionName);
7032 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007033 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007034 try {
7035 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007036 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007037 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007039 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007040 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007041 }
7042
7043
7044 final long identity = Binder.clearCallingIdentity();
7045 try {
Jack Yu285100e2022-12-02 22:48:35 -08007046 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007047 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007048 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007049 + " reason=" + reason);
7050 }
7051 Phone phone = PhoneFactory.getPhone(phoneId);
7052 if (phone != null) {
7053 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007054 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007055 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007056 return retVal;
7057 } else {
7058 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007059 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007060 + subId + " retVal=false");
7061 }
7062 return false;
7063 }
7064 } finally {
7065 Binder.restoreCallingIdentity(identity);
7066 }
7067 }
7068
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007069 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007070 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007071 // No permission needed; this only lets the caller inspect their own status.
7072 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007073 }
Junda Liu29340342014-07-10 15:23:27 -07007074
7075 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007076 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007077 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007078 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7079 }
7080
7081 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7082 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007083 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007084 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007085 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7086 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007087 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7088 if (cpt == null) {
7089 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007090 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7091 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007092 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007093 }
7094
7095 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007096 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007097 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007098 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007099 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007100 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007101 Phone phone = getPhone(subId);
7102 if (phone == null) {
7103 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7104 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7105 }
7106 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7107 if (cpt == null) {
7108 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007109 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7110 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007111 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007112 }
7113
7114 @Override
7115 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007116 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007117 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7118 }
7119
7120 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007121 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007122 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007123 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007124 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007125 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7126 Phone phone = PhoneFactory.getPhone(phoneId);
7127 if (phone == null) {
7128 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007129 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007130 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7131 if (cpt == null) {
7132 continue;
7133 }
7134 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007135 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7136 break;
7137 }
7138 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007139 return result;
Junda Liu29340342014-07-10 15:23:27 -07007140 }
Derek Tan89e89d42014-07-08 17:00:10 -07007141
7142 @Override
Junda Liue64de782015-04-16 17:19:16 -07007143 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007144 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007145 Phone phone = PhoneFactory.getPhone(phoneId);
7146 if (phone == null) {
7147 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007148 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007149 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7150 if (cpt == null) {
7151 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007152 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007153 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007154 }
7155
Amith Yamasani6e118872016-02-19 12:53:51 -08007156 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007157 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007158 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007159 Phone phone = PhoneFactory.getPhone(phoneId);
7160 if (phone == null) {
7161 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007162 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007163 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7164 if (cpt == null) {
7165 return Collections.emptyList();
7166 }
7167 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007168 }
7169
chen xuf7e9fe82019-05-09 19:31:02 -07007170 @Override
7171 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007172 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007173 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007174 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007175 try {
7176 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7177 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7178 }
7179 } finally {
7180 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007181 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007182 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007183 }
7184
Rambo Wang6812ffb2022-03-15 16:54:17 -07007185 @Override
7186 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7187 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7188
7189 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7190 if (phone == null) {
7191 return null;
7192 }
7193 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7194 if (cpt == null) {
7195 return null;
7196 }
7197 return cpt.getCarrierServicePackageName();
7198 }
7199
Wink Savilleb564aae2014-10-23 10:18:09 -07007200 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007201 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007202 UiccPort port = phone == null ? null : phone.getUiccPort();
7203 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007204 return null;
7205 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007206 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007207 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007208 return null;
7209 }
7210 return iccId;
7211 }
7212
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007213 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007214 public void setCallComposerStatus(int subId, int status) {
7215 enforceModifyPermission();
7216
7217 final long identity = Binder.clearCallingIdentity();
7218 try {
7219 Phone phone = getPhone(subId);
7220 if (phone != null) {
7221 Phone defaultPhone = phone.getImsPhone();
7222 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7223 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7224 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007225 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7226 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007227 }
7228 }
Shuo Qian284ae752020-12-22 19:10:14 -08007229 } catch (ImsException e) {
7230 throw new ServiceSpecificException(e.getCode());
7231 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007232 Binder.restoreCallingIdentity(identity);
7233 }
7234 }
7235
7236 @Override
7237 public int getCallComposerStatus(int subId) {
7238 enforceReadPrivilegedPermission("getCallComposerStatus");
7239
7240 final long identity = Binder.clearCallingIdentity();
7241 try {
7242 Phone phone = getPhone(subId);
7243 if (phone != null) {
7244 Phone defaultPhone = phone.getImsPhone();
7245 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7246 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7247 return imsPhone.getCallComposerStatus();
7248 }
7249 }
7250 } finally {
7251 Binder.restoreCallingIdentity(identity);
7252 }
7253 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7254 }
7255
7256 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007257 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7258 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007259 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007260 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007261
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007262 final long identity = Binder.clearCallingIdentity();
7263 try {
7264 final String iccId = getIccId(subId);
7265 final Phone phone = getPhone(subId);
7266 if (phone == null) {
7267 return false;
7268 }
7269 final String subscriberId = phone.getSubscriberId();
7270
7271 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007272 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007273 + subscriberId + " to " + number);
7274 }
7275
7276 if (TextUtils.isEmpty(iccId)) {
7277 return false;
7278 }
7279
7280 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7281
7282 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7283 if (alphaTag == null) {
7284 editor.remove(alphaTagPrefKey);
7285 } else {
7286 editor.putString(alphaTagPrefKey, alphaTag);
7287 }
7288
7289 // Record both the line number and IMSI for this ICCID, since we need to
7290 // track all merged IMSIs based on line number
7291 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7292 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7293 if (number == null) {
7294 editor.remove(numberPrefKey);
7295 editor.remove(subscriberPrefKey);
7296 } else {
7297 editor.putString(numberPrefKey, number);
7298 editor.putString(subscriberPrefKey, subscriberId);
7299 }
7300
7301 editor.commit();
7302 return true;
7303 } finally {
7304 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007305 }
Derek Tan7226c842014-07-02 17:42:23 -07007306 }
7307
7308 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007309 public String getLine1NumberForDisplay(int subId, String callingPackage,
7310 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007311 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007312 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007313 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007314 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007315 return null;
7316 }
Derek Tan97ebb422014-09-05 16:55:38 -07007317
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007318 final long identity = Binder.clearCallingIdentity();
7319 try {
7320 String iccId = getIccId(subId);
7321 if (iccId != null) {
7322 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7323 if (DBG_MERGE) {
7324 log("getLine1NumberForDisplay returning "
7325 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7326 }
7327 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007328 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007329 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7330 return null;
7331 } finally {
7332 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007333 }
Derek Tan7226c842014-07-02 17:42:23 -07007334 }
7335
7336 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007337 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7338 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007339 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007340 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007341 return null;
7342 }
Derek Tan97ebb422014-09-05 16:55:38 -07007343
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007344 final long identity = Binder.clearCallingIdentity();
7345 try {
7346 String iccId = getIccId(subId);
7347 if (iccId != null) {
7348 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7349 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7350 }
7351 return null;
7352 } finally {
7353 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007354 }
Derek Tan7226c842014-07-02 17:42:23 -07007355 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007356
7357 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007358 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7359 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007360 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7361 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007362 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007363 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007364 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007365 return null;
7366 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007367
Jordan Liub49b04b2019-05-06 14:45:15 -07007368 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7369 // the process, where TelephonyManager was instantiated.
7370 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007371 final long identity = Binder.clearCallingIdentity();
7372 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007373 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007374 final TelephonyManager tele = TelephonyManager.from(context);
7375 final SubscriptionManager sub = SubscriptionManager.from(context);
7376
7377 // Figure out what subscribers are currently active
7378 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007379
Jordan Liub49b04b2019-05-06 14:45:15 -07007380 // Only consider subs which match the current subId
7381 // This logic can be simplified. See b/131189269 for progress.
7382 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007383 activeSubscriberIds.add(tele.getSubscriberId(subId));
7384 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007385
7386 // First pass, find a number override for an active subscriber
7387 String mergeNumber = null;
7388 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7389 for (String key : prefs.keySet()) {
7390 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7391 final String subscriberId = (String) prefs.get(key);
7392 if (activeSubscriberIds.contains(subscriberId)) {
7393 final String iccId = key.substring(
7394 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7395 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7396 mergeNumber = (String) prefs.get(numberKey);
7397 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007398 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007399 + " for active subscriber " + subscriberId);
7400 }
7401 if (!TextUtils.isEmpty(mergeNumber)) {
7402 break;
7403 }
7404 }
7405 }
7406 }
7407
7408 // Shortcut when no active merged subscribers
7409 if (TextUtils.isEmpty(mergeNumber)) {
7410 return null;
7411 }
7412
7413 // Second pass, find all subscribers under that line override
7414 final ArraySet<String> result = new ArraySet<>();
7415 for (String key : prefs.keySet()) {
7416 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7417 final String number = (String) prefs.get(key);
7418 if (mergeNumber.equals(number)) {
7419 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7420 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7421 final String subscriberId = (String) prefs.get(subscriberKey);
7422 if (!TextUtils.isEmpty(subscriberId)) {
7423 result.add(subscriberId);
7424 }
7425 }
7426 }
7427 }
7428
7429 final String[] resultArray = result.toArray(new String[result.size()]);
7430 Arrays.sort(resultArray);
7431 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007432 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007433 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7434 }
7435 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007436 } finally {
7437 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007438 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007439 }
7440
7441 @Override
zoey chen38003472019-12-13 17:16:31 +08007442 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7443 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007444
7445 final long identity = Binder.clearCallingIdentity();
7446 try {
7447 final TelephonyManager telephonyManager = mApp.getSystemService(
7448 TelephonyManager.class);
7449 String subscriberId = telephonyManager.getSubscriberId(subId);
7450 if (subscriberId == null) {
7451 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007452 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007453 + subId);
7454 }
7455 return null;
7456 }
7457
Jack Yu3beaf9d2023-04-14 09:17:27 -07007458 final SubscriptionInfo info = getSubscriptionManagerService()
7459 .getSubscriptionInfo(subId);
7460 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007461 // If it doesn't belong to any group, return just subscriberId of itself.
7462 if (groupUuid == null) {
7463 return new String[]{subscriberId};
7464 }
7465
7466 // Get all subscriberIds from the group.
7467 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07007468 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
7469 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7470 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007471 for (SubscriptionInfo subInfo : groupInfos) {
7472 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7473 if (subscriberId != null) {
7474 mergedSubscriberIds.add(subscriberId);
7475 }
7476 }
7477
7478 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7479 } finally {
7480 Binder.restoreCallingIdentity(identity);
7481
7482 }
7483 }
7484
7485 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007486 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007487 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007488 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007489
7490 final long identity = Binder.clearCallingIdentity();
7491 try {
7492 final Phone phone = getPhone(subId);
7493 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7494 } finally {
7495 Binder.restoreCallingIdentity(identity);
7496 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007497 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007498
7499 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007500 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007501 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7502 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007503 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7504 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007505
7506 final long identity = Binder.clearCallingIdentity();
7507 try {
7508 final Phone phone = getPhone(subId);
7509 if (phone == null) {
7510 return false;
7511 }
7512 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7513 cdmaNonRoamingList);
7514 } finally {
7515 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007516 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007517 }
7518
7519 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007520 @Deprecated
7521 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7522 enforceModifyPermission();
7523
7524 int returnValue = 0;
7525 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007526 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007527 if(result.exception == null) {
7528 if (result.result != null) {
7529 byte[] responseData = (byte[])(result.result);
7530 if(responseData.length > oemResp.length) {
7531 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7532 responseData.length + "bytes. Buffer Size is " +
7533 oemResp.length + "bytes.");
7534 }
7535 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7536 returnValue = responseData.length;
7537 }
7538 } else {
7539 CommandException ex = (CommandException) result.exception;
7540 returnValue = ex.getCommandError().ordinal();
7541 if(returnValue > 0) returnValue *= -1;
7542 }
7543 } catch (RuntimeException e) {
7544 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7545 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7546 if(returnValue > 0) returnValue *= -1;
7547 }
7548
7549 return returnValue;
7550 }
7551
7552 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007553 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007554 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007555 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007556 if (phone == null) {
7557 return raf;
7558 }
7559
Shuo Qiandee53402020-05-29 14:08:15 -07007560 try {
7561 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007562 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007563 mApp, phone.getSubId(), "getRadioAccessFamily");
7564 } catch (SecurityException e) {
7565 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7566 throw e;
7567 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007568
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007569 final long identity = Binder.clearCallingIdentity();
7570 try {
chen xub97461a2018-10-26 14:17:57 -07007571 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007572 } finally {
7573 Binder.restoreCallingIdentity(identity);
7574 }
chen xub97461a2018-10-26 14:17:57 -07007575 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007576 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007577
7578 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007579 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007580 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007581 try {
7582 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7583 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007584 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007585 }
7586 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007587 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007588 }
7589 RoleManager rm = mApp.getSystemService(RoleManager.class);
7590 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7591 if (!dialerRoleHolders.contains(callingPackage)) {
7592 throw new SecurityException("App must be the dialer role holder to"
7593 + " upload a call composer pic");
7594 }
7595
7596 Executors.newSingleThreadExecutor().execute(() -> {
7597 ByteArrayOutputStream output = new ByteArrayOutputStream(
7598 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7599 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7600 boolean readUntilEnd = false;
7601 int totalBytesRead = 0;
7602 byte[] buffer = new byte[16 * 1024];
7603 while (true) {
7604 int numRead;
7605 try {
7606 numRead = input.read(buffer);
7607 } catch (IOException e) {
7608 try {
7609 fd.checkError();
7610 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7611 null);
7612 } catch (IOException e1) {
7613 // This means that the other side closed explicitly with an error. If this
7614 // happens, log and ignore.
7615 loge("Remote end of call composer picture pipe closed: " + e1);
7616 }
7617 break;
7618 }
7619 if (numRead == -1) {
7620 readUntilEnd = true;
7621 break;
7622 }
7623 totalBytesRead += numRead;
7624 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7625 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7626 try {
7627 input.close();
7628 } catch (IOException e) {
7629 // ignore
7630 }
7631 break;
7632 }
7633 output.write(buffer, 0, numRead);
7634 }
7635 // Generally, the remote end will close the file descriptors. The only case where we
7636 // close is above, where the picture size is too big.
7637
7638 try {
7639 fd.checkError();
7640 } catch (IOException e) {
7641 loge("Remote end for call composer closed with an error: " + e);
7642 return;
7643 }
7644
Hall Liuaa4211e2021-01-20 15:43:39 -08007645 if (!readUntilEnd) {
7646 loge("Did not finish reading entire image; aborting");
7647 return;
7648 }
Hall Liu82694d52020-12-11 18:22:04 -08007649
Hall Liuaa4211e2021-01-20 15:43:39 -08007650 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7651 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7652 new CallComposerPictureTransfer.Factory() {},
7653 imageData,
7654 (result) -> {
7655 if (result.first != null) {
7656 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7657 Bundle outputResult = new Bundle();
7658 outputResult.putParcelable(
7659 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7660 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7661 outputResult);
7662 } else {
7663 callback.send(result.second, null);
7664 }
7665 }
7666 );
Hall Liu82694d52020-12-11 18:22:04 -08007667 });
7668 }
7669
7670 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007671 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007672 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007673 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007674
7675 final long identity = Binder.clearCallingIdentity();
7676 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007677 ImsManager.getInstance(defaultPhone.getContext(),
7678 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007679 } finally {
7680 Binder.restoreCallingIdentity(identity);
7681 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007682 }
7683
7684 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007685 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007686 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007687 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7688 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007689 return false;
7690 }
Svet Ganovb320e182015-04-16 12:30:10 -07007691
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007692 final long identity = Binder.clearCallingIdentity();
7693 try {
7694 // Check the user preference and the system-level IMS setting. Even if the user has
7695 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7696 // In the long run, we may instead need to check if there exists a connection service
7697 // which can support video calling.
7698 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007699 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007700 return imsManager.isVtEnabledByPlatform()
7701 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7702 && imsManager.isVtEnabledByUser();
7703 } finally {
7704 Binder.restoreCallingIdentity(identity);
7705 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007706 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007707
Andrew Leea1239f22015-03-02 17:44:07 -08007708 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007709 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7710 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007711 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007712 mApp, subId, callingPackage, callingFeatureId,
7713 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007714 return false;
7715 }
7716
7717 final long identity = Binder.clearCallingIdentity();
7718 try {
7719 CarrierConfigManager configManager =
7720 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007721 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007722 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7723 } finally {
7724 Binder.restoreCallingIdentity(identity);
7725 }
Andrew Leea1239f22015-03-02 17:44:07 -08007726 }
7727
7728 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007729 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007730 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007731 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007732 return false;
7733 }
7734
7735 final long identity = Binder.clearCallingIdentity();
7736 try {
7737 CarrierConfigManager configManager =
7738 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007739 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007740 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7741 } finally {
7742 Binder.restoreCallingIdentity(identity);
7743 }
Andrew Leea1239f22015-03-02 17:44:07 -08007744 }
7745
Andrew Lee9431b832015-03-09 18:46:45 -07007746 @Override
7747 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007748 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007749 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007750 }
7751
7752 @Override
7753 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007754 final long identity = Binder.clearCallingIdentity();
7755 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007756 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007757 } finally {
7758 Binder.restoreCallingIdentity(identity);
7759 }
Andrew Lee9431b832015-03-09 18:46:45 -07007760 }
7761
Hall Liuf6668912018-10-31 17:05:23 -07007762 /**
7763 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7764 * support for the feature and device firmware support.
7765 *
7766 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7767 */
7768 @Override
7769 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007770 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007771 final Phone phone = getPhone(subscriptionId);
7772 if (phone == null) {
7773 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7774 return false;
7775 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007776 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007777 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007778 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7779 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007780 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007781 return isCarrierSupported && isDeviceSupported;
7782 } finally {
7783 Binder.restoreCallingIdentity(identity);
7784 }
Hall Liu98187582018-01-22 19:15:32 -08007785 }
7786
Hall Liuf6668912018-10-31 17:05:23 -07007787 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007788 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7789 * RTT setting, will return true if the device and carrier both support RTT.
7790 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007791 */
7792 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007793 final long identity = Binder.clearCallingIdentity();
7794 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007795 boolean isRttSupported = isRttSupported(subscriptionId);
7796 boolean isUserRttSettingOn = Settings.Secure.getInt(
7797 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7798 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7799 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7800 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007801 } finally {
7802 Binder.restoreCallingIdentity(identity);
7803 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007804 }
7805
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007806 @Deprecated
7807 @Override
7808 public String getDeviceId(String callingPackage) {
7809 return getDeviceIdWithFeature(callingPackage, null);
7810 }
7811
Sanket Padawe7310cc72015-01-14 09:53:20 -08007812 /**
7813 * Returns the unique device ID of phone, for example, the IMEI for
7814 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7815 *
7816 * <p>Requires Permission:
7817 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7818 */
7819 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007820 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007821 try {
7822 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7823 } catch (SecurityException se) {
7824 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7825 throw new SecurityException("Package " + callingPackage + " does not belong to "
7826 + Binder.getCallingUid());
7827 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007828 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007829 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007830 return null;
7831 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007832 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007833 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007834 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007835 return null;
7836 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007837
7838 final long identity = Binder.clearCallingIdentity();
7839 try {
7840 return phone.getDeviceId();
7841 } finally {
7842 Binder.restoreCallingIdentity(identity);
7843 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007844 }
7845
Ping Sunc67b7c22016-03-02 19:16:45 +08007846 /**
7847 * {@hide}
7848 * Returns the IMS Registration Status on a particular subid
7849 *
7850 * @param subId
7851 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007852 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007853 Phone phone = getPhone(subId);
7854 if (phone != null) {
7855 return phone.isImsRegistered();
7856 } else {
7857 return false;
7858 }
7859 }
7860
Santos Cordon7a1885b2015-02-03 11:15:19 -08007861 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007862 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007863 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007864 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007865 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007866 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7867 }
7868 final long identity = Binder.clearCallingIdentity();
7869 try {
7870 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7871 } finally {
7872 Binder.restoreCallingIdentity(identity);
7873 }
7874 }
7875
7876 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007877 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007878 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007879 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007880 mApp,
7881 subscriptionId,
7882 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
7883 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007884 final long identity = Binder.clearCallingIdentity();
7885 try {
7886 Phone phone = getPhone(subscriptionId);
7887 if (phone == null) {
7888 return null;
7889 }
7890 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7891 } finally {
7892 Binder.restoreCallingIdentity(identity);
7893 }
7894 }
7895
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007896 /**
7897 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007898 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007899 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007900 final long identity = Binder.clearCallingIdentity();
7901 try {
7902 Phone phone = getPhone(subId);
7903 if (phone != null) {
7904 return phone.isWifiCallingEnabled();
7905 } else {
7906 return false;
7907 }
7908 } finally {
7909 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007910 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007911 }
7912
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007913 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007914 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007915 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007916 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007917 final long identity = Binder.clearCallingIdentity();
7918 try {
7919 Phone phone = getPhone(subId);
7920 if (phone != null) {
7921 return phone.isVideoEnabled();
7922 } else {
7923 return false;
7924 }
7925 } finally {
7926 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007927 }
7928 }
7929
7930 /**
7931 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7932 * defined in {@link ImsRegistrationImplBase}.
7933 */
7934 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007935 final long identity = Binder.clearCallingIdentity();
7936 try {
7937 Phone phone = getPhone(subId);
7938 if (phone != null) {
7939 return phone.getImsRegistrationTech();
7940 } else {
7941 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7942 }
7943 } finally {
7944 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007945 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007946 }
7947
Stuart Scott8eef64f2015-04-08 15:13:54 -07007948 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007949 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007950 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007951 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7952 return;
7953 }
Kai Shif70f46f2021-03-03 13:59:46 -08007954 Phone defaultPhone = getDefaultPhone();
7955 if (defaultPhone != null) {
7956 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7957 mApp, getDefaultPhone().getSubId(), "factoryReset");
7958 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007959 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007960
Svet Ganovcc087f82015-05-12 20:35:54 -07007961 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007962 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7963 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007964 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007965 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007966 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007967 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007968 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007969 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007970 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007971 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007972 // There has been issues when Sms raw table somehow stores orphan
7973 // fragments. They lead to garbled message when new fragments come
7974 // in and combined with those stale ones. In case this happens again,
7975 // user can reset all network settings which will clean up this table.
7976 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007977 // Clean up IMS settings as well here.
7978 int slotId = getSlotIndex(subId);
7979 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7980 ImsManager.getInstance(mApp, slotId).factoryReset();
7981 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007982
Kai Shif70f46f2021-03-03 13:59:46 -08007983 if (defaultPhone == null) {
7984 return;
7985 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007986 // Erase modem config if erase modem on network setting is enabled.
7987 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7988 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7989 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007990 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007991 }
Kai Shif70f46f2021-03-03 13:59:46 -08007992
7993 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007994 } finally {
7995 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007996 }
7997 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007998
SongFerngWangfd89b102021-05-27 22:44:54 +08007999 @VisibleForTesting
8000 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8001 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8002 return;
8003 }
8004 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8005 RILConstants.PREFERRED_NETWORK_MODE);
8006 SubscriptionManager.setSubscriptionProperty(subId,
8007 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8008 "user=" + defaultNetworkType);
8009 phone.loadAllowedNetworksFromSubscriptionDatabase();
8010 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8011 defaultNetworkType, null);
8012 }
8013
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008014 private void cleanUpSmsRawTable(Context context) {
8015 ContentResolver resolver = context.getContentResolver();
8016 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8017 resolver.delete(uri, null, null);
8018 }
8019
Narayan Kamath1c496c22015-04-16 14:40:19 +01008020 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008021 public String getSimLocaleForSubscriber(int subId) {
8022 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
8023 final Phone phone = getPhone(subId);
8024 if (phone == null) {
8025 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008026 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008027 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008028 final long identity = Binder.clearCallingIdentity();
8029 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008030 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8031 phone.getContext().getOpPackageName(),
8032 phone.getContext().getAttributionTag());
8033 if (info == null) {
8034 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8035 return null;
chen xu6291c472019-02-04 12:55:53 -08008036 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008037 // Try and fetch the locale from the carrier properties or from the SIM language
8038 // preferences (EF-PL and EF-LI)...
8039 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008040 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008041 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8042 if (localeFromDefaultSim != null) {
8043 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8044 if (DBG) log("Using locale from subId: " + subId + " locale: "
8045 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008046 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008047 } else {
8048 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008049 }
8050 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008051
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008052 // The SIM language preferences only store a language (e.g. fr = French), not an
8053 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8054 // the SIM and carrier preferences does not include a country we add the country
8055 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008056 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008057 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008058 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008059 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008060 }
8061
8062 if (DBG) log("No locale found - returning null");
8063 return null;
8064 } finally {
8065 Binder.restoreCallingIdentity(identity);
8066 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008067 }
8068
tom hsu0b59d292022-09-29 23:49:21 +08008069 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008070 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008071 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008072 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008073 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008074 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8075 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008076 Locale.forLanguageTag(localeTag).getCountry())) {
8077 return localeTag;
8078 }
8079 }
8080 return inputLocale.toLanguageTag();
8081 }
8082
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008083 /**
8084 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8085 */
8086 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008087 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
8088 mApp.getOpPackageName(), mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008089 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008090
Gary Jian3aa9a762022-01-24 16:41:19 +08008091 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8092 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008093
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008094 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008095 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8096 * representing the state of the modem.
8097 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008098 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8099 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008100 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008101 */
8102 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008103 public void requestModemActivityInfo(ResultReceiver result) {
8104 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008105 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008106
8107 final long identity = Binder.clearCallingIdentity();
8108 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008109 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008110 } finally {
8111 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008112 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008113 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008114
Gary Jian76280a42022-12-07 16:18:33 +08008115 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008116 // less than total activity duration.
8117 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8118 if (info == null) {
8119 return false;
8120 }
8121 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008122 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008123 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8124
Hall Liu49656c02020-10-09 19:00:11 -07008125 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8126
Siddharth Rayb8114062018-06-17 15:02:38 -07008127 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008128 && (info.getSleepTimeMillis() <= activityDurationMs)
8129 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008130 }
8131
Gary Jian3aa9a762022-01-24 16:41:19 +08008132 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8133 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8134 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8135 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8136
8137 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8138 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8139 }
8140
8141 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8142 mLastModemActivityInfo.setReceiveTimeMillis(
8143 rat,
8144 freq,
8145 info.getReceiveTimeMillis(rat, freq)
8146 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8147 }
8148
8149 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8150 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8151 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8152 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8153
8154 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8155 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8156 }
8157 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8158 mLastModemActivityInfo.setReceiveTimeMillis(
8159 rat,
8160 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8161 }
8162
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008163 /**
8164 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8165 * @param info recent ModemActivityInfo
8166 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008167 private void mergeModemActivityInfo(ModemActivityInfo info) {
8168 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008169 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008170 boolean matched;
8171 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8172 matched = false;
8173 int rat = info.getSpecificInfoRat(i);
8174 int freq = info.getSpecificInfoFrequencyRange(i);
8175 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8176 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8177 //if it already exists
8178 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8179 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8180 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8181 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8182 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8183 updateLastModemActivityInfo(info, rat, freq);
8184 matched = true;
8185 }
8186 } else {
8187 updateLastModemActivityInfo(info, rat);
8188 matched = true;
8189 }
8190 }
8191 }
8192
8193 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008194 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008195 new ActivityStatsTechSpecificInfo(
8196 rat,
8197 freq,
8198 info.getTransmitTimeMillis(rat, freq),
8199 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008200 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008201 }
8202 }
8203 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8204 mLastModemActivitySpecificInfo =
8205 new ActivityStatsTechSpecificInfo[merged.size()];
8206 merged.toArray(mLastModemActivitySpecificInfo);
8207
8208 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8209 mLastModemActivityInfo.setSleepTimeMillis(
8210 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008211 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008212 mLastModemActivityInfo.setIdleTimeMillis(
8213 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008214 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008215
8216 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008217 new ModemActivityInfo(
8218 mLastModemActivityInfo.getTimestampMillis(),
8219 mLastModemActivityInfo.getSleepTimeMillis(),
8220 mLastModemActivityInfo.getIdleTimeMillis(),
8221 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008222 }
8223
8224 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8225 ActivityStatsTechSpecificInfo[] info) {
8226 int infoSize = info.length;
8227 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8228 for (int i = 0; i < infoSize; i++) {
8229 ret[i] = new ActivityStatsTechSpecificInfo(
8230 info[i].getRat(), info[i].getFrequencyRange(),
8231 info[i].getTransmitTimeMillis(),
8232 (int) info[i].getReceiveTimeMillis());
8233 }
8234 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008235 }
8236
Jack Yu85bd38a2015-11-09 11:34:32 -08008237 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008238 * Returns the service state information on specified subscription.
8239 */
8240 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008241 public ServiceState getServiceStateForSubscriber(int subId,
8242 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8243 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008244 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008245 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008246 return null;
8247 }
8248
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008249 boolean hasFinePermission = false;
8250 boolean hasCoarsePermission = false;
8251 if (!renounceFineLocationAccess) {
8252 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8253 LocationAccessPolicy.checkLocationPermission(mApp,
8254 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8255 .setCallingPackage(callingPackage)
8256 .setCallingFeatureId(callingFeatureId)
8257 .setCallingPid(Binder.getCallingPid())
8258 .setCallingUid(Binder.getCallingUid())
8259 .setMethod("getServiceStateForSubscriber")
8260 .setLogAsInfo(true)
8261 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8262 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8263 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8264 .build());
8265 hasFinePermission =
8266 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8267 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008268
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008269 if (!renounceCoarseLocationAccess) {
8270 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8271 LocationAccessPolicy.checkLocationPermission(mApp,
8272 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8273 .setCallingPackage(callingPackage)
8274 .setCallingFeatureId(callingFeatureId)
8275 .setCallingPid(Binder.getCallingPid())
8276 .setCallingUid(Binder.getCallingUid())
8277 .setMethod("getServiceStateForSubscriber")
8278 .setLogAsInfo(true)
8279 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8280 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8281 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8282 .build());
8283 hasCoarsePermission =
8284 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8285 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008286
Jack Yu479f40e2020-10-27 21:29:25 -07008287 final Phone phone = getPhone(subId);
8288 if (phone == null) {
8289 return null;
8290 }
8291
Jordan Liu0f2bc442020-11-18 16:47:37 -08008292 final long identity = Binder.clearCallingIdentity();
8293
Jack Yu479f40e2020-10-27 21:29:25 -07008294 boolean isCallingPackageDataService = phone.getDataServicePackages()
8295 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008296 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008297 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008298 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8299 .getSubscriptionInfoInternal(subId);
8300 if (subInfo == null || !subInfo.isActive()) {
8301 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8302 + "subId=" + subId);
8303 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008304 }
8305
Hall Liuf19c44f2018-11-27 14:38:17 -08008306 ServiceState ss = phone.getServiceState();
8307
8308 // Scrub out the location info in ServiceState depending on what level of access
8309 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008310 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008311 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8312 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008313 } finally {
8314 Binder.restoreCallingIdentity(identity);
8315 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008316 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008317
8318 /**
8319 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8320 *
8321 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8322 * voicemail ringtone.
8323 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8324 * PhoneAccount.
8325 */
8326 @Override
8327 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008328 final long identity = Binder.clearCallingIdentity();
8329 try {
8330 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8331 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008332 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008333 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008334
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008335 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8336 } finally {
8337 Binder.restoreCallingIdentity(identity);
8338 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008339 }
8340
8341 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008342 * Sets the per-account voicemail ringtone.
8343 *
8344 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8345 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8346 *
8347 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8348 * voicemail ringtone.
8349 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8350 * PhoneAccount.
8351 */
8352 @Override
8353 public void setVoicemailRingtoneUri(String callingPackage,
8354 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008355 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008356 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008357 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8358 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8360 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8361 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008362 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008363
8364 final long identity = Binder.clearCallingIdentity();
8365 try {
8366 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8367 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008368 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008369 }
8370 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8371 } finally {
8372 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008373 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008374 }
8375
8376 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008377 * Returns whether vibration is set for voicemail notification in Phone settings.
8378 *
8379 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8380 * voicemail vibration setting.
8381 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8382 */
8383 @Override
8384 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008385 final long identity = Binder.clearCallingIdentity();
8386 try {
8387 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8388 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008389 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008390 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008391
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008392 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8393 } finally {
8394 Binder.restoreCallingIdentity(identity);
8395 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008396 }
8397
Youhan Wange64578a2016-05-02 15:32:42 -07008398 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008399 * Sets the per-account voicemail vibration.
8400 *
8401 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8402 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8403 *
8404 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8405 * voicemail vibration setting.
8406 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8407 * specific PhoneAccount.
8408 */
8409 @Override
8410 public void setVoicemailVibrationEnabled(String callingPackage,
8411 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008412 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008413 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008414 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8415 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008416 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8417 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8418 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008419 }
8420
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008421 final long identity = Binder.clearCallingIdentity();
8422 try {
8423 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8424 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008425 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008426 }
8427 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8428 } finally {
8429 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008430 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008431 }
8432
8433 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008434 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8435 *
8436 * @throws SecurityException if the caller does not have the required permission
8437 */
arunvoddud7401012022-12-15 16:08:12 +00008438 @VisibleForTesting
8439 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008440 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008441 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008442 }
8443
8444 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008445 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8446 * permission.
8447 *
8448 * @throws SecurityException if the caller does not have the required permission
8449 */
8450 private void enforceSendSmsPermission() {
8451 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8452 }
8453
8454 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008455 * Make sure either called from same process as self (phone) or IPC caller has interact across
8456 * users permission.
8457 *
8458 * @throws SecurityException if the caller does not have the required permission
8459 */
8460 private void enforceInteractAcrossUsersPermission(String message) {
8461 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8462 }
8463
8464 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008465 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008466 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008467 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008468 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008469 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008470 final long identity = Binder.clearCallingIdentity();
8471 try {
8472 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008473 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008474 if (componentName == null) {
8475 throw new SecurityException(
8476 "Caller not current active visual voicemail package[null]");
8477 }
8478 String vvmPackage = componentName.getPackageName();
8479 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008480 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008481 }
8482 } finally {
8483 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008484 }
8485 }
8486
8487 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008488 * Return the application ID for the app type.
8489 *
8490 * @param subId the subscription ID that this request applies to.
8491 * @param appType the uicc app type.
8492 * @return Application ID for specificied app type, or null if no uicc.
8493 */
8494 @Override
8495 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008496 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008497 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008498
8499 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008500 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008501 if (phone == null) {
8502 return null;
8503 }
8504 String aid = null;
8505 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008506 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008507 .getApplicationByType(appType).getAid();
8508 } catch (Exception e) {
8509 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8510 }
8511 return aid;
8512 } finally {
8513 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008514 }
Youhan Wange64578a2016-05-02 15:32:42 -07008515 }
8516
Youhan Wang4001d252016-05-11 10:29:41 -07008517 /**
8518 * Return the Electronic Serial Number.
8519 *
8520 * @param subId the subscription ID that this request applies to.
8521 * @return ESN or null if error.
8522 */
8523 @Override
8524 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008525 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008526 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008527
8528 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008529 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008530 if (phone == null) {
8531 return null;
8532 }
8533 String esn = null;
8534 try {
8535 esn = phone.getEsn();
8536 } catch (Exception e) {
8537 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8538 }
8539 return esn;
8540 } finally {
8541 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008542 }
Youhan Wang4001d252016-05-11 10:29:41 -07008543 }
8544
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008545 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008546 * Return the Preferred Roaming List Version.
8547 *
8548 * @param subId the subscription ID that this request applies to.
8549 * @return PRLVersion or null if error.
8550 */
8551 @Override
8552 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008553 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008554 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008555
8556 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008557 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008558 if (phone == null) {
8559 return null;
8560 }
8561 String cdmaPrlVersion = null;
8562 try {
8563 cdmaPrlVersion = phone.getCdmaPrlVersion();
8564 } catch (Exception e) {
8565 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8566 }
8567 return cdmaPrlVersion;
8568 } finally {
8569 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008570 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008571 }
8572
8573 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008574 * Get snapshot of Telephony histograms
8575 * @return List of Telephony histograms
8576 * @hide
8577 */
8578 @Override
8579 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008580 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8581 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008582
8583 final long identity = Binder.clearCallingIdentity();
8584 try {
8585 return RIL.getTelephonyRILTimingHistograms();
8586 } finally {
8587 Binder.restoreCallingIdentity(identity);
8588 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008589 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008590
8591 /**
8592 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008593 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8594 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008595 * Require system privileges. In the future we may add this to carrier APIs.
8596 *
Michele Berionne482f8202018-11-27 18:57:59 -08008597 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008598 */
8599 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008600 @TelephonyManager.SetCarrierRestrictionResult
8601 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008602 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008603 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008604
Michele Berionne482f8202018-11-27 18:57:59 -08008605 if (carrierRestrictionRules == null) {
8606 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008607 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008608
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008609 final long identity = Binder.clearCallingIdentity();
8610 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008611 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008612 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008613 } finally {
8614 Binder.restoreCallingIdentity(identity);
8615 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008616 }
8617
8618 /**
8619 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008620 * Get the allowed carrier list and the excluded carrier list, including the priority between
8621 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008622 * Require system privileges. In the future we may add this to carrier APIs.
8623 *
Michele Berionne482f8202018-11-27 18:57:59 -08008624 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008625 */
8626 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008627 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008628 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008629 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008630
8631 final long identity = Binder.clearCallingIdentity();
8632 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008633 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8634 if (response instanceof CarrierRestrictionRules) {
8635 return (CarrierRestrictionRules) response;
8636 }
8637 // Response is an Exception of some kind,
8638 // which is signalled to the user as a NULL retval
8639 return null;
8640 } catch (Exception e) {
8641 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8642 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008643 } finally {
8644 Binder.restoreCallingIdentity(identity);
8645 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008646 }
8647
fionaxu59545b42016-05-25 15:53:37 -07008648 /**
arunvoddud7401012022-12-15 16:08:12 +00008649 * Fetches the carrier restriction status of the device and sends the status to the caller
8650 * through the callback.
8651 *
8652 * @param callback The callback that will be used to send the result.
8653 * @throws SecurityException if the caller does not have the required permission/privileges or
8654 * the caller is not allowlisted.
8655 */
8656 @Override
8657 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
8658 enforceReadPermission("getCarrierRestrictionStatus");
8659 int carrierId = validateCallerAndGetCarrierId(packageName);
8660 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
8661 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
8662 throw new SecurityException("Not an authorized caller");
8663 }
8664 final long identity = Binder.clearCallingIdentity();
8665 try {
8666 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
8667 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
8668 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
8669 } finally {
8670 Binder.restoreCallingIdentity(identity);
8671 }
8672 }
8673
arunvoddu567f2b42023-04-25 17:22:00 +00008674 @Override
8675 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
8676 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
8677 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8678 return allowListInfo.getShaIdList(pkgName, carrierId);
8679 }
8680
arunvoddud7401012022-12-15 16:08:12 +00008681 @VisibleForTesting
8682 public int validateCallerAndGetCarrierId(String packageName) {
8683 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8684 return allowListInfo.validateCallerAndGetCarrierId(packageName);
8685 }
8686
8687 /**
fionaxu59545b42016-05-25 15:53:37 -07008688 * Action set from carrier signalling broadcast receivers to enable/disable radio
8689 * @param subId the subscription ID that this action applies to.
8690 * @param enabled control enable or disable radio.
8691 * {@hide}
8692 */
8693 @Override
8694 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8695 enforceModifyPermission();
8696 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008697
8698 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008699 if (phone == null) {
8700 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8701 return;
8702 }
8703 try {
8704 phone.carrierActionSetRadioEnabled(enabled);
8705 } catch (Exception e) {
8706 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008707 } finally {
8708 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008709 }
8710 }
8711
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008712 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008713 * Enable or disable Voice over NR (VoNR)
8714 * @param subId the subscription ID that this action applies to.
8715 * @param enabled enable or disable VoNR.
8716 * @return operation result.
8717 */
8718 @Override
8719 public int setVoNrEnabled(int subId, boolean enabled) {
8720 enforceModifyPermission();
8721 final Phone phone = getPhone(subId);
8722
8723 final long identity = Binder.clearCallingIdentity();
8724 if (phone == null) {
8725 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8726 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8727 }
8728
8729 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8730 try {
8731 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8732 workSource);
8733 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008734
8735 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8736 if (DBG) {
8737 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8738 }
8739 SubscriptionManager.setSubscriptionProperty(
8740 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8741 (enabled ? "1" : "0"));
8742 }
8743
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008744 return result;
8745 } finally {
8746 Binder.restoreCallingIdentity(identity);
8747 }
8748 }
8749
8750 /**
8751 * Is voice over NR enabled
8752 * @return true if VoNR is enabled else false
8753 */
8754 @Override
8755 public boolean isVoNrEnabled(int subId) {
8756 enforceReadPrivilegedPermission("isVoNrEnabled");
8757 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8758 final long identity = Binder.clearCallingIdentity();
8759 try {
8760 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8761 null, subId, workSource);
8762 if (DBG) log("isVoNrEnabled: " + isEnabled);
8763 return isEnabled;
8764 } finally {
8765 Binder.restoreCallingIdentity(identity);
8766 }
8767 }
8768
8769 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008770 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8771 * network status based on which carrier apps could apply actions accordingly,
8772 * enable/disable default url handler for example.
8773 *
8774 * @param subId the subscription ID that this action applies to.
8775 * @param report control start/stop reporting the default network status.
8776 * {@hide}
8777 */
8778 @Override
8779 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8780 enforceModifyPermission();
8781 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008782
8783 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008784 if (phone == null) {
8785 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8786 return;
8787 }
8788 try {
8789 phone.carrierActionReportDefaultNetworkStatus(report);
8790 } catch (Exception e) {
8791 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008792 } finally {
8793 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008794 }
8795 }
8796
8797 /**
fionaxud9622282017-07-17 17:51:30 -07008798 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8799 * @param subId the subscription ID that this action applies to.
8800 * {@hide}
8801 */
8802 @Override
8803 public void carrierActionResetAll(int subId) {
8804 enforceModifyPermission();
8805 final Phone phone = getPhone(subId);
8806 if (phone == null) {
8807 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8808 return;
8809 }
8810 try {
8811 phone.carrierActionResetAll();
8812 } catch (Exception e) {
8813 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8814 }
8815 }
8816
8817 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008818 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8819 * bug report is being generated.
8820 */
8821 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008822 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008823 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8824 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008825 writer.println("Permission Denial: can't dump Phone from pid="
8826 + Binder.getCallingPid()
8827 + ", uid=" + Binder.getCallingUid()
8828 + "without permission "
8829 + android.Manifest.permission.DUMP);
8830 return;
8831 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008832 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008833 }
Jack Yueb89b242016-06-22 13:27:47 -07008834
Brad Ebingerdac2f002018-04-03 15:17:52 -07008835 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008836 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8837 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8838 @NonNull String[] args) {
8839 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8840 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008841 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008842 }
8843
Jack Yueb89b242016-06-22 13:27:47 -07008844 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008845 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008846 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008847 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008848 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008849 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008850 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008851 */
8852 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008853 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008854 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008855 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8856 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8857 try {
8858 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008859 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008860 } catch (SecurityException se) {
8861 enforceModifyPermission();
8862 }
8863 } else {
8864 enforceModifyPermission();
8865 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008866
8867 final long identity = Binder.clearCallingIdentity();
8868 try {
8869 Phone phone = getPhone(subId);
8870 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008871 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8872 phone.carrierActionSetMeteredApnsEnabled(enabled);
8873 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008874 phone.getDataSettingsManager().setDataEnabled(
8875 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008876 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008877 }
8878 } finally {
8879 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008880 }
8881 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008882
8883 /**
8884 * Get Client request stats
8885 * @return List of Client Request Stats
8886 * @hide
8887 */
8888 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008889 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8890 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008891 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008892 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008893 return null;
8894 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008895 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008896
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008897 final long identity = Binder.clearCallingIdentity();
8898 try {
8899 if (phone != null) {
8900 return phone.getClientRequestStats();
8901 }
8902
8903 return null;
8904 } finally {
8905 Binder.restoreCallingIdentity(identity);
8906 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008907 }
8908
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008909 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008910 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008911 if (uid == Process.ROOT_UID && packageName == null) {
8912 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8913 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8914 // exception. ROOT_UID seems not to have a valid package name returned by
8915 // PackageManager, so just fake it here to avoid issues when running telephony shell
8916 // commands that plumb through the RIL as root, like so:
8917 // $ adb root
8918 // $ adb shell cmd phone ...
8919 packageName = "root";
8920 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008921 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008922 }
Jack Yueb4124c2017-02-16 15:32:43 -08008923
8924 /**
Grace Chen70990072017-03-24 17:21:30 -07008925 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008926 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008927 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008928 * @param state State of SIM (power down, power up, pass through)
8929 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8930 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8931 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008932 *
8933 **/
8934 @Override
Grace Chen70990072017-03-24 17:21:30 -07008935 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008936 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008937 Phone phone = PhoneFactory.getPhone(slotIndex);
8938
vagdeviaf9a5b92018-08-15 16:01:53 -07008939 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8940
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008941 final long identity = Binder.clearCallingIdentity();
8942 try {
8943 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008944 phone.setSimPowerState(state, null, workSource);
8945 }
8946 } finally {
8947 Binder.restoreCallingIdentity(identity);
8948 }
8949 }
8950
8951 /**
8952 * Set SIM card power state.
8953 *
8954 * @param slotIndex SIM slot id.
8955 * @param state State of SIM (power down, power up, pass through)
8956 * @param callback callback to trigger after success or failure
8957 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8958 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8959 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8960 *
8961 **/
8962 @Override
8963 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8964 IIntegerConsumer callback) {
8965 enforceModifyPermission();
8966 Phone phone = PhoneFactory.getPhone(slotIndex);
8967
8968 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8969
8970 final long identity = Binder.clearCallingIdentity();
8971 try {
8972 if (phone != null) {
8973 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8974 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008975 }
8976 } finally {
8977 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008978 }
8979 }
Shuo Qiandd210312017-04-12 22:11:33 +00008980
Tyler Gunn65d45c22017-06-05 11:22:26 -07008981 private boolean isUssdApiAllowed(int subId) {
8982 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008983 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008984 if (configManager == null) {
8985 return false;
8986 }
8987 PersistableBundle pb = configManager.getConfigForSubId(subId);
8988 if (pb == null) {
8989 return false;
8990 }
8991 return pb.getBoolean(
8992 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8993 }
8994
Shuo Qiandd210312017-04-12 22:11:33 +00008995 /**
Ling Mac28f0212023-03-24 16:07:15 -07008996 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00008997 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07008998 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00008999 */
goneil9c5f4872017-12-05 14:07:56 -08009000 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009001 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009002 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009003 final long identity = Binder.clearCallingIdentity();
9004 try {
Ling Mac28f0212023-03-24 16:07:15 -07009005 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009006 } finally {
9007 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009008 }
9009 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009010
9011 /**
9012 * Get the current signal strength information for the given subscription.
9013 * Because this information is not updated when the device is in a low power state
9014 * it should not be relied-upon to be current.
9015 * @param subId Subscription index
9016 * @return the most recent cached signal strength info from the modem
9017 */
9018 @Override
9019 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009020 final long identity = Binder.clearCallingIdentity();
9021 try {
9022 Phone p = getPhone(subId);
9023 if (p == null) {
9024 return null;
9025 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009026
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009027 return p.getSignalStrength();
9028 } finally {
9029 Binder.restoreCallingIdentity(identity);
9030 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009031 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009032
Pengquan Meng77b7f132018-08-22 14:49:57 -07009033 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009034 * Get the current modem radio state for the given slot.
9035 * @param slotIndex slot index.
9036 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009037 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009038 * @return the current radio power state from the modem
9039 */
9040 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009041 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009042 Phone phone = PhoneFactory.getPhone(slotIndex);
9043 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009044 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9045 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009046 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9047 }
9048
9049 final long identity = Binder.clearCallingIdentity();
9050 try {
9051 return phone.getRadioPowerState();
9052 } finally {
9053 Binder.restoreCallingIdentity(identity);
9054 }
9055 }
9056 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9057 }
9058
9059 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009060 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9061 *
9062 * <p>Requires one of the following permissions:
9063 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009064 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009065 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9066 * privileges.
9067 *
9068 * @param subId subscription id
9069 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9070 * {@code false}.
9071 */
9072 @Override
9073 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009074 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009075 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009076 try {
9077 mApp.enforceCallingOrSelfPermission(
9078 android.Manifest.permission.ACCESS_NETWORK_STATE,
9079 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009080 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009081 mApp.enforceCallingOrSelfPermission(
9082 permission.READ_BASIC_PHONE_STATE, functionName);
9083 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009084 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009085 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009086 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009087 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009088
Pengquan Menga1bb6272018-09-06 09:59:22 -07009089 boolean isEnabled = false;
9090 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009091 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009092 Phone phone = getPhone(subId);
9093 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009094 } finally {
9095 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009096 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009097 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009098 }
9099
9100
9101 /**
9102 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9103 *
9104 * <p> Requires permission:
9105 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9106 * privileges.
9107 *
9108 * @param subId subscription id
9109 * @param isEnabled {@code true} means enable, {@code false} means disable.
9110 */
9111 @Override
9112 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009113 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9114 mApp, subId, "setDataRoamingEnabled");
9115
Pengquan Menga1bb6272018-09-06 09:59:22 -07009116 final long identity = Binder.clearCallingIdentity();
9117 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009118 Phone phone = getPhone(subId);
9119 if (phone != null) {
9120 phone.setDataRoamingEnabled(isEnabled);
9121 }
9122 } finally {
9123 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009124 }
9125 }
9126
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009127 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009128 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009129 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009130 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009131 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009132
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009133 boolean isAllowed = true;
9134 final long identity = Binder.clearCallingIdentity();
9135 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009136 Phone phone = getPhone(subId);
9137 if (phone != null) {
9138 isAllowed = phone.isCspPlmnEnabled();
9139 }
9140 } finally {
9141 Binder.restoreCallingIdentity(identity);
9142 }
9143 return isAllowed;
9144 }
9145
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009146 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9147 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009148 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009149 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009150 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009151 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9152 if (phone == null) {
9153 return false;
9154 }
9155 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9156 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9157 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009158 }
9159
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009160 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009161 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009162 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009163 mApp.getSystemService(AppOpsManager.class)
9164 .checkPackage(Binder.getCallingUid(), callingPackage);
9165
Jordan Liu1e142fc2019-04-22 15:10:43 -07009166 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009167 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009168 try {
9169 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009170 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009171 } catch (SecurityException e) {
9172 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9173 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009174 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009175 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009176 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009177 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009178 }
sandeepjsb6c87872021-09-27 15:34:44 +00009179 // checking compatibility, if calling app's target SDK is T and beyond.
9180 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9181 Binder.getCallingUid())) {
9182 isIccIdAccessRestricted = true;
9183 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009184 final long identity = Binder.clearCallingIdentity();
9185 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009186 UiccController uiccController = UiccController.getInstance();
9187 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009188 if (hasReadPermission) {
9189 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009190 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009191
9192 // Remove private info if the caller doesn't have access
9193 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9194 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009195 //setting the value after compatibility check
9196 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009197 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9198 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009199 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009200 if (card == null) {
9201 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009202 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009203 continue;
9204 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009205 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9206 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009207 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009208 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009209 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009210 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9211 for (UiccPortInfo portInfo : portInfos) {
9212 UiccPort port = uiccController.getUiccPortForSlot(
9213 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9214 if (port == null) {
9215 // assume no access if port is null
9216 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9217 continue;
9218 }
9219 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9220 uiccPortInfos.add(portInfo);
9221 } else {
9222 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9223 }
9224 }
9225 filteredInfos.add(new UiccCardInfo(
9226 cardInfo.isEuicc(),
9227 cardInfo.getCardId(),
9228 null,
9229 cardInfo.getPhysicalSlotIndex(),
9230 cardInfo.isRemovable(),
9231 cardInfo.isMultipleEnabledProfilesSupported(),
9232 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009233 }
9234 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009235 } finally {
9236 Binder.restoreCallingIdentity(identity);
9237 }
9238 }
9239
sandeepjsb6c87872021-09-27 15:34:44 +00009240 /**
9241 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9242 * generally private and require carrier privileges to view.
9243 *
9244 * @hide
9245 */
9246 @NonNull
9247 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9248 List<UiccPortInfo> portinfo = new ArrayList<>();
9249 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9250 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9251 }
9252 return new UiccCardInfo(
9253 cardInfo.isEuicc(),
9254 cardInfo.getCardId(),
9255 null,
9256 cardInfo.getPhysicalSlotIndex(),
9257 cardInfo.isRemovable(),
9258 cardInfo.isMultipleEnabledProfilesSupported(),
9259 portinfo
9260 );
9261 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009262
sandeepjsb6c87872021-09-27 15:34:44 +00009263 /**
9264 * @hide
9265 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9266 * These values are generally private and require carrier privileges to view.
9267 */
9268 @NonNull
9269 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9270 return new UiccPortInfo(
9271 UiccPortInfo.ICCID_REDACTED,
9272 portInfo.getPortIndex(),
9273 portInfo.getLogicalSlotIndex(),
9274 portInfo.isActive()
9275 );
9276 }
9277 @Override
9278 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009279 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009280 mApp.getSystemService(AppOpsManager.class)
9281 .checkPackage(Binder.getCallingUid(), callingPackage);
9282
sandeepjsb6c87872021-09-27 15:34:44 +00009283 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009284
Aman Guptaf3c90b32022-03-17 04:54:16 +00009285 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9286 // we are reading iccId which is PII data.
9287 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009288
9289 // checking compatibility, if calling app's target SDK is T and beyond.
9290 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9291 Binder.getCallingUid())) {
9292 isLogicalSlotAccessRestricted = true;
9293 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009294 final long identity = Binder.clearCallingIdentity();
9295 try {
9296 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009297 if (slots == null || slots.length == 0) {
9298 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009299 return null;
9300 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009301 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9302 for (int i = 0; i < slots.length; i++) {
9303 UiccSlot slot = slots[i];
9304 if (slot == null) {
9305 continue;
9306 }
9307
Jordan Liu7be7e652019-05-06 18:55:02 +00009308 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009309 UiccCard card = slot.getUiccCard();
9310 if (card != null) {
9311 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009312 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009313 cardId = slot.getEid();
9314 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009315 // If cardId is null, use iccId of default port as cardId.
9316 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009317 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009318 }
9319
Jordan Liu857451f2019-05-09 16:35:35 -07009320 if (cardId != null) {
9321 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9322 // if cardId is an EID, it's all digits so this is fine
9323 cardId = IccUtils.stripTrailingFs(cardId);
9324 }
9325
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009326 int cardState = 0;
9327 switch (slot.getCardState()) {
9328 case CARDSTATE_ABSENT:
9329 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9330 break;
9331 case CARDSTATE_PRESENT:
9332 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9333 break;
9334 case CARDSTATE_ERROR:
9335 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9336 break;
9337 case CARDSTATE_RESTRICTED:
9338 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9339 break;
9340 default:
9341 break;
9342
9343 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009344 List<UiccPortInfo> portInfos = new ArrayList<>();
9345 int[] portIndexes = slot.getPortList();
9346 for (int portIdx : portIndexes) {
9347 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009348 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009349 portInfos.add(new UiccPortInfo(iccId, portIdx,
9350 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009351 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009352 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009353 slot.isEuicc(),
9354 cardId,
9355 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009356 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009357 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009358 //setting the value after compatibility check
9359 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009360 }
9361 return infos;
9362 } finally {
9363 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009364 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009365 }
9366
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009367 /* Returns null if doesn't have read permission or carrier privilege access. */
9368 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9369 boolean hasReadPermission) {
9370 String iccId = slot.getIccId(portIndex);
9371 if (hasReadPermission) { // if has read permission
9372 return iccId;
9373 } else {
9374 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9375 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9376 // if no read permission, checking carrier privilege access
9377 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9378 return iccId;
9379 }
9380 }
9381 }
9382 // No read permission or carrier privilege access.
9383 return UiccPortInfo.ICCID_REDACTED;
9384 }
9385
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009386 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009387 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009388 public boolean switchSlots(int[] physicalSlots) {
9389 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009390
9391 final long identity = Binder.clearCallingIdentity();
9392 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009393 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9394 for (int i = 0; i < physicalSlots.length; i++) {
9395 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9396 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9397 physicalSlots[i], i));
9398 }
9399 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009400 } finally {
9401 Binder.restoreCallingIdentity(identity);
9402 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009403 }
Jack Yu4c988042018-02-27 15:30:01 -08009404
9405 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009406 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9407 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9408 enforceModifyPermission();
9409
9410 final long identity = Binder.clearCallingIdentity();
9411 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009412 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009413 } finally {
9414 Binder.restoreCallingIdentity(identity);
9415 }
9416 }
9417
9418 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009419 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009420 final long identity = Binder.clearCallingIdentity();
9421 try {
9422 return UiccController.getInstance().getCardIdForDefaultEuicc();
9423 } finally {
9424 Binder.restoreCallingIdentity(identity);
9425 }
9426 }
9427
Pengquan Meng85728fb2018-03-12 16:31:21 -07009428 /**
goneil47ffb6e2018-04-06 15:40:58 -07009429 * A test API to reload the UICC profile.
9430 *
9431 * <p>Requires that the calling app has permission
9432 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9433 * @hide
9434 */
9435 @Override
9436 public void refreshUiccProfile(int subId) {
9437 enforceModifyPermission();
9438
9439 final long identity = Binder.clearCallingIdentity();
9440 try {
9441 Phone phone = getPhone(subId);
9442 if (phone == null) {
9443 return;
9444 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009445 UiccPort uiccPort = phone.getUiccPort();
9446 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009447 return;
9448 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009449 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009450 if (uiccProfile == null) {
9451 return;
9452 }
9453 uiccProfile.refresh();
9454 } finally {
9455 Binder.restoreCallingIdentity(identity);
9456 }
9457 }
9458
9459 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009460 * Returns false if the mobile data is disabled by default, otherwise return true.
9461 */
9462 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009463 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009464 }
9465
9466 /**
9467 * Returns true if the data roaming is enabled by default, i.e the system property
9468 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9469 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9470 */
9471 private boolean getDefaultDataRoamingEnabled(int subId) {
9472 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009473 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009474 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009475 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9476 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9477 return isDataRoamingEnabled;
9478 }
9479
9480 /**
9481 * Returns the default network type for the given {@code subId}, if the default network type is
9482 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9483 */
9484 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009485 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009486 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009487 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9488 return list.get(phoneId);
9489 }
9490 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009491 }
fionaxua13278b2018-03-21 00:08:13 -07009492
9493 @Override
9494 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009495 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009496 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009497
9498 final long identity = Binder.clearCallingIdentity();
9499 try {
9500 final Phone phone = getPhone(subId);
9501 if (phone == null) {
9502 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9503 return;
9504 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009505 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9506 if (cpt != null) {
9507 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9508 }
9509 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009510 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9511 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009512 if (carrierPrivilegeRules == null) {
9513 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9514 } else {
9515 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9516 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009517 } finally {
9518 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009519 }
fionaxua13278b2018-03-21 00:08:13 -07009520 }
9521
9522 @Override
Benedict Wong66477622023-02-03 23:30:57 +00009523 public void setCarrierServicePackageOverride(
9524 int subId, String carrierServicePackage, String callingPackage) {
9525 TelephonyPermissions.enforceShellOnly(
9526 Binder.getCallingUid(), "setCarrierServicePackageOverride");
9527
9528 // Verify that the callingPackage belongs to the calling UID
9529 mApp.getSystemService(AppOpsManager.class)
9530 .checkPackage(Binder.getCallingUid(), callingPackage);
9531
9532 final long identity = Binder.clearCallingIdentity();
9533 try {
9534 final Phone phone = getPhone(subId);
9535 if (phone == null || phone.getSubId() != subId) {
9536 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
9537 throw new IllegalArgumentException("No phone for subid");
9538 }
9539 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9540 if (cpt == null) {
9541 loge("setCarrierServicePackageOverride failed with no CPT for phone");
9542 throw new IllegalStateException("No CPT for phone");
9543 }
9544 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
9545 } finally {
9546 Binder.restoreCallingIdentity(identity);
9547 }
9548 }
9549
9550 @Override
fionaxua13278b2018-03-21 00:08:13 -07009551 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009552 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009553
9554 final long identity = Binder.clearCallingIdentity();
9555 try {
9556 final Phone phone = getPhone(subId);
9557 if (phone == null) {
9558 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9559 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9560 }
9561 return phone.getCarrierIdListVersion();
9562 } finally {
9563 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009564 }
fionaxua13278b2018-03-21 00:08:13 -07009565 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009566
9567 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009568 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9569 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009570 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009571 mApp, subId, callingPackage, callingFeatureId,
9572 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009573 return -1;
9574 }
9575
9576 final long identity = Binder.clearCallingIdentity();
9577 try {
9578 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9579 } finally {
9580 Binder.restoreCallingIdentity(identity);
9581 }
9582 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009583
9584 @Override
9585 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009586 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009587 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009588 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -07009589
9590 final long identity = Binder.clearCallingIdentity();
9591 try {
9592 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9593 } finally {
9594 Binder.restoreCallingIdentity(identity);
9595 }
9596 }
9597
9598 @Override
9599 public boolean setCdmaRoamingMode(int subId, int mode) {
9600 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9601 mApp, subId, "setCdmaRoamingMode");
9602
9603 final long identity = Binder.clearCallingIdentity();
9604 try {
9605 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9606 } finally {
9607 Binder.restoreCallingIdentity(identity);
9608 }
9609 }
9610
9611 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009612 public int getCdmaSubscriptionMode(int subId) {
9613 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009614 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009615 mApp, subId, "getCdmaSubscriptionMode");
9616
9617 final long identity = Binder.clearCallingIdentity();
9618 try {
9619 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9620 } finally {
9621 Binder.restoreCallingIdentity(identity);
9622 }
9623 }
9624
9625 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009626 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9628 mApp, subId, "setCdmaSubscriptionMode");
9629
9630 final long identity = Binder.clearCallingIdentity();
9631 try {
9632 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9633 } finally {
9634 Binder.restoreCallingIdentity(identity);
9635 }
9636 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009637
sqianc5eccab2018-10-19 18:46:41 -07009638 @Override
sqian8c685422019-02-22 15:55:18 -08009639 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009640 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009641 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009642 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9643 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009644 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9645 }
9646 final long identity = Binder.clearCallingIdentity();
9647 try {
sqian854d44b2018-12-12 16:48:18 -08009648 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9649 for (Phone phone: PhoneFactory.getPhones()) {
9650 if (phone.getEmergencyNumberTracker() != null
9651 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9652 emergencyNumberListInternal.put(
9653 phone.getSubId(),
9654 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9655 }
sqian11b7a0e2018-12-05 18:48:28 -08009656 }
sqian854d44b2018-12-12 16:48:18 -08009657 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009658 } finally {
9659 Binder.restoreCallingIdentity(identity);
9660 }
sqianc5eccab2018-10-19 18:46:41 -07009661 }
9662
9663 @Override
sqian8c685422019-02-22 15:55:18 -08009664 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009665 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009666 if (!exactMatch) {
9667 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009668 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009669 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009670 }
9671 final long identity = Binder.clearCallingIdentity();
9672 try {
sqian854d44b2018-12-12 16:48:18 -08009673 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009674 //Note: we ignore passed in param exactMatch. We can remove it once
9675 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009676 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009677 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009678 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009679 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009680 }
sqian11b7a0e2018-12-05 18:48:28 -08009681 }
9682 return false;
9683 } finally {
9684 Binder.restoreCallingIdentity(identity);
9685 }
9686 }
9687
sqianf4ca7ed2019-01-15 18:32:07 -08009688 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009689 * Start emergency callback mode for GsmCdmaPhone for testing.
9690 */
9691 @Override
9692 public void startEmergencyCallbackMode() {
9693 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9694 "startEmergencyCallbackMode");
9695 enforceModifyPermission();
9696 final long identity = Binder.clearCallingIdentity();
9697 try {
9698 for (Phone phone : PhoneFactory.getPhones()) {
9699 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9700 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9701 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9702 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9703 gsmCdmaPhone.obtainMessage(
9704 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9705 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9706 }
9707 }
9708 } finally {
9709 Binder.restoreCallingIdentity(identity);
9710 }
9711 }
9712
9713 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009714 * Update emergency number list for test mode.
9715 */
9716 @Override
9717 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9718 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9719 "updateEmergencyNumberListTestMode");
9720
9721 final long identity = Binder.clearCallingIdentity();
9722 try {
9723 for (Phone phone: PhoneFactory.getPhones()) {
9724 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9725 if (tracker != null) {
9726 tracker.executeEmergencyNumberTestModeCommand(action, num);
9727 }
9728 }
9729 } finally {
9730 Binder.restoreCallingIdentity(identity);
9731 }
9732 }
9733
9734 /**
9735 * Get the full emergency number list for test mode.
9736 */
9737 @Override
9738 public List<String> getEmergencyNumberListTestMode() {
9739 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9740 "getEmergencyNumberListTestMode");
9741
9742 final long identity = Binder.clearCallingIdentity();
9743 try {
9744 Set<String> emergencyNumbers = new HashSet<>();
9745 for (Phone phone: PhoneFactory.getPhones()) {
9746 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9747 if (tracker != null) {
9748 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9749 emergencyNumbers.add(num.getNumber());
9750 }
9751 }
9752 }
9753 return new ArrayList<>(emergencyNumbers);
9754 } finally {
9755 Binder.restoreCallingIdentity(identity);
9756 }
9757 }
9758
chen xud6b45bd2018-10-30 22:27:10 -07009759 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009760 public int getEmergencyNumberDbVersion(int subId) {
9761 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9762
9763 final long identity = Binder.clearCallingIdentity();
9764 try {
9765 final Phone phone = getPhone(subId);
9766 if (phone == null) {
9767 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9768 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9769 }
9770 return phone.getEmergencyNumberDbVersion();
9771 } finally {
9772 Binder.restoreCallingIdentity(identity);
9773 }
9774 }
9775
9776 @Override
9777 public void notifyOtaEmergencyNumberDbInstalled() {
9778 enforceModifyPermission();
9779
9780 final long identity = Binder.clearCallingIdentity();
9781 try {
9782 for (Phone phone: PhoneFactory.getPhones()) {
9783 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9784 if (tracker != null) {
9785 tracker.updateOtaEmergencyNumberDatabase();
9786 }
9787 }
9788 } finally {
9789 Binder.restoreCallingIdentity(identity);
9790 }
9791 }
9792
9793 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009794 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009795 enforceActiveEmergencySessionPermission();
9796
9797 final long identity = Binder.clearCallingIdentity();
9798 try {
9799 for (Phone phone: PhoneFactory.getPhones()) {
9800 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9801 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009802 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9803 }
9804 }
9805 } finally {
9806 Binder.restoreCallingIdentity(identity);
9807 }
9808 }
9809
9810 @Override
9811 public void resetOtaEmergencyNumberDbFilePath() {
9812 enforceActiveEmergencySessionPermission();
9813
9814 final long identity = Binder.clearCallingIdentity();
9815 try {
9816 for (Phone phone: PhoneFactory.getPhones()) {
9817 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9818 if (tracker != null) {
9819 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009820 }
9821 }
9822 } finally {
9823 Binder.restoreCallingIdentity(identity);
9824 }
9825 }
9826
9827 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009828 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9829 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9830 Phone phone = getPhone(subId);
9831 if (phone == null) {
9832 return null;
9833 }
9834 final long identity = Binder.clearCallingIdentity();
9835 try {
9836 UiccProfile profile = UiccController.getInstance()
9837 .getUiccProfileForPhone(phone.getPhoneId());
9838 if (profile != null) {
9839 return profile.getCertsFromCarrierPrivilegeAccessRules();
9840 }
9841 } finally {
9842 Binder.restoreCallingIdentity(identity);
9843 }
9844 return null;
9845 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009846
9847 /**
9848 * Enable or disable a modem stack.
9849 */
9850 @Override
9851 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9852 enforceModifyPermission();
9853
9854 final long identity = Binder.clearCallingIdentity();
9855 try {
9856 Phone phone = PhoneFactory.getPhone(slotIndex);
9857 if (phone == null) {
9858 return false;
9859 } else {
9860 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9861 }
9862 } finally {
9863 Binder.restoreCallingIdentity(identity);
9864 }
9865 }
Michelecea4cf22018-12-21 15:00:11 -08009866
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009867 /**
9868 * Whether a modem stack is enabled or not.
9869 */
9870 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009871 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9872 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009873 Phone phone = PhoneFactory.getPhone(slotIndex);
9874 if (phone == null) return false;
9875
9876 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009877 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9878 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009879 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9880 }
9881
9882 final long identity = Binder.clearCallingIdentity();
9883 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009884 try {
9885 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9886 } catch (NoSuchElementException ex) {
9887 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9888 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009889 } finally {
9890 Binder.restoreCallingIdentity(identity);
9891 }
9892 }
9893
Michelecea4cf22018-12-21 15:00:11 -08009894 @Override
Michele0ea7d782019-03-19 14:58:42 -07009895 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009896 enforceModifyPermission();
9897
9898 final long identity = Binder.clearCallingIdentity();
9899 try {
9900 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009901 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009902 .commit();
9903 } finally {
9904 Binder.restoreCallingIdentity(identity);
9905 }
9906 }
9907
9908 @Override
Michele0ea7d782019-03-19 14:58:42 -07009909 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009910 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009911 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009912 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9913 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009914 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009915 }
Michelecea4cf22018-12-21 15:00:11 -08009916
9917 final long identity = Binder.clearCallingIdentity();
9918 try {
Michele0ea7d782019-03-19 14:58:42 -07009919 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009920 } finally {
9921 Binder.restoreCallingIdentity(identity);
9922 }
9923 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009924
Michele0ea7d782019-03-19 14:58:42 -07009925 @TelephonyManager.IsMultiSimSupportedResult
9926 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009927 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9928 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9929 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009930 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9931 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009932 }
9933 // Check if the hardware supports multisim functionality. If usage of multisim is not
9934 // supported by the modem, indicate that it is restricted.
9935 PhoneCapability staticCapability =
9936 mPhoneConfigurationManager.getStaticPhoneCapability();
9937 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009938 loge("isMultiSimSupportedInternal: no static configuration available");
9939 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009940 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009941 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009942 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9943 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009944 }
9945 // Check if support of multiple SIMs is restricted by carrier
9946 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009947 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009948 }
9949
Michele0ea7d782019-03-19 14:58:42 -07009950 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009951 }
9952
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009953 /**
9954 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009955 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9956 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9957 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009958 * @param numOfSims number of active sims we want to switch to
9959 */
9960 @Override
9961 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009962 if (numOfSims == 1) {
9963 enforceModifyPermission();
9964 } else {
9965 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9966 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9967 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009968 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009969
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009970 try {
Michele30b57b22019-03-01 12:01:14 -08009971 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009972 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009973 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9974 return;
9975 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009976 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9977 } finally {
9978 Binder.restoreCallingIdentity(identity);
9979 }
9980 }
9981
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009982 @Override
9983 public boolean isApplicationOnUicc(int subId, int appType) {
9984 enforceReadPrivilegedPermission("isApplicationOnUicc");
9985 Phone phone = getPhone(subId);
9986 if (phone == null) {
9987 return false;
9988 }
9989 final long identity = Binder.clearCallingIdentity();
9990 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009991 UiccPort uiccPort = phone.getUiccPort();
9992 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009993 return false;
9994 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009995 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009996 if (uiccProfile == null) {
9997 return false;
9998 }
9999 if (TelephonyManager.APPTYPE_SIM <= appType
10000 && appType <= TelephonyManager.APPTYPE_ISIM) {
10001 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10002 }
10003 return false;
10004 } finally {
10005 Binder.restoreCallingIdentity(identity);
10006 }
10007 }
10008
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010009 /**
chen xub4baa772019-04-03 10:23:41 -070010010 * Get whether making changes to modem configurations will trigger reboot.
10011 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010012 */
10013 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010014 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10015 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010016 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010017 mApp, subId, callingPackage, callingFeatureId,
10018 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010019 return false;
10020 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010021 final long identity = Binder.clearCallingIdentity();
10022 try {
10023 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10024 } finally {
10025 Binder.restoreCallingIdentity(identity);
10026 }
10027 }
10028
Nathan Harold29f5f052019-02-15 13:41:57 -080010029 private void updateModemStateMetrics() {
10030 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10031 // TODO: check the state for each modem if the api is ready.
10032 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10033 }
10034
Pengquan Meng3889a572019-01-23 11:16:29 -080010035 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010036 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010037 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010038 // Verify that the callingPackage belongs to the calling UID
10039 mApp.getSystemService(AppOpsManager.class)
10040 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010041 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010042 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010043 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010044 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10045 if (slotInfos != null) {
10046 for (int i = 0; i < slotInfos.length; i++) {
10047 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10048 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10049 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10050 portInfo.getLogicalSlotIndex()));
10051 }
10052 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010053 }
10054 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010055 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010056 } finally {
10057 Binder.restoreCallingIdentity(identity);
10058 }
10059 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010060
10061 /**
10062 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010063 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010064 */
jimsunf9ec1622022-09-13 21:18:43 +080010065 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010066 @Override
10067 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010068 return getHalVersion(HAL_SERVICE_RADIO);
10069 }
10070
10071 /**
10072 * Get the HAL Version of a specific service
10073 */
10074 @Override
10075 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010076 Phone phone = getDefaultPhone();
10077 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010078 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010079 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10080 return hv.major * 100 + hv.minor;
10081 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010082
10083 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010084 * Get the current calling package name.
10085 * @return the current calling package name
10086 */
10087 @Override
10088 public String getCurrentPackageName() {
10089 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10090 }
10091
10092 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010093 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10094 * corresponding network requests on a subId.
10095 *
10096 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010097 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010098 * 2) APN is un-metered for this subscription, or
10099 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010100 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010101 *
10102 * @return whether data is allowed for a apn type.
10103 *
10104 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010105 */
10106 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010107 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010108 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10109 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010110
10111 // Now that all security checks passes, perform the operation as ourselves.
10112 final long identity = Binder.clearCallingIdentity();
10113 try {
10114 Phone phone = getPhone(subId);
10115 if (phone == null) return false;
10116
Jack Yu27422a52022-03-21 10:38:05 -070010117 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010118 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010119 isMetered = phone.getDataNetworkController().getDataConfigManager()
10120 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10121 phone.getServiceState().getDataRoaming());
10122 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010123 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010124 } finally {
10125 Binder.restoreCallingIdentity(identity);
10126 }
10127 }
10128
10129 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010130 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010131 enforceReadPrivilegedPermission("isApnMetered");
10132
10133 // Now that all security checks passes, perform the operation as ourselves.
10134 final long identity = Binder.clearCallingIdentity();
10135 try {
10136 Phone phone = getPhone(subId);
10137 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010138 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10139 DataUtils.apnTypeToNetworkCapability(apnType),
10140 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010141 } finally {
10142 Binder.restoreCallingIdentity(identity);
10143 }
10144 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010145
10146 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010147 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10148 int subscriptionId, IBooleanConsumer resultCallback) {
10149 enforceModifyPermission();
10150 long token = Binder.clearCallingIdentity();
10151 try {
10152 Phone phone = getPhone(subscriptionId);
10153 if (phone == null) {
10154 try {
10155 if (resultCallback != null) {
10156 resultCallback.accept(false);
10157 }
10158 } catch (RemoteException e) {
10159 // ignore
10160 }
10161 return;
10162 }
10163 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10164 Pair.create(specifiers, (x) -> {
10165 try {
10166 if (resultCallback != null) {
10167 resultCallback.accept(x);
10168 }
10169 } catch (RemoteException e) {
10170 // ignore
10171 }
10172 });
10173 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10174 } finally {
10175 Binder.restoreCallingIdentity(token);
10176 }
10177 }
10178
10179 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010180 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10181 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010182 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010183 mApp, subId, "getSystemSelectionChannels");
10184 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10185 final long identity = Binder.clearCallingIdentity();
10186 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010187 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10188 if (result instanceof IllegalStateException) {
10189 throw (IllegalStateException) result;
10190 }
10191 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010192 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10193 return specifiers;
10194 } finally {
10195 Binder.restoreCallingIdentity(identity);
10196 }
10197 }
10198
10199 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010200 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010201 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010202 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010203 }
10204
10205 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010206 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10207 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010208 if (callingPackage == null) {
10209 callingPackage = getCurrentPackageName();
10210 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010211 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10212 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010213 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10214 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010215 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10216 }
10217 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10218 Intent intent = new Intent();
10219 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10220 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10221 // Bring up choose default SMS subscription dialog right now
10222 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10223 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10224 mApp.startActivity(intent);
10225 }
chen xud5ca2d52019-05-28 15:20:57 -070010226
10227 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010228 public void showSwitchToManagedProfileDialog() {
10229 enforceModifyPermission();
10230
10231 Intent intent = new Intent();
10232 intent.setClass(mApp, ErrorDialogActivity.class);
10233 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10234 mApp.startActivity(intent);
10235 }
10236
10237 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010238 public String getMmsUAProfUrl(int subId) {
10239 //TODO investigate if this API should require proper permission check in R b/133791609
10240 final long identity = Binder.clearCallingIdentity();
10241 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010242 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10243 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10244 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10245 return carrierUAProfUrl;
10246 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010247 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10248 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010249 } finally {
10250 Binder.restoreCallingIdentity(identity);
10251 }
10252 }
10253
10254 @Override
10255 public String getMmsUserAgent(int subId) {
10256 //TODO investigate if this API should require proper permission check in R b/133791609
10257 final long identity = Binder.clearCallingIdentity();
10258 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010259 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10260 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10261 if (!TextUtils.isEmpty(carrierUserAgent)) {
10262 return carrierUserAgent;
10263 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010264 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10265 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010266 } finally {
10267 Binder.restoreCallingIdentity(identity);
10268 }
10269 }
Jack Yub07d4972019-05-28 16:12:25 -070010270
10271 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010272 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10273 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010274
Jack Yub07d4972019-05-28 16:12:25 -070010275 final long identity = Binder.clearCallingIdentity();
10276 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010277 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010278 if (phone == null) return false;
10279
Ling Maf188d502022-09-16 15:22:36 -070010280 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010281 } finally {
10282 Binder.restoreCallingIdentity(identity);
10283 }
10284 }
10285
10286 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010287 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010288 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010289 enforceModifyPermission();
10290
changbettyd5c246e2019-12-24 15:40:37 +080010291 final long identity = Binder.clearCallingIdentity();
10292 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010293 Phone phone = getPhone(subscriptionId);
10294 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010295
Ling Maf188d502022-09-16 15:22:36 -070010296 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010297 } finally {
10298 Binder.restoreCallingIdentity(identity);
10299 }
10300 }
10301
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010302 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010303 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010304 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10305 * otherwise.
10306 */
10307 @Override
10308 public void setCepEnabled(boolean isCepEnabled) {
10309 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10310
10311 final long identity = Binder.clearCallingIdentity();
10312 try {
10313 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10314 for (Phone phone : PhoneFactory.getPhones()) {
10315 Phone defaultPhone = phone.getImsPhone();
10316 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10317 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10318 ImsPhoneCallTracker imsPhoneCallTracker =
10319 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10320 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10321 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10322 + imsPhone.getMsisdn());
10323 }
10324 }
10325 } finally {
10326 Binder.restoreCallingIdentity(identity);
10327 }
10328 }
allenwtsu46dcc572020-01-08 18:24:03 +080010329
10330 /**
10331 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10332 *
10333 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10334 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10335 * before being read.
10336 */
10337 @Override
10338 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10339 isCompressed) {
10340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10341 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010342 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10343 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10344 }
10345 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010346 // ProvisioningManager can not handle ServiceSpecificException.
10347 // Throw the IllegalStateException and annotate ProvisioningManager.
10348 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010349 }
10350
10351 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010352 try {
Hui Wang761a6682020-10-31 05:12:53 +000010353 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10354 } finally {
10355 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010356 }
10357 }
zoey chene02881a2019-12-30 16:11:23 +080010358
10359 @Override
10360 public boolean isIccLockEnabled(int subId) {
10361 enforceReadPrivilegedPermission("isIccLockEnabled");
10362
10363 // Now that all security checks passes, perform the operation as ourselves.
10364 final long identity = Binder.clearCallingIdentity();
10365 try {
10366 Phone phone = getPhone(subId);
10367 if (phone != null && phone.getIccCard() != null) {
10368 return phone.getIccCard().getIccLockEnabled();
10369 } else {
10370 return false;
10371 }
10372 } finally {
10373 Binder.restoreCallingIdentity(identity);
10374 }
10375 }
10376
10377 /**
10378 * Set the ICC pin lock enabled or disabled.
10379 *
10380 * @return an integer representing the status of IccLock enabled or disabled in the following
10381 * three cases:
10382 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10383 * successfully.
10384 * - Positive number and zero for remaining password attempts.
10385 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10386 *
10387 */
10388 @Override
10389 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10390 enforceModifyPermission();
10391
10392 Phone phone = getPhone(subId);
10393 if (phone == null) {
10394 return 0;
10395 }
10396 // Now that all security checks passes, perform the operation as ourselves.
10397 final long identity = Binder.clearCallingIdentity();
10398 try {
10399 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10400 new Pair<Boolean, String>(enabled, password), phone, null);
10401 return attemptsRemaining;
10402
10403 } catch (Exception e) {
10404 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10405 } finally {
10406 Binder.restoreCallingIdentity(identity);
10407 }
10408 return 0;
10409 }
10410
10411 /**
10412 * Change the ICC password used in ICC pin lock.
10413 *
10414 * @return an integer representing the status of IccLock changed in the following three cases:
10415 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10416 * - Positive number and zero for remaining password attempts.
10417 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10418 *
10419 */
10420 @Override
10421 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10422 enforceModifyPermission();
10423
10424 Phone phone = getPhone(subId);
10425 if (phone == null) {
10426 return 0;
10427 }
10428 // Now that all security checks passes, perform the operation as ourselves.
10429 final long identity = Binder.clearCallingIdentity();
10430 try {
10431 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10432 new Pair<String, String>(oldPassword, newPassword), phone, null);
10433 return attemptsRemaining;
10434
10435 } catch (Exception e) {
10436 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10437 } finally {
10438 Binder.restoreCallingIdentity(identity);
10439 }
10440 return 0;
10441 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010442
10443 /**
10444 * Request for receiving user activity notification
10445 */
10446 @Override
10447 public void requestUserActivityNotification() {
10448 if (!mNotifyUserActivity.get()
10449 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10450 mNotifyUserActivity.set(true);
10451 }
10452 }
10453
10454 /**
10455 * Called when userActivity is signalled in the power manager.
10456 * This is safe to call from any thread, with any window manager locks held or not.
10457 */
10458 @Override
10459 public void userActivity() {
10460 // ***************************************
10461 // * Inherited from PhoneWindowManager *
10462 // ***************************************
10463 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10464 // WITH ITS LOCKS HELD.
10465 //
10466 // This code must be VERY careful about the locks
10467 // it acquires.
10468 // In fact, the current code acquires way too many,
10469 // and probably has lurking deadlocks.
10470
10471 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10472 throw new SecurityException("Only the OS may call notifyUserActivity()");
10473 }
10474
10475 if (mNotifyUserActivity.getAndSet(false)) {
10476 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10477 USER_ACTIVITY_NOTIFICATION_DELAY);
10478 }
10479 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010480
10481 @Override
10482 public boolean canConnectTo5GInDsdsMode() {
10483 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10484 }
Jack Yud10cdd42020-09-28 20:28:01 -070010485
10486 @Override
10487 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10488 String callingFeatureId) {
10489 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10490 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10491 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10492 }
10493
10494 Phone phone = getPhone(subId);
10495 if (phone == null) {
10496 throw new RuntimeException("phone is not available");
10497 }
10498 // Now that all security checks passes, perform the operation as ourselves.
10499 final long identity = Binder.clearCallingIdentity();
10500 try {
10501 return phone.getEquivalentHomePlmns();
10502 } finally {
10503 Binder.restoreCallingIdentity(identity);
10504 }
10505 }
Daniel Bright59e67312020-11-13 11:49:37 -080010506
10507 @Override
10508 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010509 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10510 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010511 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010512 if (radioInterfaceCapabilities == null) {
10513 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010514 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010515 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010516 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010517
Hui Wang641e81c2020-10-12 12:14:23 -070010518 @Override
10519 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10520 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010521 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10522 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10523 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10524 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10525 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010526 if (DBG) {
10527 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10528 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10529 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10530 }
10531
10532 if (!SubscriptionManager.isValidSubscriptionId(subId)
10533 || appType < TelephonyManager.APPTYPE_UNKNOWN
10534 || appType > TelephonyManager.APPTYPE_ISIM
10535 || nafUrl == null || securityProtocol == null || callback == null) {
10536 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10537 if (callback != null) {
10538 try {
10539 callback.onAuthenticationFailure(
10540 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10541 } catch (RemoteException exception) {
10542 log("Fail to notify onAuthenticationFailure due to " + exception);
10543 }
10544 return;
10545 }
10546 }
10547
10548 final long token = Binder.clearCallingIdentity();
10549 try {
10550 getGbaManager(subId).bootstrapAuthenticationRequest(
10551 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010552 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070010553 } finally {
10554 Binder.restoreCallingIdentity(token);
10555 }
10556 }
10557
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010558 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010559 * Attempts to set the radio power state for all phones for thermal reason.
10560 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010561 * requested radio power state will actually be set. See {@link
10562 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10563 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010564 * @param enable {@code true} if trying to turn radio on.
10565 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10566 * false}.
10567 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010568 private boolean setRadioPowerForThermal(boolean enable) {
10569 boolean isPhoneAvailable = false;
10570 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10571 Phone phone = PhoneFactory.getPhone(i);
10572 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010573 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010574 isPhoneAvailable = true;
10575 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010576 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010577
10578 // return true if successfully informed the phone object about the thermal radio power
10579 // request.
10580 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010581 }
10582
10583 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010584 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010585 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10586 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10587 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10588 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10589 throw new IllegalArgumentException("modem does not support data throttling");
10590 }
10591
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010592 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10593 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010594 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010595 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10596 }
10597
Sarah Chinecc78c42022-03-31 21:16:48 -070010598 setDataEnabledForReason(
10599 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010600
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010601 if (isDataThrottlingSupported) {
10602 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010603 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010604 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10605 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10606 } else if (thermalMitigationResult
10607 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010608 log("Modem likely does not support data throttling on secondary carrier. Data " +
10609 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10610 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010611 }
10612 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010613 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010614
10615 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010616 }
10617
Jack Nudelman644b91a2021-03-12 14:09:48 -080010618 private static List<String> getThermalMitigationAllowlist(Context context) {
10619 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10620 for (String pckg : context.getResources()
10621 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10622 sThermalMitigationAllowlistedPackages.add(pckg);
10623 }
10624 }
10625
10626 return sThermalMitigationAllowlistedPackages;
10627 }
10628
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010629 private boolean isAnyPhoneInEmergencyState() {
10630 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10631 if (tm.isInEmergencyCall()) {
10632 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10633 return true;
10634 }
10635 for (Phone phone : PhoneFactory.getPhones()) {
10636 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10637 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010638 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10639 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010640 return true;
10641 }
10642 }
10643
10644 return false;
10645 }
10646
Jack Nudelman644b91a2021-03-12 14:09:48 -080010647 /**
10648 * Used by shell commands to add an authorized package name for thermal mitigation.
10649 * @param packageName name of package to be allowlisted
10650 * @param context
10651 */
10652 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10653 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10654 sThermalMitigationAllowlistedPackages.add(packageName);
10655 }
10656
10657 /**
10658 * Used by shell commands to remove an authorized package name for thermal mitigation.
10659 * @param packageName name of package to remove from allowlist
10660 * @param context
10661 */
10662 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10663 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10664 sThermalMitigationAllowlistedPackages.remove(packageName);
10665 }
10666
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010667 /**
10668 * Thermal mitigation request to control functionalities at modem.
10669 *
10670 * @param subId the id of the subscription.
10671 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010672 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010673 *
10674 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10675 */
10676 @Override
10677 @ThermalMitigationResult
10678 public int sendThermalMitigationRequest(
10679 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010680 ThermalMitigationRequest thermalMitigationRequest,
10681 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010682 enforceModifyPermission();
10683
Jack Nudelman644b91a2021-03-12 14:09:48 -080010684 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10685 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10686 .contains(callingPackage)) {
10687 throw new SecurityException("Calling package must be configured in the device config. "
10688 + "calling package: " + callingPackage);
10689 }
10690
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010691 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10692 final long identity = Binder.clearCallingIdentity();
10693
10694 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10695 try {
10696 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10697 switch (thermalMitigationAction) {
10698 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10699 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010700 handleDataThrottlingRequest(subId,
10701 thermalMitigationRequest.getDataThrottlingRequest(),
10702 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010703 break;
10704 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10705 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10706 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10707 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10708 }
10709
10710 // Ensure that radio is on. If not able to power on due to phone being
10711 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010712 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010713 thermalMitigationResult =
10714 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10715 break;
10716 }
10717
10718 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010719 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010720 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10721 break;
10722 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10723 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10724 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10725 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10726 }
10727
10728 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10729 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010730 Phone phone = getPhone(subId);
10731 if (phone == null) {
10732 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010733 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010734 break;
10735 }
10736
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010737 TelephonyConnectionService service =
10738 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010739 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010740 Log.e(LOG_TAG, "An emergency call is pending");
10741 thermalMitigationResult =
10742 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10743 break;
10744 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010745 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010746 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010747 break;
10748 }
10749 } else {
10750 thermalMitigationResult =
10751 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10752 break;
10753 }
10754
10755 // Turn radio off. If not able to power off due to phone being unavailable,
10756 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010757 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010758 thermalMitigationResult =
10759 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10760 break;
10761 }
10762 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010763 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010764 break;
10765 default:
10766 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10767 + "not exist. Requested action: " + thermalMitigationAction);
10768 }
10769 } catch (IllegalArgumentException e) {
10770 throw e;
10771 } catch (Exception e) {
10772 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10773 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10774 } finally {
10775 Binder.restoreCallingIdentity(identity);
10776 }
10777
10778 if (DBG) {
10779 log("thermalMitigationRequest returning with thermalMitigationResult: "
10780 + thermalMitigationResult);
10781 }
10782
10783 return thermalMitigationResult;
10784 }
Hui Wang641e81c2020-10-12 12:14:23 -070010785
10786 /**
10787 * Set the GbaService Package Name that Telephony will bind to.
10788 *
10789 * @param subId The sim that the GbaService is associated with.
10790 * @param packageName The name of the package to be replaced with.
10791 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10792 */
10793 @Override
10794 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10795 enforceModifyPermission();
10796
10797 final long identity = Binder.clearCallingIdentity();
10798 try {
10799 return getGbaManager(subId).overrideServicePackage(packageName);
10800 } finally {
10801 Binder.restoreCallingIdentity(identity);
10802 }
10803 }
10804
10805 /**
10806 * Return the package name of the currently bound GbaService.
10807 *
10808 * @param subId The sim that the GbaService is associated with.
10809 * @return the package name of the GbaService configuration, null if GBA is not supported.
10810 */
10811 @Override
10812 public String getBoundGbaService(int subId) {
10813 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10814
10815 final long identity = Binder.clearCallingIdentity();
10816 try {
10817 return getGbaManager(subId).getServicePackage();
10818 } finally {
10819 Binder.restoreCallingIdentity(identity);
10820 }
10821 }
10822
10823 /**
10824 * Set the release time for telephony to unbind GbaService.
10825 *
10826 * @param subId The sim that the GbaService is associated with.
10827 * @param interval The release time to unbind GbaService by millisecond.
10828 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10829 */
10830 @Override
10831 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10832 enforceModifyPermission();
10833
10834 final long identity = Binder.clearCallingIdentity();
10835 try {
10836 return getGbaManager(subId).overrideReleaseTime(interval);
10837 } finally {
10838 Binder.restoreCallingIdentity(identity);
10839 }
10840 }
10841
10842 /**
10843 * Return the release time for telephony to unbind GbaService.
10844 *
10845 * @param subId The sim that the GbaService is associated with.
10846 * @return The release time to unbind GbaService by millisecond.
10847 */
10848 @Override
10849 public int getGbaReleaseTime(int subId) {
10850 enforceReadPrivilegedPermission("getGbaReleaseTime");
10851
10852 final long identity = Binder.clearCallingIdentity();
10853 try {
10854 return getGbaManager(subId).getReleaseTime();
10855 } finally {
10856 Binder.restoreCallingIdentity(identity);
10857 }
10858 }
10859
10860 private GbaManager getGbaManager(int subId) {
10861 GbaManager instance = GbaManager.getInstance(subId);
10862 if (instance == null) {
10863 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10864 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10865 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10866 }
10867 return instance;
10868 }
Hui Wang761a6682020-10-31 05:12:53 +000010869
10870 /**
10871 * indicate whether the device and the carrier can support
10872 * RCS VoLTE single registration.
10873 */
10874 @Override
10875 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010876 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10877 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10878 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10879 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010880
10881 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10882 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10883 }
10884
10885 final long identity = Binder.clearCallingIdentity();
10886 try {
10887 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10888 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010889 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10890 if (isCapable != null) {
10891 return isCapable;
10892 }
Hui Wang761a6682020-10-31 05:12:53 +000010893 }
Hui Wang67af90e2021-06-04 16:57:15 -070010894 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10895 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010896 } finally {
10897 Binder.restoreCallingIdentity(identity);
10898 }
10899 }
10900
10901 /**
10902 * Register RCS provisioning callback.
10903 */
10904 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010905 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010906 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010907 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010908 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010909 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10910 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010911
10912 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10913 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10914 }
10915 if (!isImsAvailableOnDevice()) {
10916 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10917 "IMS not available on device.");
10918 }
10919
10920 final long identity = Binder.clearCallingIdentity();
10921 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010922 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010923 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010924 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10925 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010926 }
Hui Wang761a6682020-10-31 05:12:53 +000010927 } finally {
10928 Binder.restoreCallingIdentity(identity);
10929 }
10930 }
10931
10932 /**
10933 * Unregister RCS provisioning callback.
10934 */
10935 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010936 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010937 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010938 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010939 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010940 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10941 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010942
10943 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10944 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10945 }
10946 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010947 // operation failed silently
10948 Rlog.w(LOG_TAG, "IMS not available on device.");
10949 return;
Hui Wang761a6682020-10-31 05:12:53 +000010950 }
10951
10952 final long identity = Binder.clearCallingIdentity();
10953 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010954 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010955 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010956 } finally {
10957 Binder.restoreCallingIdentity(identity);
10958 }
10959 }
10960
10961 /**
10962 * trigger RCS reconfiguration.
10963 */
10964 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010965 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10966 "triggerRcsReconfiguration",
10967 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010968
10969 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10970 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10971 }
10972 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010973 // ProvisioningManager can not handle ServiceSpecificException.
10974 // Throw the IllegalStateException and annotate ProvisioningManager.
10975 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010976 }
10977
10978 final long identity = Binder.clearCallingIdentity();
10979 try {
10980 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10981 } finally {
10982 Binder.restoreCallingIdentity(identity);
10983 }
10984 }
10985
10986 /**
10987 * Provide the client configuration parameters of the RCS application.
10988 */
10989 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010990 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10991 "setRcsClientConfiguration",
10992 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010993
10994 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10995 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10996 }
10997 if (!isImsAvailableOnDevice()) {
10998 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10999 "IMS not available on device.");
11000 }
11001
11002 final long identity = Binder.clearCallingIdentity();
11003
11004 try {
11005 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11006 if (configBinder == null) {
11007 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011008 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11009 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011010 } else {
11011 configBinder.setRcsClientConfiguration(rcc);
11012 }
joonhunshin3e154242021-09-17 06:33:39 +000011013
11014 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11015 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011016 } catch (RemoteException e) {
11017 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011018 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11019 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011020 } finally {
11021 Binder.restoreCallingIdentity(identity);
11022 }
11023 }
11024
11025 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011026 * Enables or disables the test mode for RCS VoLTE single registration.
11027 */
11028 @Override
11029 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11030 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11031 "setRcsSingleRegistrationTestModeEnabled");
11032
11033 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11034 }
11035
11036 /**
11037 * Gets the test mode for RCS VoLTE single registration.
11038 */
11039 @Override
11040 public boolean getRcsSingleRegistrationTestModeEnabled() {
11041 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11042 "getRcsSingleRegistrationTestModeEnabled");
11043
11044 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11045 }
11046
11047 /**
Hui Wang761a6682020-10-31 05:12:53 +000011048 * Overrides the config of RCS VoLTE single registration enabled for the device.
11049 */
11050 @Override
11051 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11052 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11053 "setDeviceSingleRegistrationEnabledOverride");
11054 enforceModifyPermission();
11055
11056 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11057 : Boolean.parseBoolean(enabledStr);
11058 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011059 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011060 }
11061
11062 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011063 * Sends a device to device communication message. Only usable via shell.
11064 * @param message message to send.
11065 * @param value message value.
11066 */
11067 @Override
11068 public void sendDeviceToDeviceMessage(int message, int value) {
11069 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011070 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011071 enforceModifyPermission();
11072
11073 final long identity = Binder.clearCallingIdentity();
11074 try {
11075 TelephonyConnectionService service =
11076 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11077 if (service == null) {
11078 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11079 return;
11080 }
11081 service.sendTestDeviceToDeviceMessage(message, value);
11082 } finally {
11083 Binder.restoreCallingIdentity(identity);
11084 }
11085 }
11086
Tyler Gunnbabbda02021-02-10 11:05:02 -080011087 /**
11088 * Sets the specified device to device transport active.
11089 * @param transport The transport to set active.
11090 */
11091 @Override
11092 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11093 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11094 "setActiveDeviceToDeviceTransport");
11095 enforceModifyPermission();
11096
11097 final long identity = Binder.clearCallingIdentity();
11098 try {
11099 TelephonyConnectionService service =
11100 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11101 if (service == null) {
11102 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11103 return;
11104 }
11105 service.setActiveDeviceToDeviceTransport(transport);
11106 } finally {
11107 Binder.restoreCallingIdentity(identity);
11108 }
11109 }
Tyler Gunn92479152021-01-20 16:30:10 -080011110
Tyler Gunnd4339262021-05-03 14:46:49 -070011111 @Override
11112 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11113 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11114 "setDeviceToDeviceForceEnabled");
11115
11116 final long identity = Binder.clearCallingIdentity();
11117 try {
11118 Arrays.stream(PhoneFactory.getPhones()).forEach(
11119 p -> {
11120 Phone thePhone = p.getImsPhone();
11121 if (thePhone != null && thePhone instanceof ImsPhone) {
11122 ImsPhone imsPhone = (ImsPhone) thePhone;
11123 CallTracker tracker = imsPhone.getCallTracker();
11124 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11125 ImsPhoneCallTracker imsPhoneCallTracker =
11126 (ImsPhoneCallTracker) tracker;
11127 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11128 }
11129 }
11130 }
11131 );
11132 } finally {
11133 Binder.restoreCallingIdentity(identity);
11134 }
11135 }
11136
Tyler Gunn92479152021-01-20 16:30:10 -080011137 /**
Hui Wang761a6682020-10-31 05:12:53 +000011138 * Gets the config of RCS VoLTE single registration enabled for the device.
11139 */
11140 @Override
11141 public boolean getDeviceSingleRegistrationEnabled() {
11142 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11143 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11144 }
11145
11146 /**
11147 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11148 */
11149 @Override
11150 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11151 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11152 "setCarrierSingleRegistrationEnabledOverride");
11153 enforceModifyPermission();
11154
11155 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11156 : Boolean.parseBoolean(enabledStr);
11157 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11158 subId, enabled);
11159 }
11160
11161 /**
11162 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11163 */
11164 @Override
11165 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11166 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11167 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11168 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011169
11170 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011171 * Overrides the ims feature validation result
11172 */
11173 @Override
11174 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11175 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11176 "setImsFeatureValidationOverride");
11177
11178 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11179 : Boolean.parseBoolean(enabledStr);
11180 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11181 subId, enabled);
11182 }
11183
11184 /**
11185 * Gets the ims feature validation override value
11186 */
11187 @Override
11188 public boolean getImsFeatureValidationOverride(int subId) {
11189 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11190 "getImsFeatureValidationOverride");
11191 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11192 }
11193
11194 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011195 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11196 * their mobile plan.
11197 */
11198 @Override
11199 public String getMobileProvisioningUrl() {
11200 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11201 final long identity = Binder.clearCallingIdentity();
11202 try {
11203 return getDefaultPhone().getMobileProvisioningUrl();
11204 } finally {
11205 Binder.restoreCallingIdentity(identity);
11206 }
11207 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011208
James.cf Linbcdf8b32021-01-14 16:44:13 +080011209 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011210 * Get the EAB contact from the EAB database.
11211 */
11212 @Override
11213 public String getContactFromEab(String contact) {
11214 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11215 enforceModifyPermission();
11216 final long identity = Binder.clearCallingIdentity();
11217 try {
11218 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11219 } finally {
11220 Binder.restoreCallingIdentity(identity);
11221 }
11222 }
11223
11224 /**
Calvin Pana1434322021-07-01 19:27:01 +080011225 * Get the EAB capability from the EAB database.
11226 */
11227 @Override
11228 public String getCapabilityFromEab(String contact) {
11229 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11230 enforceModifyPermission();
11231 final long identity = Binder.clearCallingIdentity();
11232 try {
11233 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11234 } finally {
11235 Binder.restoreCallingIdentity(identity);
11236 }
11237 }
11238
11239 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011240 * Remove the EAB contacts from the EAB database.
11241 */
11242 @Override
11243 public int removeContactFromEab(int subId, String contacts) {
11244 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11245 enforceModifyPermission();
11246 final long identity = Binder.clearCallingIdentity();
11247 try {
11248 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11249 } finally {
11250 Binder.restoreCallingIdentity(identity);
11251 }
11252 }
11253
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011254 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011255 public boolean getDeviceUceEnabled() {
11256 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11257 final long identity = Binder.clearCallingIdentity();
11258 try {
11259 return mApp.getDeviceUceEnabled();
11260 } finally {
11261 Binder.restoreCallingIdentity(identity);
11262 }
11263 }
11264
11265 @Override
11266 public void setDeviceUceEnabled(boolean isEnabled) {
11267 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11268 final long identity = Binder.clearCallingIdentity();
11269 try {
11270 mApp.setDeviceUceEnabled(isEnabled);
11271 } finally {
11272 Binder.restoreCallingIdentity(identity);
11273 }
11274 }
11275
Brad Ebinger14d467f2021-02-12 06:18:28 +000011276 /**
11277 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11278 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11279 */
11280 // Used for SHELL command only right now.
11281 @Override
11282 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11283 List<String> featureTags) {
11284 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11285 "addUceRegistrationOverrideShell");
11286 final long identity = Binder.clearCallingIdentity();
11287 try {
11288 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11289 new ArraySet<>(featureTags));
11290 } catch (ImsException e) {
11291 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11292 } finally {
11293 Binder.restoreCallingIdentity(identity);
11294 }
11295 }
11296
11297 /**
11298 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11299 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11300 */
11301 // Used for SHELL command only right now.
11302 @Override
11303 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11304 List<String> featureTags) {
11305 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11306 "removeUceRegistrationOverrideShell");
11307 final long identity = Binder.clearCallingIdentity();
11308 try {
11309 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11310 new ArraySet<>(featureTags));
11311 } catch (ImsException e) {
11312 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11313 } finally {
11314 Binder.restoreCallingIdentity(identity);
11315 }
11316 }
11317
11318 /**
11319 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11320 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11321 */
11322 // Used for SHELL command only right now.
11323 @Override
11324 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11325 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11326 "clearUceRegistrationOverrideShell");
11327 final long identity = Binder.clearCallingIdentity();
11328 try {
11329 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11330 } catch (ImsException e) {
11331 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11332 } finally {
11333 Binder.restoreCallingIdentity(identity);
11334 }
11335 }
11336
11337 /**
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 getLatestRcsContactUceCapabilityShell(int subId) {
11343 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11344 "getLatestRcsContactUceCapabilityShell");
11345 final long identity = Binder.clearCallingIdentity();
11346 try {
11347 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11348 } catch (ImsException e) {
11349 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11350 } finally {
11351 Binder.restoreCallingIdentity(identity);
11352 }
11353 }
11354
11355 /**
11356 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11357 * device does not have an active PUBLISH.
11358 */
11359 // Used for SHELL command only right now.
11360 @Override
11361 public String getLastUcePidfXmlShell(int subId) {
11362 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11363 final long identity = Binder.clearCallingIdentity();
11364 try {
11365 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11366 } catch (ImsException e) {
11367 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11368 } finally {
11369 Binder.restoreCallingIdentity(identity);
11370 }
11371 }
11372
James.cf Line8713a42021-04-29 16:04:26 +080011373 /**
11374 * Remove UCE requests cannot be sent to the network status.
11375 */
11376 // Used for SHELL command only right now.
11377 @Override
11378 public boolean removeUceRequestDisallowedStatus(int subId) {
11379 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11380 final long identity = Binder.clearCallingIdentity();
11381 try {
11382 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11383 } catch (ImsException e) {
11384 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11385 } finally {
11386 Binder.restoreCallingIdentity(identity);
11387 }
11388 }
11389
James.cf Lin18bb9002021-05-25 01:37:38 +080011390 /**
11391 * Remove UCE requests cannot be sent to the network status.
11392 */
11393 // Used for SHELL command only.
11394 @Override
11395 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11396 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11397 final long identity = Binder.clearCallingIdentity();
11398 try {
11399 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11400 } catch (ImsException e) {
11401 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11402 } finally {
11403 Binder.restoreCallingIdentity(identity);
11404 }
11405 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011406
James.cf Lin4b784aa2021-01-31 03:25:15 +080011407 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011408 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11409 String callingPackage) {
11410 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11411 mApp, subId, "setSignalStrengthUpdateRequest");
11412
11413 final int callingUid = Binder.getCallingUid();
11414 // Verify that tha callingPackage belongs to the calling UID
11415 mApp.getSystemService(AppOpsManager.class)
11416 .checkPackage(callingUid, callingPackage);
11417
Rambo Wang3607f502021-02-01 21:51:40 -080011418 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011419
11420 final long identity = Binder.clearCallingIdentity();
11421 try {
11422 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11423 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11424
11425 if (result instanceof IllegalStateException) {
11426 throw (IllegalStateException) result;
11427 }
11428 } finally {
11429 Binder.restoreCallingIdentity(identity);
11430 }
11431 }
11432
11433 @Override
11434 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11435 String callingPackage) {
11436 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11437 mApp, subId, "clearSignalStrengthUpdateRequest");
11438
11439 final int callingUid = Binder.getCallingUid();
11440 // Verify that tha callingPackage belongs to the calling UID
11441 mApp.getSystemService(AppOpsManager.class)
11442 .checkPackage(callingUid, callingPackage);
11443
11444 final long identity = Binder.clearCallingIdentity();
11445 try {
11446 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11447 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11448
11449 if (result instanceof IllegalStateException) {
11450 throw (IllegalStateException) result;
11451 }
11452 } finally {
11453 Binder.restoreCallingIdentity(identity);
11454 }
11455 }
11456
Rambo Wang3607f502021-02-01 21:51:40 -080011457 private static void validateSignalStrengthUpdateRequest(Context context,
11458 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011459 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11460 // phone/system process do not have further restriction on request
11461 return;
11462 }
11463
11464 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011465 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011466 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011467 context.enforceCallingOrSelfPermission(
11468 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11469 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011470 }
11471
11472 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011473 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011474 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011475 || info.isEnabled()) {
11476 throw new IllegalArgumentException(
11477 "Only system can set hide fields in SignalThresholdInfo");
11478 }
11479
11480 // Thresholds length for each RAN need in range. This has been validated in
11481 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11482 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11483 final int[] thresholds = info.getThresholds();
11484 Objects.requireNonNull(thresholds);
11485 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11486 || thresholds.length
11487 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11488 throw new IllegalArgumentException(
11489 "thresholds length is out of range: " + thresholds.length);
11490 }
11491 }
11492 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011493
11494 /**
11495 * Gets the current phone capability.
11496 *
11497 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11498 * @return the PhoneCapability which describes the data connection capability of modem.
11499 * It's used to evaluate possible phone config change, for example from single
11500 * SIM device to multi-SIM device.
11501 */
11502 @Override
11503 public PhoneCapability getPhoneCapability() {
11504 enforceReadPrivilegedPermission("getPhoneCapability");
11505 final long identity = Binder.clearCallingIdentity();
11506 try {
11507 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11508 } finally {
11509 Binder.restoreCallingIdentity(identity);
11510 }
11511 }
Michele Berionne5e411512020-11-13 02:36:59 +000011512
11513 /**
11514 * Prepare TelephonyManager for an unattended reboot. The reboot is
11515 * required to be done shortly after the API is invoked.
11516 */
11517 @Override
11518 @TelephonyManager.PrepareUnattendedRebootResult
11519 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011520 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011521 enforceRebootPermission();
11522
11523 final long identity = Binder.clearCallingIdentity();
11524 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011525 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011526 } finally {
11527 Binder.restoreCallingIdentity(identity);
11528 }
11529 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011530
11531 /**
11532 * Request to get the current slicing configuration including URSP rules and
11533 * NSSAIs (configured, allowed and rejected).
11534 *
11535 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11536 */
11537 @Override
11538 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011539 TelephonyPermissions
11540 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11541 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011542
11543 final long identity = Binder.clearCallingIdentity();
11544 try {
11545 Phone phone = getDefaultPhone();
11546 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11547 } finally {
11548 Binder.restoreCallingIdentity(identity);
11549 }
11550 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011551
11552 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011553 * Check whether the given premium capability is available for purchase from the carrier.
11554 *
11555 * @param capability The premium capability to check.
11556 * @param subId The subId to check the premium capability for.
11557 *
11558 * @return Whether the given premium capability is available to purchase.
11559 */
11560 @Override
11561 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11562 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11563 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11564 log("Premium capability "
11565 + TelephonyManager.convertPremiumCapabilityToString(capability)
11566 + " is not available for purchase due to missing permissions.");
11567 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11568 + "permission READ_BASIC_PHONE_STATE.");
11569 }
11570
11571 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011572 if (phone == null) {
11573 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11574 return false;
11575 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011576 final long identity = Binder.clearCallingIdentity();
11577 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011578 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011579 .isPremiumCapabilityAvailableForPurchase(capability);
11580 } finally {
11581 Binder.restoreCallingIdentity(identity);
11582 }
11583 }
11584
11585 /**
11586 * Purchase the given premium capability from the carrier.
11587 *
11588 * @param capability The premium capability to purchase.
11589 * @param callback The result of the purchase request.
11590 * @param subId The subId to purchase the premium capability for.
11591 */
11592 @Override
11593 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11594 log("purchasePremiumCapability: capability="
11595 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11596 + getCurrentPackageName());
11597
11598 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11599 mApp, "purchasePremiumCapability")) {
11600 log("purchasePremiumCapability "
11601 + TelephonyManager.convertPremiumCapabilityToString(capability)
11602 + " failed due to missing permissions.");
11603 throw new SecurityException("purchasePremiumCapability requires permission "
11604 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011605 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
11606 mApp, "purchasePremiumCapability")) {
11607 log("purchasePremiumCapability "
11608 + TelephonyManager.convertPremiumCapabilityToString(capability)
11609 + " failed due to missing permissions.");
11610 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070011611 }
11612
11613 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011614 if (phone == null) {
11615 try {
11616 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11617 callback.accept(result);
11618 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11619 } catch (RemoteException e) {
11620 String logStr = "Purchase premium capability "
11621 + TelephonyManager.convertPremiumCapabilityToString(capability)
11622 + " failed due to RemoteException handling null phone: " + e;
11623 if (DBG) log(logStr);
11624 AnomalyReporter.reportAnomaly(
11625 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11626 }
11627 return;
11628 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011629
11630 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070011631 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011632 callingProcess = mApp.getPackageManager().getApplicationInfo(
11633 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070011634 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011635 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070011636 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011637
11638 boolean isVisible = false;
11639 ActivityManager am = mApp.getSystemService(ActivityManager.class);
11640 if (am != null) {
11641 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
11642 if (processes != null) {
11643 for (ActivityManager.RunningAppProcessInfo process : processes) {
11644 log("purchasePremiumCapability: process " + process.processName
11645 + "has importance " + process.importance);
11646 if (process.processName.equals(callingProcess) && process.importance
11647 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
11648 isVisible = true;
11649 break;
11650 }
11651 }
11652 }
11653 }
11654
11655 if (!isVisible) {
11656 try {
11657 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
11658 callback.accept(result);
11659 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
11660 } catch (RemoteException e) {
11661 String logStr = "Purchase premium capability "
11662 + TelephonyManager.convertPremiumCapabilityToString(capability)
11663 + " failed due to RemoteException handling background application: " + e;
11664 if (DBG) log(logStr);
11665 AnomalyReporter.reportAnomaly(
11666 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11667 }
11668 return;
11669 }
11670
Sarah Chin71b3a852022-09-28 15:54:19 -070011671 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080011672 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011673 }
11674
11675 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011676 * Register an IMS connection state callback
11677 */
11678 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011679 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11680 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011681 if (feature == ImsFeature.FEATURE_MMTEL) {
11682 // ImsMmTelManager
11683 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11684 TelephonyPermissions
11685 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11686 mApp, subId, "registerImsStateCallback");
11687 } else if (feature == ImsFeature.FEATURE_RCS) {
11688 // ImsRcsManager or SipDelegateManager
11689 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11690 Binder.getCallingUid(), "registerImsStateCallback",
11691 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11692 Manifest.permission.READ_PRECISE_PHONE_STATE,
11693 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11694 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11695 }
11696
11697 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11698 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11699 "IMS not available on device.");
11700 }
11701
11702 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11703 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11704 }
11705
11706 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11707 if (controller == null) {
11708 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11709 "IMS not available on device.");
11710 }
11711
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011712 if (callingPackage == null) {
11713 callingPackage = getCurrentPackageName();
11714 }
11715
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011716 final long token = Binder.clearCallingIdentity();
11717 try {
11718 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011719 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011720 } catch (ImsException e) {
11721 throw new ServiceSpecificException(e.getCode());
11722 } finally {
11723 Binder.restoreCallingIdentity(token);
11724 }
11725 }
11726
11727 /**
11728 * Unregister an IMS connection state callback
11729 */
11730 @Override
11731 public void unregisterImsStateCallback(IImsStateCallback cb) {
11732 final long token = Binder.clearCallingIdentity();
11733 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11734 if (controller == null) {
11735 return;
11736 }
11737 try {
11738 controller.unregisterImsStateCallback(cb);
11739 } finally {
11740 Binder.restoreCallingIdentity(token);
11741 }
11742 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011743
11744 /**
11745 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11746 *
11747 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11748 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11749 * SecurityException.
11750 * If there is current registered network this value will be same as the registered cell
11751 * identity. If the device goes out of service the previous cell identity is cached and
11752 * will be returned. If the cache age of the Cell identity is more than 24 hours
11753 * it will be cleared and null will be returned.
11754 *
11755 */
11756 @Override
11757 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11758 String callingFeatureId) {
11759 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11760 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11761 LocationAccessPolicy.checkLocationPermission(mApp,
11762 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11763 .setCallingPackage(callingPackage)
11764 .setCallingFeatureId(callingFeatureId)
11765 .setCallingPid(Binder.getCallingPid())
11766 .setCallingUid(Binder.getCallingUid())
11767 .setMethod("getLastKnownCellIdentity")
11768 .setLogAsInfo(true)
11769 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11770 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11771 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11772 .build());
11773
11774 boolean hasFinePermission =
11775 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11776 if (!hasFinePermission
11777 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11778 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011779 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011780 }
11781
11782 final long identity = Binder.clearCallingIdentity();
11783 try {
Ling Mac28f0212023-03-24 16:07:15 -070011784 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011785 if (sst == null) return null;
11786 return sst.getLastKnownCellIdentity();
11787 } finally {
11788 Binder.restoreCallingIdentity(identity);
11789 }
11790 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011791
jimsun3b9ccac2021-10-26 15:01:23 +080011792 /**
11793 * Sets the modem service class Name that Telephony will bind to.
11794 *
11795 * @param serviceName The class name of the modem service.
11796 * @return true if the operation is succeed, otherwise false.
11797 */
11798 public boolean setModemService(String serviceName) {
11799 Log.d(LOG_TAG, "setModemService - " + serviceName);
11800 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11801 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011802 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11803 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080011804 return mPhoneConfigurationManager.setModemService(serviceName);
11805 }
11806
11807 /**
11808 * Return the class name of the currently bounded modem service.
11809 *
11810 * @return the class name of the modem service.
11811 */
11812 public String getModemService() {
11813 String result;
11814 Log.d(LOG_TAG, "getModemService");
11815 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11816 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011817 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080011818 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11819 "getModemService");
11820 result = mPhoneConfigurationManager.getModemService();
11821 Log.d(LOG_TAG, "result = " + result);
11822 return result;
11823 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011824
11825 @Override
11826 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11827 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11828 mApp.enforceCallingOrSelfPermission(
11829 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11830 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11831
11832 final long identity = Binder.clearCallingIdentity();
11833 try {
11834 Phone phone = getPhone(subId);
11835 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080011836 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
11837 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011838 phone.setVoiceServiceStateOverride(hasService);
11839 } finally {
11840 Binder.restoreCallingIdentity(identity);
11841 }
11842 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011843
11844 /**
11845 * set removable eSIM as default eUICC.
11846 *
11847 * @hide
11848 */
11849 @Override
11850 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11851 enforceModifyPermission();
11852 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11853
11854 final long identity = Binder.clearCallingIdentity();
11855 try {
11856 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11857 } finally {
11858 Binder.restoreCallingIdentity(identity);
11859 }
11860 }
11861
11862 /**
11863 * Returns whether the removable eSIM is default eUICC or not.
11864 *
11865 * @hide
11866 */
11867 @Override
11868 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11869 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11870 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11871
11872 final long identity = Binder.clearCallingIdentity();
11873 try {
11874 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11875 } finally {
11876 Binder.restoreCallingIdentity(identity);
11877 }
11878 }
11879
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011880 /**
11881 * Get the component name of the default app to direct respond-via-message intent for the
11882 * user associated with this subscription, update the cache if there is no respond-via-message
11883 * application currently configured for this user.
11884 * @return component name of the app and class to direct Respond Via Message intent to, or
11885 * {@code null} if the functionality is not supported.
11886 * @hide
11887 */
11888 @Override
11889 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11890 boolean updateIfNeeded) {
11891 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011892
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000011893 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
11894
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011895 UserHandle userHandle = null;
11896 final long identity = Binder.clearCallingIdentity();
11897 try {
11898 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11899 } finally {
11900 Binder.restoreCallingIdentity(identity);
11901 }
11902 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11903 updateIfNeeded, userHandle);
11904 }
Jack Yuf5badd92022-12-08 00:50:53 -080011905
11906 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011907 * Set whether the device is able to connect with null ciphering or integrity
11908 * algorithms. This is a global setting and will apply to all active subscriptions
11909 * and all new subscriptions after this.
11910 *
11911 * @param enabled when true, null cipher and integrity algorithms are allowed.
11912 * @hide
11913 */
11914 @Override
11915 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11916 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11917 enforceModifyPermission();
11918 checkForNullCipherAndIntegritySupport();
11919
11920 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11921 // for listening to these preference changes and applying them immediately.
11922 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11923 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11924 editor.apply();
11925
11926 for (Phone phone: PhoneFactory.getPhones()) {
11927 phone.handleNullCipherEnabledChange();
11928 }
11929 }
11930
11931
11932 /**
11933 * Get whether the device is able to connect with null ciphering or integrity
11934 * algorithms. Note that this retrieves the phone-global preference and not
11935 * the state of the radio.
11936 *
11937 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11938 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11939 * version for this feature.
11940 * @hide
11941 */
11942 @Override
11943 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11944 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11945 enforceReadPermission();
11946 checkForNullCipherAndIntegritySupport();
11947 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11948 }
11949
11950 private void checkForNullCipherAndIntegritySupport() {
11951 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11952 throw new UnsupportedOperationException(
11953 "Null cipher and integrity operations require HAL 2.1 or above");
11954 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000011955 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
11956 throw new UnsupportedOperationException(
11957 "Null cipher and integrity operations unsupported by modem");
11958 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011959 }
11960
11961 /**
Jack Yuf5badd92022-12-08 00:50:53 -080011962 * Get the SIM state for the slot index.
11963 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11964 *
11965 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11966 */
11967 @Override
11968 @SimState
11969 public int getSimStateForSlotIndex(int slotIndex) {
11970 IccCardConstants.State simState;
11971 if (slotIndex < 0) {
11972 simState = IccCardConstants.State.UNKNOWN;
11973 } else {
11974 Phone phone = null;
11975 try {
11976 phone = PhoneFactory.getPhone(slotIndex);
11977 } catch (IllegalStateException e) {
11978 // ignore
11979 }
11980 if (phone == null) {
11981 simState = IccCardConstants.State.UNKNOWN;
11982 } else {
11983 IccCard icc = phone.getIccCard();
11984 if (icc == null) {
11985 simState = IccCardConstants.State.UNKNOWN;
11986 } else {
11987 simState = icc.getState();
11988 }
11989 }
11990 }
11991 return simState.ordinal();
11992 }
Hui Wang9b5793a2022-12-05 14:38:06 -060011993
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080011994 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
11995 boolean enableLogcat,
11996 long logcatStartTimestampMillis, boolean enableTelecomDump,
11997 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080011998 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
11999 TelephonyManager.EmergencyCallDiagnosticParams edp =
12000 new TelephonyManager.EmergencyCallDiagnosticParams();
12001 edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis);
12002 edp.setTelephonyDumpSysCollection(enableTelephonyDump);
12003 edp.setTelecomDumpSysCollection(enableTelecomDump);
12004 Log.d(LOG_TAG, "persisting with Params " + edp.toString());
12005 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12006 Executors.newCachedThreadPool(), db,
12007 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
12008 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012009 }
12010
12011 /**
12012 * Request telephony to persist state for debugging emergency call failures.
12013 *
12014 * @param dropBoxTag Tag to use when persisting data to dropbox service.
12015 * @param enableLogcat whether to collect logcat output
12016 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12017 * @param enableTelecomDump whether to collect telecom dumpsys
12018 * @param enableTelephonyDump whether to collect telephony dumpsys
12019 */
12020 @Override
12021 @RequiresPermission(android.Manifest.permission.DUMP)
12022 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12023 long logcatStartTimestampMillis, boolean enableTelecomDump,
12024 boolean enableTelephonyDump) {
12025 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12026 "persistEmergencyCallDiagnosticData");
12027 final long identity = Binder.clearCallingIdentity();
12028 try {
12029 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12030 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12031
12032 } finally {
12033 Binder.restoreCallingIdentity(identity);
12034 }
12035 }
12036
Hui Wang9b5793a2022-12-05 14:38:06 -060012037 /**
12038 * Get current cell broadcast ranges.
12039 */
12040 @Override
12041 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12042 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12043 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12044 "getCellBroadcastIdRanges");
12045 final long identity = Binder.clearCallingIdentity();
12046 try {
12047 return getPhone(subId).getCellBroadcastIdRanges();
12048 } finally {
12049 Binder.restoreCallingIdentity(identity);
12050 }
12051 }
12052
12053 /**
12054 * Set reception of cell broadcast messages with the list of the given ranges
12055 *
12056 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12057 */
12058 @Override
12059 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12060 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12061 @Nullable IIntegerConsumer callback) {
12062 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12063 "setCellBroadcastIdRanges");
12064 final long identity = Binder.clearCallingIdentity();
12065 try {
12066 Phone phone = getPhoneFromSubId(subId);
12067 if (DBG) {
12068 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12069 }
12070 phone.setCellBroadcastIdRanges(ranges, result -> {
12071 if (callback != null) {
12072 try {
12073 callback.accept(result);
12074 } catch (RemoteException e) {
12075 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12076 }
12077 }
12078 });
12079 } finally {
12080 Binder.restoreCallingIdentity(identity);
12081 }
12082 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012083
12084 /**
12085 * Returns whether the device supports the domain selection service.
12086 *
12087 * @return {@code true} if the device supports the domain selection service.
12088 */
12089 @Override
12090 public boolean isDomainSelectionSupported() {
12091 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12092 "isDomainSelectionSupported");
12093
12094 final long identity = Binder.clearCallingIdentity();
12095 try {
12096 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12097 } finally {
12098 Binder.restoreCallingIdentity(identity);
12099 }
12100 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012101
12102 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012103 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12104 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12105 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012106 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012107 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012108 * @param enableSatellite {@code true} to enable the satellite modem and
12109 * {@code false} to disable.
12110 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
12111 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012112 *
12113 * @throws SecurityException if the caller doesn't have the required permission.
12114 */
12115 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012116 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
12117 @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012118 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Sarah Chinabf081b2023-03-09 23:00:57 -080012119 mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode,
12120 callback);
Sarah Chin503828c2023-02-01 23:54:20 -080012121 }
12122
12123 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012124 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012125 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012126 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012127 * @param result The result receiver that returns whether the satellite modem is enabled
12128 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012129 *
12130 * @throws SecurityException if the caller doesn't have the required permission.
12131 */
12132 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012133 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12134 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012135 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012136 }
12137
12138 /**
Sarah Chin43457982023-02-15 17:50:38 -080012139 * Request to get whether the satellite service demo mode is enabled.
12140 *
12141 * @param subId The subId of the subscription to check whether the satellite demo mode
12142 * is enabled for.
12143 * @param result The result receiver that returns whether the satellite demo mode is enabled
12144 * if the request is successful or an error code if the request failed.
12145 *
12146 * @throws SecurityException if the caller doesn't have the required permission.
12147 */
12148 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012149 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
12150 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
12151 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080012152 }
12153
12154 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012155 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012156 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012157 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012158 * @param result The result receiver that returns whether the satellite service is supported on
12159 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012160 */
12161 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012162 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012163 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012164 }
12165
12166 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012167 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012168 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012169 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012170 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12171 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012172 *
12173 * @throws SecurityException if the caller doesn't have required permission.
12174 */
12175 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012176 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12177 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012178 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012179 }
12180
12181 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012182 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012183 * This can be called by the pointing UI when the user starts pointing to the satellite.
12184 * Modem should continue to report the pointing input as the device or satellite moves.
12185 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012186 * @param subId The subId of the subscription to start satellite transmission updates for.
12187 * @param resultCallback The callback to get the result of the request.
12188 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080012189 *
12190 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012191 */
12192 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012193 public void startSatelliteTransmissionUpdates(int subId,
12194 @NonNull IIntegerConsumer resultCallback,
12195 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12196 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
12197 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080012198 }
12199
12200 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012201 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012202 * This can be called by the pointing UI when the user stops pointing to the satellite.
12203 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012204 * @param subId The subId of the subscription to stop satellite transmission updates for.
12205 * @param resultCallback The callback to get the result of the request.
12206 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
12207 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080012208 *
12209 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012210 */
12211 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012212 public void stopSatelliteTransmissionUpdates(int subId,
12213 @NonNull IIntegerConsumer resultCallback,
12214 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12215 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
12216 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012217 }
12218
12219 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012220 * Register the subscription with a satellite provider.
12221 * This is needed to register the subscription if the provider allows dynamic registration.
12222 *
12223 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012224 * @param token The token to be used as a unique identifier for provisioning with satellite
12225 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012226 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080012227 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012228 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012229 * @return The signal transport used by the caller to cancel the provision request,
12230 * or {@code null} if the request failed.
12231 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012232 * @throws SecurityException if the caller doesn't have the required permission.
12233 */
12234 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012235 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012236 @NonNull String token, @NonNull byte[] provisionData,
12237 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012238 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012239 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
12240 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012241 }
12242
12243 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012244 * Unregister the device/subscription with the satellite provider.
12245 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012246 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012247 * should report as deprovisioned.
12248 *
12249 * @param subId The subId of the subscription to be deprovisioned.
12250 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080012251 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012252 *
12253 * @throws SecurityException if the caller doesn't have the required permission.
12254 */
12255 @Override
12256 public void deprovisionSatelliteService(int subId,
12257 @NonNull String token, @NonNull IIntegerConsumer callback) {
12258 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012259 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012260 }
12261
12262 /**
Sarah Chin43457982023-02-15 17:50:38 -080012263 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012264 *
Sarah Chin43457982023-02-15 17:50:38 -080012265 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012266 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012267 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012268 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12269 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012270 * @throws SecurityException if the caller doesn't have the required permission.
12271 */
12272 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080012273 @SatelliteManager.SatelliteError public int registerForSatelliteProvisionStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012274 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012275 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012276 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012277 }
12278
12279 /**
Sarah Chin43457982023-02-15 17:50:38 -080012280 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012281 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012282 *
Sarah Chin43457982023-02-15 17:50:38 -080012283 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012284 * @param callback The callback that was passed to
12285 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012286 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012287 * @throws SecurityException if the caller doesn't have the required permission.
12288 */
12289 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012290 public void unregisterForSatelliteProvisionStateChanged(
12291 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012292 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012293 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012294 }
12295
12296 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012297 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012298 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012299 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012300 * @param result The result receiver that returns whether the device is provisioned with a
12301 * satellite provider if the request is successful or an error code if the
12302 * request failed.
12303 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012304 * @throws SecurityException if the caller doesn't have the required permission.
12305 */
12306 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012307 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
12308 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012309 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012310 }
12311
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012312 /**
Sarah Chin43457982023-02-15 17:50:38 -080012313 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012314 *
Sarah Chin43457982023-02-15 17:50:38 -080012315 * @param subId The subId of the subscription to register for satellite modem state changed.
12316 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080012317 *
12318 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12319 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012320 * @throws SecurityException if the caller doesn't have the required permission.
12321 */
12322 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012323 @SatelliteManager.SatelliteError public int registerForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012324 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012325 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012326 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012327 }
12328
12329 /**
Sarah Chin43457982023-02-15 17:50:38 -080012330 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012331 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012332 *
Sarah Chin43457982023-02-15 17:50:38 -080012333 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080012334 * @param callback The callback that was passed to
Sarah Chin43457982023-02-15 17:50:38 -080012335 * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012336 *
12337 * @throws SecurityException if the caller doesn't have the required permission.
12338 */
12339 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012340 public void unregisterForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012341 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012342 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012343 mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012344 }
12345
12346 /**
12347 * Register to receive incoming datagrams over satellite.
12348 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012349 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080012350 * @param callback The callback to handle incoming datagrams over satellite.
12351 *
12352 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12353 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012354 * @throws SecurityException if the caller doesn't have the required permission.
12355 */
12356 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080012357 @SatelliteManager.SatelliteError public int registerForSatelliteDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012358 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012359 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
Sarah Chinabf081b2023-03-09 23:00:57 -080012360 return mSatelliteController.registerForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012361 }
12362
12363 /**
12364 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012365 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012366 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012367 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
12368 * @param callback The callback that was passed to
Sarah Chinabf081b2023-03-09 23:00:57 -080012369 * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012370 *
12371 * @throws SecurityException if the caller doesn't have the required permission.
12372 */
12373 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012374 public void unregisterForSatelliteDatagram(int subId,
12375 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012376 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012377 mSatelliteController.unregisterForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012378 }
12379
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012380 /**
12381 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012382 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012383 * This method requests modem to check if there are any pending datagrams to be received over
12384 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000012385 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080012386 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012387 * @param subId The subId of the subscription used for receiving datagrams.
12388 * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012389 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012390 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012391 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012392 @Override
12393 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012394 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012395 mSatelliteController.pollPendingSatelliteDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012396 }
12397
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012398 /**
12399 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012400 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012401 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
12402 * input to this method. Datagram received here will be passed down to modem without any
12403 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080012404 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012405 * @param subId The subId of the subscription to send satellite datagrams for.
12406 * @param datagramType datagram type indicating whether the datagram is of type
12407 * SOS_SMS or LOCATION_SHARING.
12408 * @param datagram encoded gateway datagram which is encrypted by the caller.
12409 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000012410 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
12411 * full screen mode.
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012412 * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012413 *
12414 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012415 */
12416 @Override
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012417 public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
12418 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
12419 @NonNull IIntegerConsumer callback) {
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012420 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012421 mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram,
12422 needFullScreenPointingUI, callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012423 }
12424
Sarah Chindf715ec2023-02-13 13:46:24 -080012425 /**
12426 * Request to get whether satellite communication is allowed for the current location.
12427 *
12428 * @param subId The subId of the subscription to check whether satellite communication is
12429 * allowed for the current location for.
12430 * @param result The result receiver that returns whether satellite communication is allowed
12431 * for the current location if the request is successful or an error code
12432 * if the request failed.
12433 *
12434 * @throws SecurityException if the caller doesn't have the required permission.
12435 */
12436 @Override
12437 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
12438 @NonNull ResultReceiver result) {
12439 enforceSatelliteCommunicationPermission(
12440 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012441 mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId,
12442 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080012443 }
12444
12445 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012446 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080012447 *
Sarah Chin5f57c582023-02-14 04:16:10 -080012448 * @param subId The subId to get the time after which the satellite will be visible for.
12449 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080012450 * be visible if the request is successful or an error code if the request failed.
12451 *
12452 * @throws SecurityException if the caller doesn't have the required permission.
12453 */
12454 @Override
12455 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
12456 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012457 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012458 }
12459
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012460 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012461 * Inform that Device is aligned to satellite for demo mode.
12462 *
12463 * @param subId The subId to get the time after which the satellite will be visible for.
12464 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
12465 * {@code false} Device fails to align with the satellite for demo mode.
12466 *
12467 * @throws SecurityException if the caller doesn't have required permission.
12468 */
12469 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
12470
12471 public void onDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
12472 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
12473 mSatelliteController.onDeviceAlignedWithSatellite(subId, isAligned);
12474 }
12475
12476 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070012477 * This API can be used by only CTS to update satellite vendor service package name.
12478 *
12479 * @param servicePackageName The package name of the satellite vendor service.
12480 * @return {@code true} if the satellite vendor service is set successfully,
12481 * {@code false} otherwise.
12482 */
12483 public boolean setSatelliteServicePackageName(String servicePackageName) {
12484 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
12485 TelephonyPermissions.enforceShellOnly(
12486 Binder.getCallingUid(), "setSatelliteServicePackageName");
12487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12488 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12489 "setSatelliteServicePackageName");
12490 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
12491 }
12492
12493 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070012494 * This API can be used by only CTS to update satellite gateway service package name.
12495 *
12496 * @param servicePackageName The package name of the satellite gateway service.
12497 * @return {@code true} if the satellite gateway service is set successfully,
12498 * {@code false} otherwise.
12499 */
12500 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
12501 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
12502 TelephonyPermissions.enforceShellOnly(
12503 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
12504 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12505 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12506 "setSatelliteGatewayServicePackageName");
12507 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
12508 }
12509
12510 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070012511 * This API can be used by only CTS to update satellite pointing UI app package and class names.
12512 *
12513 * @param packageName The package name of the satellite pointing UI app.
12514 * @param className The class name of the satellite pointing UI app.
12515 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
12516 * {@code false} otherwise.
12517 */
12518 public boolean setSatellitePointingUiClassName(
12519 @Nullable String packageName, @Nullable String className) {
12520 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
12521 + ", className=" + className);
12522 TelephonyPermissions.enforceShellOnly(
12523 Binder.getCallingUid(), "setSatellitePointingUiClassName");
12524 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12525 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12526 "setSatelliteGatewayServicePackageName");
12527 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
12528 }
12529
12530 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070012531 * This API can be used by only CTS to update the timeout duration in milliseconds that
12532 * satellite should stay at listening mode to wait for the next incoming page before disabling
12533 * listening mode.
12534 *
12535 * @param timeoutMillis The timeout duration in millisecond.
12536 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12537 */
12538 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
12539 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
12540 TelephonyPermissions.enforceShellOnly(
12541 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
12542 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12543 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12544 "setSatelliteListeningTimeoutDuration");
12545 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
12546 }
12547
12548 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012549 * This API can be used by only CTS to update the timeout duration in milliseconds whether
12550 * the device is aligned with the satellite for demo mode
12551 *
12552 * @param timeoutMillis The timeout duration in millisecond.
12553 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12554 */
12555 public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) {
12556 Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis);
12557 TelephonyPermissions.enforceShellOnly(
12558 Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration");
12559 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12560 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12561 "setDeviceAlignedTimeoutDuration");
12562 return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis);
12563 }
12564
12565 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000012566 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
12567 *
12568 * <p>This method behaves in one of the following ways:
12569 * <ul>
12570 * <li>return true : if the calling package has the appop permission {@link
12571 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
12572 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
12573 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
12574 * Owner device identifier access check, or the calling package has carrier privileges</>
12575 * <li>throw SecurityException: if the caller does not meet any of the requirements.
12576 * </ul>
12577 */
12578 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
12579 String callingPackage, @Nullable String callingFeatureId, String message) {
12580 for (Phone phone : PhoneFactory.getPhones()) {
12581 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
12582 phone.getSubId(), callingPackage, callingFeatureId, message)) {
12583 return true;
12584 }
12585 }
12586 return false;
12587 }
arunvoddud7401012022-12-15 16:08:12 +000012588
12589 /**
Jack Yufa8ed012023-02-11 15:42:28 -080012590 * @return The subscription manager service instance.
12591 */
12592 public SubscriptionManagerService getSubscriptionManagerService() {
12593 return SubscriptionManagerService.getInstance();
12594 }
12595
12596 /**
arunvoddud7401012022-12-15 16:08:12 +000012597 * Class binds the consumer[callback] and carrierId.
12598 */
12599 private static class CallerCallbackInfo {
12600 private final Consumer<Integer> mConsumer;
12601 private final int mCarrierId;
12602
12603 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
12604 mConsumer = consumer;
12605 mCarrierId = carrierId;
12606 }
12607
12608 public Consumer<Integer> getConsumer() {
12609 return mConsumer;
12610 }
12611
12612 public int getCarrierId() {
12613 return mCarrierId;
12614 }
12615 }
Jack Yufa8ed012023-02-11 15:42:28 -080012616}