blob: 29c9dc22498fa7a1a0379fb808d7706f0984631a [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000020import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080021import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Hall Liud892bec2018-11-30 14:51:45 -080022
Shuo Qianccbaf742021-02-22 18:32:21 -080023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
24import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070025import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000027import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070028
Brad Ebinger34c09a52021-02-17 23:23:21 +000029import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080030import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080031import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070032import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000033import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080034import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080036import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070037import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000038import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080039import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000040import android.compat.annotation.ChangeId;
41import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070042import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070043import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.content.Context;
45import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070046import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070047import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070048import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.net.Uri;
50import android.os.AsyncResult;
51import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080052import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.Bundle;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080054import android.os.CancellationSignal;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070056import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080057import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080058import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import android.os.Looper;
60import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070061import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080062import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070063import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070064import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080065import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080066import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070067import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070068import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080069import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070071import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070072import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070073import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070074import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080075import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070076import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000077import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090078import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080079import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080080import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070081import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080082import android.telephony.AccessNetworkConstants;
83import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070084import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070085import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080086import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070087import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080088import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070089import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080090import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -060091import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -070092import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080093import android.telephony.CellIdentityCdma;
94import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070096import android.telephony.CellInfoGsm;
97import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070098import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080099import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700100import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700101import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700102import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800103import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700104import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800105import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700106import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800107import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800108import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700109import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800110import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800112import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800113import android.telephony.SignalStrengthUpdateRequest;
114import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800115import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800117import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700118import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700119import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800120import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800121import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800122import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800123import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000124import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000125import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000126import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700127import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700128import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800129import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800130import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700131import android.telephony.gba.GbaAuthRequest;
132import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700133import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800134import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000135import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000136import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700137import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000138import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700139import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800140import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700141import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800142import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700143import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000144import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700145import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800146import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800147import android.telephony.ims.stub.ImsRegistrationImplBase;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800148import android.telephony.satellite.ISatelliteDatagramCallback;
149import android.telephony.satellite.ISatellitePositionUpdateCallback;
150import android.telephony.satellite.ISatelliteProvisionStateCallback;
151import android.telephony.satellite.ISatelliteStateCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800152import android.telephony.satellite.PointingInfo;
Sarah Chin503828c2023-02-01 23:54:20 -0800153import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000154import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800155import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800156import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800157import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700158import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800159import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700160import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700161import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800162import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800163
Andrew Lee312e8172014-10-23 17:01:36 -0700164import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800165import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800166import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800167import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800168import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700169import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700170import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700171import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800172import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800173import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700174import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700175import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800176import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700177import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800178import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800179import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800180import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700181import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000182import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700183import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800184import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800186import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800187import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800188import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700189import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700190import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700191import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700193import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800194import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700195import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700196import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700197import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700198import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800199import com.android.internal.telephony.RILConstants;
Sarah Chineccfbd12023-01-20 19:00:35 -0800200import com.android.internal.telephony.RILUtils;
Daniel Bright94f43662021-03-01 14:43:40 -0800201import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700202import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000203import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700204import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700205import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800206import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800207import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800208import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700209import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000210import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800211import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700212import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800213import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700214import com.android.internal.telephony.imsphone.ImsPhone;
215import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000216import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800217import com.android.internal.telephony.metrics.TelephonyMetrics;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800218import com.android.internal.telephony.satellite.SatelliteServiceController;
Jack Yu285100e2022-12-02 22:48:35 -0800219import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
220import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700221import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700222import com.android.internal.telephony.uicc.IccIoResult;
223import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800224import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700225import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800226import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700227import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000228import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800229import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000230import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800231import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000232import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700233import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700234import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800235import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800236import com.android.phone.callcomposer.CallComposerPictureManager;
237import com.android.phone.callcomposer.CallComposerPictureTransfer;
238import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700239import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700240import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000241import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700242import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800243import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700244import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700245import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800246import com.android.services.telephony.TelecomAccountRegistry;
247import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800248import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800249
Hall Liu82694d52020-12-11 18:22:04 -0800250import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700251import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800252import java.io.IOException;
253import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700254import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700255import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800256import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000257import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800258import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800259import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800260import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800261import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100262import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800263import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700264import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800265import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800266import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700267import java.util.UUID;
Sarah Chineccfbd12023-01-20 19:00:35 -0800268import java.util.concurrent.ConcurrentHashMap;
Hall Liu82694d52020-12-11 18:22:04 -0800269import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800270import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800271import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700272
273/**
274 * Implementation of the ITelephony interface.
275 */
Santos Cordon117fee72014-05-16 17:56:12 -0700276public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700277 private static final String LOG_TAG = "PhoneInterfaceManager";
278 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
279 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800280 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700281
282 // Message codes used with mMainThreadHandler
283 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700284 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
285 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700286 private static final int CMD_OPEN_CHANNEL = 9;
287 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
288 private static final int CMD_CLOSE_CHANNEL = 11;
289 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800290 private static final int CMD_NV_READ_ITEM = 13;
291 private static final int EVENT_NV_READ_ITEM_DONE = 14;
292 private static final int CMD_NV_WRITE_ITEM = 15;
293 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
294 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
295 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700296 private static final int CMD_RESET_MODEM_CONFIG = 19;
297 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800298 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
299 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800300 private static final int CMD_SEND_ENVELOPE = 25;
301 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000302 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
303 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700304 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
305 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
306 private static final int CMD_EXCHANGE_SIM_IO = 31;
307 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800308 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
309 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700310 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
311 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700312 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
313 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700314 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
315 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
316 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
317 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700318 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
319 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
320 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
321 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700322 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800323 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
324 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000325 private static final int CMD_SWITCH_SLOTS = 50;
326 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700327 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
328 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
329 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
330 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
331 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
332 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
333 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
334 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700335 private static final int CMD_GET_ALL_CELL_INFO = 60;
336 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
337 private static final int CMD_GET_CELL_LOCATION = 62;
338 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700339 private static final int CMD_MODEM_REBOOT = 64;
340 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700341 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
342 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800343 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
344 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700345 private static final int CMD_GET_MODEM_STATUS = 70;
346 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700347 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
348 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700349 private static final int CMD_ERASE_MODEM_CONFIG = 74;
350 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800351 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
352 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
353 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
354 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800355 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
356 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800357 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800358 private static final int CMD_GET_CALL_FORWARDING = 83;
359 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
360 private static final int CMD_SET_CALL_FORWARDING = 85;
361 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
362 private static final int CMD_GET_CALL_WAITING = 87;
363 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
364 private static final int CMD_SET_CALL_WAITING = 89;
365 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700366 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
367 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
368 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
369 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700370 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
371 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800372 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
373 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800374 private static final int CMD_SET_DATA_THROTTLING = 99;
375 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800376 private static final int CMD_SET_SIM_POWER = 101;
377 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800378 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
379 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
380 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
381 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800382 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
383 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000384 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800385 private static final int CMD_GET_SLICING_CONFIG = 110;
386 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800387 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700388 private static final int CMD_ENABLE_VONR = 113;
389 private static final int EVENT_ENABLE_VONR_DONE = 114;
390 private static final int CMD_IS_VONR_ENABLED = 115;
391 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700392 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
393 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Sarah Chineccfbd12023-01-20 19:00:35 -0800394 private static final int CMD_START_SATELLITE_POSITION_UPDATES = 119;
395 private static final int EVENT_START_SATELLITE_POSITION_UPDATES_DONE = 120;
396 private static final int CMD_STOP_SATELLITE_POSITION_UPDATES = 121;
397 private static final int EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE = 122;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +0000398 private static final int CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG = 123;
399 private static final int EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE = 124;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800400 private static final int CMD_PROVISION_SATELLITE_SERVICE = 125;
401 private static final int EVENT_PROVISION_SATELLITE_SERVICE_DONE = 126;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -0800402 private static final int CMD_DEPROVISION_SATELLITE_SERVICE = 127;
403 private static final int EVENT_DEPROVISION_SATELLITE_SERVICE_DONE = 128;
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800404 private static final int CMD_SET_SATELLITE_ENABLED = 129;
405 private static final int EVENT_SET_SATELLITE_ENABLED_DONE = 130;
406 private static final int CMD_IS_SATELLITE_ENABLED = 131;
407 private static final int EVENT_IS_SATELLITE_ENABLED_DONE = 132;
408 private static final int CMD_IS_SATELLITE_SUPPORTED = 133;
409 private static final int EVENT_IS_SATELLITE_SUPPORTED_DONE = 134;
410 private static final int CMD_GET_SATELLITE_CAPABILITIES = 135;
411 private static final int EVENT_GET_SATELLITE_CAPABILITIES_DONE = 136;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000412 private static final int CMD_POLL_PENDING_SATELLITE_DATAGRAMS = 137;
413 private static final int EVENT_POLL_PENDING_SATELLITE_DATAGRAMS_DONE = 138;
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +0000414 private static final int CMD_SEND_SATELLITE_DATAGRAM = 139;
415 private static final int EVENT_SEND_SATELLITE_DATAGRAM_DONE = 140;
Sarah Chindf715ec2023-02-13 13:46:24 -0800416 private static final int CMD_IS_SATELLITE_COMMUNICATION_ALLOWED = 141;
417 private static final int EVENT_IS_SATELLITE_COMMUNICATION_ALLOWED_DONE = 142;
418 private static final int CMD_GET_TIME_SATELLITE_NEXT_VISIBLE = 143;
419 private static final int EVENT_GET_TIME_SATELLITE_NEXT_VISIBLE_DONE = 144;
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800420 // Parameters of select command.
421 private static final int SELECT_COMMAND = 0xA4;
422 private static final int SELECT_P1 = 0x04;
423 private static final int SELECT_P2 = 0;
424 private static final int SELECT_P3 = 0x10;
425
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000426 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
427 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
428
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700429 /** The singleton instance. */
430 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800431 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700432
Sarah Chin4beb2b72023-02-14 14:47:54 -0800433 private final PhoneGlobals mApp;
434 private final CallManager mCM;
435 private final ImsResolver mImsResolver;
436 private final SatelliteServiceController mSatelliteServiceController;
437 private final UserManager mUserManager;
438 private final AppOpsManager mAppOps;
439 private final MainThreadHandler mMainThreadHandler;
Jack Yue37dd262022-12-16 11:53:37 -0800440 private final SubscriptionController mSubscriptionController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800441 private final SharedPreferences mTelephonySharedPreferences;
442 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800443 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444
Peter Wangdafb9ac2020-01-15 14:13:38 -0800445 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800446 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800447 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
448
Sarah Chin4beb2b72023-02-14 14:47:54 -0800449 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800450
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800451 /**
452 * Map key: subId, value: callback to get error code of the provision request.
453 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800454 private final ConcurrentHashMap<Integer, Consumer<Integer>> mSatelliteProvisionCallbacks =
Sarah Chineccfbd12023-01-20 19:00:35 -0800455 new ConcurrentHashMap<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800456 /**
457 * Map key: subId, value: SatellitePositionUpdateHandler to notify registrants.
458 */
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800459 private final ConcurrentHashMap<Integer, SatellitePositionUpdateHandler>
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800460 mSatellitePositionUpdateHandlers = new ConcurrentHashMap<>();
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800461 /**
462 * Map key: subId, value: SatelliteProvisionStateChangedHandler to notify registrants.
463 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800464 private final ConcurrentHashMap<Integer, SatelliteProvisionStateChangedHandler>
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800465 mSatelliteProvisionStateChangedHandlers = new ConcurrentHashMap<>();
466
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800467 private Boolean mIsSatelliteSupported = null;
468 private final Object mIsSatelliteSupportedLock = new Object();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800469 private final ResultReceiver mSatelliteSupportedReceiver;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800470 /**
471 * {@code true} to use the vendor satellite service and {@code false} to use the HAL.
472 */
473 private final boolean mIsSatelliteServiceSupported = false;
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800474
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000475 /**
476 * Map key: subId, value: SatelliteStateChangeHandler to notify registrants.
477 */
478 private ConcurrentHashMap<Integer, SatelliteStateListenerHandler>
479 mSatelliteStateListenerHandlers = new ConcurrentHashMap<>();
480
481 /**
482 * Map key: subId, value: SatelliteDatagramListenerHandler to notify registrants.
483 */
484 private ConcurrentHashMap<Integer, SatelliteDatagramListenerHandler>
485 mSatelliteDatagramListenerHandlers = new ConcurrentHashMap<>();
486
Derek Tan97ebb422014-09-05 16:55:38 -0700487 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
488 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800489 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800490 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700491
Michelecea4cf22018-12-21 15:00:11 -0800492 // String to store multi SIM allowed
493 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
494
Derek Tan740e1672017-06-27 14:56:27 -0700495 // The AID of ISD-R.
496 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
497
yinxub1bed742017-04-17 11:45:04 -0700498 private NetworkScanRequestTracker mNetworkScanRequestTracker;
499
David Kelly5e06a7f2018-03-12 14:10:59 +0000500 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
501 private static final int MANUFACTURER_CODE_LENGTH = 8;
502
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800503 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800504 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800505
Sarah Chin2ec39f62022-08-31 17:03:26 -0700506 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
507 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
508
Derek Tan89e89d42014-07-08 17:00:10 -0700509 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700510 * Experiment flag to enable erase modem config on reset network, default value is false
511 */
512 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
513 "reset_network_erase_modem_config_enabled";
514
Rambo Wang0f050d82021-02-12 11:43:36 -0800515 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800516
Gary Jian76280a42022-12-07 16:18:33 +0800517 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
518
sandeepjsb6c87872021-09-27 15:34:44 +0000519 /**
520 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
521 * one ICCID active at the same time.
522 * Apps should use below API signatures if targeting SDK is T and beyond.
523 *
524 * @hide
525 */
526 @ChangeId
527 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
528 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800529
Naina Nallurid63128d2019-09-17 14:10:30 -0700530 /**
Chen Xu540470b2021-12-14 17:15:47 -0800531 * Apps targeting on Android T and beyond will get exception whenever icc close channel
532 * operation fails.
533 */
534 @ChangeId
535 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
536 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
537
538 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700539 * A request object to use for transmitting data to an ICC.
540 */
541 private static final class IccAPDUArgument {
542 public int channel, cla, command, p1, p2, p3;
543 public String data;
544
545 public IccAPDUArgument(int channel, int cla, int command,
546 int p1, int p2, int p3, String data) {
547 this.channel = channel;
548 this.cla = cla;
549 this.command = command;
550 this.p1 = p1;
551 this.p2 = p2;
552 this.p3 = p3;
553 this.data = data;
554 }
555 }
556
557 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700558 * A request object to use for transmitting data to an ICC.
559 */
560 private static final class ManualNetworkSelectionArgument {
561 public OperatorInfo operatorInfo;
562 public boolean persistSelection;
563
564 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
565 this.operatorInfo = operatorInfo;
566 this.persistSelection = persistSelection;
567 }
568 }
569
Sarah Chin71b3a852022-09-28 15:54:19 -0700570 private static final class PurchasePremiumCapabilityArgument {
571 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700572 public @NonNull IIntegerConsumer callback;
573
574 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800575 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700576 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700577 this.callback = callback;
578 }
579 }
580
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800581 private static final class ProvisionSatelliteServiceArgument {
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800582 public @NonNull String token;
583 public @NonNull Consumer<Integer> callback;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800584 public int subId;
585
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800586 ProvisionSatelliteServiceArgument(String token, Consumer<Integer> callback, int subId) {
587 this.token = token;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800588 this.callback = callback;
589 this.subId = subId;
590 }
591 }
592
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +0000593 private static final class SendSatelliteDatagramArgument {
594 public @SatelliteManager.DatagramType int datagramType;
595 public @NonNull SatelliteDatagram datagram;
596 public @NonNull Consumer<Integer> callback;
597
598 SendSatelliteDatagramArgument(@SatelliteManager.DatagramType int datagramType,
599 SatelliteDatagram datagram, Consumer<Integer> callback) {
600 this.datagramType = datagramType;
601 this.datagram = datagram;
602 this.callback = callback;
603 }
604 }
605
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800606 private static final class SatellitePositionUpdateArgument {
607 public @NonNull Consumer<Integer> errorCallback;
608 public @NonNull ISatellitePositionUpdateCallback callback;
609 public int subId;
610
611 SatellitePositionUpdateArgument(Consumer<Integer> errorCallback,
612 ISatellitePositionUpdateCallback callback, int subId) {
613 this.errorCallback = errorCallback;
614 this.callback = callback;
615 this.subId = subId;
616 }
617 }
618
Sarah Chineccfbd12023-01-20 19:00:35 -0800619 private static final class SatellitePositionUpdateHandler extends Handler {
620 public static final int EVENT_POSITION_UPDATE = 1;
621 public static final int EVENT_MESSAGE_TRANSFER_STATE_UPDATE = 2;
622
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800623 private final ConcurrentHashMap<IBinder, ISatellitePositionUpdateCallback> mListeners;
624 SatellitePositionUpdateHandler(Looper looper) {
Sarah Chineccfbd12023-01-20 19:00:35 -0800625 super(looper);
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800626 mListeners = new ConcurrentHashMap<>();
627 }
628
629 public void addListener(ISatellitePositionUpdateCallback listener) {
630 mListeners.put(listener.asBinder(), listener);
631 }
632
633 public void removeListener(ISatellitePositionUpdateCallback listener) {
634 mListeners.remove(listener.asBinder());
635 }
636
637 public boolean hasListeners() {
638 return !mListeners.isEmpty();
Sarah Chineccfbd12023-01-20 19:00:35 -0800639 }
640
641 @Override
642 public void handleMessage(@NonNull Message msg) {
643 switch (msg.what) {
644 case EVENT_POSITION_UPDATE: {
645 AsyncResult ar = (AsyncResult) msg.obj;
646 PointingInfo pointingInfo = (PointingInfo) ar.result;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800647 mListeners.values().forEach(listener -> {
648 try {
649 listener.onSatellitePositionUpdate(pointingInfo);
650 } catch (RemoteException e) {
651 log("EVENT_POSITION_UPDATE RemoteException: " + e);
652 }
653 });
Sarah Chineccfbd12023-01-20 19:00:35 -0800654 break;
655 }
656 case EVENT_MESSAGE_TRANSFER_STATE_UPDATE: {
657 AsyncResult ar = (AsyncResult) msg.obj;
658 int state = (int) ar.result;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800659 mListeners.values().forEach(listener -> {
660 try {
661 // TODO: get correct responses back from indication
662 listener.onDatagramTransferStateUpdate(state, 0, 0, 0);
663 } catch (RemoteException e) {
664 log("EVENT_MESSAGE_TRANSFER_STATE_UPDATE RemoteException: " + e);
665 }
666 });
Sarah Chineccfbd12023-01-20 19:00:35 -0800667 break;
668 }
669 default:
670 loge("SatellitePositionUpdateHandler unknown event: " + msg.what);
671 }
672 }
673 }
674
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800675 private static final class SatelliteProvisionStateChangedHandler extends Handler {
676 public static final int EVENT_PROVISION_STATE_CHANGED = 1;
677
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800678 private final ConcurrentHashMap<IBinder, ISatelliteProvisionStateCallback> mListeners;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800679 private final int mSubId;
680
681 SatelliteProvisionStateChangedHandler(Looper looper, int subId) {
682 super(looper);
683 mListeners = new ConcurrentHashMap<>();
684 mSubId = subId;
685 }
686
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800687 public void addListener(ISatelliteProvisionStateCallback listener) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800688 mListeners.put(listener.asBinder(), listener);
689 }
690
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800691 public void removeListener(ISatelliteProvisionStateCallback listener) {
692 mListeners.remove(listener.asBinder());
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800693 }
694
695 @Override
696 public void handleMessage(@NonNull Message msg) {
697 switch (msg.what) {
698 case EVENT_PROVISION_STATE_CHANGED: {
699 AsyncResult ar = (AsyncResult) msg.obj;
700 boolean provisioned = (boolean) ar.userObj;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800701 log("Received EVENT_PROVISION_STATE_CHANGED for subId=" + mSubId
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800702 + ", provisioned=" + provisioned);
703 mListeners.values().forEach(listener -> {
704 try {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -0800705 listener.onSatelliteProvisionStateChanged(provisioned);
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800706 } catch (RemoteException e) {
707 log("EVENT_PROVISION_STATE_CHANGED RemoteException: " + e);
708 }
709 });
710
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800711 setSatelliteProvisioned(provisioned);
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800712 /**
713 * TODO: Take bugreport if provisioned is true and user did not initiate the
714 * provision procedure for the corresponding subscription.
715 */
716 break;
717 }
718 default:
719 loge("SatelliteProvisionStateChangedHandler unknown event: " + msg.what);
720 }
721 }
722
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800723 private void setSatelliteProvisioned(boolean isProvisioned) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800724 if (mSubId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
725 SubscriptionManager.setSubscriptionProperty(
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800726 mSubId, SubscriptionManager.SATELLITE_ENABLED, isProvisioned ? "1" : "0");
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800727 } else {
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800728 //TODO (b/267826133): set via SatelliteController.
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800729 }
730 }
731 }
732
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000733 private static final class SatelliteStateListenerHandler extends Handler {
734 public static final int EVENT_SATELLITE_MODEM_STATE_CHANGE = 1;
Aishwarya Mallampati224317a2023-02-13 22:09:30 +0000735 public static final int EVENT_PENDING_DATAGRAM_COUNT = 2;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000736
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800737 private final ConcurrentHashMap<IBinder, ISatelliteStateCallback> mListeners;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000738 private final int mSubId;
739
740 SatelliteStateListenerHandler(Looper looper, int subId) {
741 super(looper);
742 mSubId = subId;
743 mListeners = new ConcurrentHashMap<>();
744 }
745
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800746 public void addListener(ISatelliteStateCallback listener) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000747 mListeners.put(listener.asBinder(), listener);
748 }
749
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800750 public void removeListener(ISatelliteStateCallback listener) {
751 mListeners.remove(listener.asBinder());
752 }
753
754 public boolean hasListeners() {
755 return !mListeners.isEmpty();
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000756 }
757
758 @Override
759 public void handleMessage(@NonNull Message msg) {
760 switch (msg.what) {
761 case EVENT_SATELLITE_MODEM_STATE_CHANGE : {
762 AsyncResult ar = (AsyncResult) msg.obj;
763 int state = (int) ar.result;
764 log("Received EVENT_SATELLITE_MODEM_STATE_CHANGE for subId=" + mSubId
765 + ", state=" + state);
766 mListeners.values().forEach(listener -> {
767 try {
768 listener.onSatelliteModemStateChange(state);
769 } catch (RemoteException e) {
770 log("EVENT_SATELLITE_MODEM_STATE_CHANGE RemoteException: " + e);
771 }
772 });
773 break;
774 }
Aishwarya Mallampati224317a2023-02-13 22:09:30 +0000775 case EVENT_PENDING_DATAGRAM_COUNT: {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000776 AsyncResult ar = (AsyncResult) msg.obj;
777 int count = (int) ar.result;
Aishwarya Mallampati224317a2023-02-13 22:09:30 +0000778 log("Received EVENT_PENDING_DATAGRAM_COUNT for subId=" + mSubId
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000779 + ", count=" + count);
780 mListeners.values().forEach(listener -> {
781 try {
Aishwarya Mallampati224317a2023-02-13 22:09:30 +0000782 listener.onPendingDatagramCount(count);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000783 } catch (RemoteException e) {
Aishwarya Mallampati224317a2023-02-13 22:09:30 +0000784 log("EVENT_PENDING_DATAGRAM_COUNT RemoteException: " + e);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000785 }
786 });
787 break;
788 }
789 default:
790 loge("SatelliteStateListenerHandler unknown event: " + msg.what);
791 }
792 }
793 }
794
795 private static final class SatelliteDatagramListenerHandler extends Handler {
796 public static final int EVENT_SATELLITE_DATAGRAMS_RECEIVED = 1;
797
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800798 private final ConcurrentHashMap<IBinder, ISatelliteDatagramCallback> mListeners;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000799 private final int mSubId;
800
801 SatelliteDatagramListenerHandler(Looper looper, int subId) {
802 super(looper);
803 mSubId = subId;
804 mListeners = new ConcurrentHashMap<>();
805 }
806
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800807 public void addListener(ISatelliteDatagramCallback listener) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000808 mListeners.put(listener.asBinder(), listener);
809 }
810
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800811 public void removeListener(ISatelliteDatagramCallback listener) {
812 mListeners.remove(listener.asBinder());
813 }
814
815 public boolean hasListeners() {
816 return !mListeners.isEmpty();
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000817 }
818
819 @Override
820 public void handleMessage(@NonNull Message msg) {
821 switch (msg.what) {
822 case EVENT_SATELLITE_DATAGRAMS_RECEIVED : {
823 AsyncResult ar = (AsyncResult) msg.obj;
824 byte[][] datagrams = (byte[][]) ar.result;
825 SatelliteDatagram[] satelliteDatagramArray =
826 convertToSatelliteDatagramArray(datagrams);
827
828 log("Received EVENT_SATELLITE_DATAGRAMS_RECEIVED for subId=" + mSubId);
829 mListeners.values().forEach(listener -> {
830 try {
831 listener.onSatelliteDatagrams(satelliteDatagramArray);
832 } catch (RemoteException e) {
833 log("EVENT_SATELLITE_DATAGRAMS_RECEIVED RemoteException: " + e);
834 }
835 });
836 break;
837 }
838 default:
839 loge("SatelliteDatagramListenerHandler unknown event: " + msg.what);
840 }
841 }
842 }
843
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700844 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700845 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
846 * request after sending. The main thread will notify the request when it is complete.
847 */
848 private static final class MainThreadRequest {
849 /** The argument to use for the request */
850 public Object argument;
851 /** The result of the request that is run on the main thread */
852 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800853 // The subscriber id that this request applies to. Defaults to
854 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
855 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700856
Nathan Harold92bed182018-10-12 18:16:49 -0700857 // In cases where subId is unavailable, the caller needs to specify the phone.
858 public Phone phone;
859
vagdeviaf9a5b92018-08-15 16:01:53 -0700860 public WorkSource workSource;
861
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700862 public MainThreadRequest(Object argument) {
863 this.argument = argument;
864 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800865
Nathan Harold92bed182018-10-12 18:16:49 -0700866 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
867 this.argument = argument;
868 if (phone != null) {
869 this.phone = phone;
870 }
871 this.workSource = workSource;
872 }
873
vagdeviaf9a5b92018-08-15 16:01:53 -0700874 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800875 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800876 if (subId != null) {
877 this.subId = subId;
878 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700879 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800880 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700881 }
882
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800883 private static final class IncomingThirdPartyCallArgs {
884 public final ComponentName component;
885 public final String callId;
886 public final String callerDisplayName;
887
888 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
889 String callerDisplayName) {
890 this.component = component;
891 this.callId = callId;
892 this.callerDisplayName = callerDisplayName;
893 }
894 }
895
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700896 /**
897 * A handler that processes messages on the main thread in the phone process. Since many
898 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
899 * inbound binder threads to the main thread in the phone process. The Binder thread
900 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
901 * on, which will be notified when the operation completes and will contain the result of the
902 * request.
903 *
904 * <p>If a MainThreadRequest object is provided in the msg.obj field,
905 * note that request.result must be set to something non-null for the calling thread to
906 * unblock.
907 */
908 private final class MainThreadHandler extends Handler {
909 @Override
910 public void handleMessage(Message msg) {
911 MainThreadRequest request;
912 Message onCompleted;
913 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000914 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700915 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800916 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700917
918 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700919 case CMD_HANDLE_USSD_REQUEST: {
920 request = (MainThreadRequest) msg.obj;
921 final Phone phone = getPhoneFromRequest(request);
922 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800923 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700924 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700925
Pengquan Menga1bb6272018-09-06 09:59:22 -0700926 if (!isUssdApiAllowed(request.subId)) {
927 // Carrier does not support use of this API, return failure.
928 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
929 UssdResponse response = new UssdResponse(ussdRequest, null);
930 Bundle returnData = new Bundle();
931 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
932 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700933
Pengquan Menga1bb6272018-09-06 09:59:22 -0700934 request.result = true;
935 notifyRequester(request);
936 return;
937 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700938
Pengquan Menga1bb6272018-09-06 09:59:22 -0700939 try {
940 request.result = phone != null
941 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
942 } catch (CallStateException cse) {
943 request.result = false;
944 }
945 // Wake up the requesting thread
946 notifyRequester(request);
947 break;
pkanwar32d516d2016-10-14 19:37:38 -0700948 }
949
Yorke Lee716f67e2015-06-17 15:39:16 -0700950 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700951 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700952 final Phone phone = getPhoneFromRequest(request);
953 request.result = phone != null ?
954 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
955 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700956 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700957 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700958 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700959 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700960
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700961 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700962 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700963 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000964 uiccPort = getUiccPortFromRequest(request);
965 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700966 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800967 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700968 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700969 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700970 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800971 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000972 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800973 iccArgument.channel, iccArgument.cla, iccArgument.command,
974 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
975 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700976 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700977 break;
978
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700979 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700980 ar = (AsyncResult) msg.obj;
981 request = (MainThreadRequest) ar.userObj;
982 if (ar.exception == null && ar.result != null) {
983 request.result = ar.result;
984 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800985 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700986 if (ar.result == null) {
987 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800988 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700989 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800990 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700991 } else {
992 loge("iccTransmitApduLogicalChannel: Unknown exception");
993 }
994 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700995 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700996 break;
997
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700998 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
999 request = (MainThreadRequest) msg.obj;
1000 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001001 uiccPort = getUiccPortFromRequest(request);
1002 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001003 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -08001004 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001005 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001006 } else {
1007 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -08001008 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001009 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -08001010 iccArgument.cla, iccArgument.command, iccArgument.p1,
1011 iccArgument.p2,
1012 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001013 }
1014 break;
1015
1016 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
1017 ar = (AsyncResult) msg.obj;
1018 request = (MainThreadRequest) ar.userObj;
1019 if (ar.exception == null && ar.result != null) {
1020 request.result = ar.result;
1021 } else {
Chen Xue9d737e2022-01-01 23:41:31 -08001022 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001023 if (ar.result == null) {
1024 loge("iccTransmitApduBasicChannel: Empty response");
1025 } else if (ar.exception instanceof CommandException) {
1026 loge("iccTransmitApduBasicChannel: CommandException: " +
1027 ar.exception);
1028 } else {
1029 loge("iccTransmitApduBasicChannel: Unknown exception");
1030 }
1031 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001032 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001033 break;
1034
1035 case CMD_EXCHANGE_SIM_IO:
1036 request = (MainThreadRequest) msg.obj;
1037 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001038 uiccPort = getUiccPortFromRequest(request);
1039 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001040 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -08001041 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001042 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001043 } else {
1044 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
1045 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001046 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001047 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
1048 iccArgument.data, onCompleted);
1049 }
1050 break;
1051
1052 case EVENT_EXCHANGE_SIM_IO_DONE:
1053 ar = (AsyncResult) msg.obj;
1054 request = (MainThreadRequest) ar.userObj;
1055 if (ar.exception == null && ar.result != null) {
1056 request.result = ar.result;
1057 } else {
Chen Xue9d737e2022-01-01 23:41:31 -08001058 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001059 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001060 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001061 break;
1062
Derek Tan4d5e5c12014-02-04 11:54:58 -08001063 case CMD_SEND_ENVELOPE:
1064 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001065 uiccPort = getUiccPortFromRequest(request);
1066 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001067 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -08001068 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001069 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001070 } else {
1071 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -08001072 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001073 }
Derek Tan4d5e5c12014-02-04 11:54:58 -08001074 break;
1075
1076 case EVENT_SEND_ENVELOPE_DONE:
1077 ar = (AsyncResult) msg.obj;
1078 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -07001079 if (ar.exception == null && ar.result != null) {
1080 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -08001081 } else {
Chen Xue9d737e2022-01-01 23:41:31 -08001082 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -07001083 if (ar.result == null) {
1084 loge("sendEnvelopeWithStatus: Empty response");
1085 } else if (ar.exception instanceof CommandException) {
1086 loge("sendEnvelopeWithStatus: CommandException: " +
1087 ar.exception);
1088 } else {
1089 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
1090 }
Derek Tan4d5e5c12014-02-04 11:54:58 -08001091 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001092 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -08001093 break;
1094
Shishir Agrawal566b7612013-10-28 14:41:00 -07001095 case CMD_OPEN_CHANNEL:
1096 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001097 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -08001098 IccLogicalChannelRequest openChannelRequest =
1099 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001100 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001101 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -08001102 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -08001103 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001104 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001105 } else {
1106 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -08001107 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
1108 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001109 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001110 break;
1111
1112 case EVENT_OPEN_CHANNEL_DONE:
1113 ar = (AsyncResult) msg.obj;
1114 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001115 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -07001116 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001117 int[] result = (int[]) ar.result;
1118 int channelId = result[0];
1119 byte[] selectResponse = null;
1120 if (result.length > 1) {
1121 selectResponse = new byte[result.length - 1];
1122 for (int i = 1; i < result.length; ++i) {
1123 selectResponse[i - 1] = (byte) result[i];
1124 }
1125 }
1126 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -08001127 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -08001128
1129 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -07001130 if (uiccPort == null) {
1131 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
1132 } else {
1133 IccLogicalChannelRequest channelRequest =
1134 (IccLogicalChannelRequest) request.argument;
1135 channelRequest.channel = channelId;
1136 uiccPort.onLogicalChannelOpened(channelRequest);
1137 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001138 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -07001139 if (ar.result == null) {
1140 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -07001141 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001142 if (ar.exception != null) {
1143 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
1144 }
1145
Shishir Agrawal527e8bf2014-08-25 08:54:56 -07001146 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -07001147 if (ar.exception instanceof CommandException) {
1148 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -08001149 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -07001150 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -07001151 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -07001152 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -07001153 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001154 }
1155 }
1156 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -08001157 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001158 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -07001159 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001160 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001161 break;
1162
1163 case CMD_CLOSE_CHANNEL:
1164 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001165 uiccPort = getUiccPortFromRequest(request);
1166 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001167 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -08001168 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001169 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -08001170 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001171 } else {
1172 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001173 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001174 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001175 break;
1176
1177 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -08001178 ar = (AsyncResult) msg.obj;
1179 request = (MainThreadRequest) ar.userObj;
1180 if (ar.exception == null) {
1181 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -08001182 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -07001183 if (uiccPort == null) {
1184 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
1185 } else {
1186 final int channelId = (Integer) request.argument;
1187 uiccPort.onLogicalChannelClosed(channelId);
1188 }
Chen Xu540470b2021-12-14 17:15:47 -08001189 } else {
1190 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -08001191 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -08001192 if (ar.exception instanceof CommandException) {
1193 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
1194 CommandException.Error error =
1195 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -08001196 if (error == CommandException.Error.INVALID_ARGUMENTS) {
1197 // should only throw exceptions from the binder threads.
1198 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -08001199 "iccCloseLogicalChannel: invalid argument ");
1200 }
1201 } else {
1202 loge("iccCloseLogicalChannel: Unknown exception");
1203 }
Chen Xua8f0dff2022-02-12 00:34:15 -08001204 request.result = (exception != null) ? exception :
1205 new IllegalStateException(
1206 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -08001207 }
1208 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001209 break;
1210
1211 case CMD_NV_READ_ITEM:
1212 request = (MainThreadRequest) msg.obj;
1213 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001214 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
1215 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -08001216 break;
1217
1218 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -07001219 ar = (AsyncResult) msg.obj;
1220 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -08001221 if (ar.exception == null && ar.result != null) {
1222 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -07001223 } else {
Jake Hambye994d462014-02-03 13:10:13 -08001224 request.result = "";
1225 if (ar.result == null) {
1226 loge("nvReadItem: Empty response");
1227 } else if (ar.exception instanceof CommandException) {
1228 loge("nvReadItem: CommandException: " +
1229 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001230 } else {
Jake Hambye994d462014-02-03 13:10:13 -08001231 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -07001232 }
1233 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001234 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001235 break;
1236
Jake Hambye994d462014-02-03 13:10:13 -08001237 case CMD_NV_WRITE_ITEM:
1238 request = (MainThreadRequest) msg.obj;
1239 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
1240 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001241 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -07001242 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -08001243 break;
1244
1245 case EVENT_NV_WRITE_ITEM_DONE:
1246 handleNullReturnEvent(msg, "nvWriteItem");
1247 break;
1248
1249 case CMD_NV_WRITE_CDMA_PRL:
1250 request = (MainThreadRequest) msg.obj;
1251 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001252 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -08001253 break;
1254
1255 case EVENT_NV_WRITE_CDMA_PRL_DONE:
1256 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
1257 break;
1258
chen xu6dac5ab2018-10-26 17:39:23 -07001259 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -08001260 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -07001261 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001262 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -08001263 break;
1264
chen xu6dac5ab2018-10-26 17:39:23 -07001265 case EVENT_RESET_MODEM_CONFIG_DONE:
1266 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -08001267 break;
1268
Sooraj Sasindran37444802020-08-11 10:40:43 -07001269 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
1270 request = (MainThreadRequest) msg.obj;
1271 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
1272 request);
1273 Phone phone = getPhoneFromRequest(request);
1274 if (phone != null) {
1275 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
1276 } else {
1277 loge("isNRDualConnectivityEnabled: No phone object");
1278 request.result = false;
1279 notifyRequester(request);
1280 }
1281 break;
1282 }
1283
1284 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
1285 ar = (AsyncResult) msg.obj;
1286 request = (MainThreadRequest) ar.userObj;
1287 if (ar.exception == null && ar.result != null) {
1288 request.result = ar.result;
1289 } else {
1290 // request.result must be set to something non-null
1291 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001292 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -07001293 request.result = ar.result;
1294 } else {
1295 request.result = false;
1296 }
1297 if (ar.result == null) {
1298 loge("isNRDualConnectivityEnabled: Empty response");
1299 } else if (ar.exception instanceof CommandException) {
1300 loge("isNRDualConnectivityEnabled: CommandException: "
1301 + ar.exception);
1302 } else {
1303 loge("isNRDualConnectivityEnabled: Unknown exception");
1304 }
1305 }
1306 notifyRequester(request);
1307 break;
1308
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001309 case CMD_IS_VONR_ENABLED: {
1310 request = (MainThreadRequest) msg.obj;
1311 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1312 request);
1313 Phone phone = getPhoneFromRequest(request);
1314 if (phone != null) {
1315 phone.isVoNrEnabled(onCompleted, request.workSource);
1316 } else {
1317 loge("isVoNrEnabled: No phone object");
1318 request.result = false;
1319 notifyRequester(request);
1320 }
1321 break;
1322 }
1323
1324 case EVENT_IS_VONR_ENABLED_DONE:
1325 ar = (AsyncResult) msg.obj;
1326 request = (MainThreadRequest) ar.userObj;
1327 if (ar.exception == null && ar.result != null) {
1328 request.result = ar.result;
1329 } else {
1330 // request.result must be set to something non-null
1331 // for the calling thread to unblock
1332 if (ar.result != null) {
1333 request.result = ar.result;
1334 } else {
1335 request.result = false;
1336 }
1337 if (ar.result == null) {
1338 loge("isVoNrEnabled: Empty response");
1339 } else if (ar.exception instanceof CommandException) {
1340 loge("isVoNrEnabled: CommandException: "
1341 + ar.exception);
1342 } else {
1343 loge("isVoNrEnabled: Unknown exception");
1344 }
1345 }
1346 notifyRequester(request);
1347 break;
1348
Sooraj Sasindran37444802020-08-11 10:40:43 -07001349 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1350 request = (MainThreadRequest) msg.obj;
1351 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1352 Phone phone = getPhoneFromRequest(request);
1353 if (phone != null) {
1354 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1355 request.workSource);
1356 } else {
1357 loge("enableNrDualConnectivity: No phone object");
1358 request.result =
1359 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1360 notifyRequester(request);
1361 }
1362 break;
1363 }
1364
1365 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1366 ar = (AsyncResult) msg.obj;
1367 request = (MainThreadRequest) ar.userObj;
1368 if (ar.exception == null) {
1369 request.result =
1370 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1371 } else {
1372 request.result =
1373 TelephonyManager
1374 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1375 if (ar.exception instanceof CommandException) {
1376 CommandException.Error error =
1377 ((CommandException) (ar.exception)).getCommandError();
1378 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1379 request.result =
1380 TelephonyManager
1381 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001382 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1383 request.result =
1384 TelephonyManager
1385 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001386 }
1387 loge("enableNrDualConnectivity" + ": CommandException: "
1388 + ar.exception);
1389 } else {
1390 loge("enableNrDualConnectivity" + ": Unknown exception");
1391 }
1392 }
1393 notifyRequester(request);
1394 break;
1395 }
1396
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001397 case CMD_ENABLE_VONR: {
1398 request = (MainThreadRequest) msg.obj;
1399 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1400 Phone phone = getPhoneFromRequest(request);
1401 if (phone != null) {
1402 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1403 request.workSource);
1404 } else {
1405 loge("setVoNrEnabled: No phone object");
1406 request.result =
1407 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1408 notifyRequester(request);
1409 }
1410 break;
1411 }
1412
1413 case EVENT_ENABLE_VONR_DONE: {
1414 ar = (AsyncResult) msg.obj;
1415 request = (MainThreadRequest) ar.userObj;
1416 if (ar.exception == null) {
1417 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1418 } else {
1419 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1420 if (ar.exception instanceof CommandException) {
1421 CommandException.Error error =
1422 ((CommandException) (ar.exception)).getCommandError();
1423 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1424 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1425 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1426 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1427 } else {
1428 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1429 }
1430 loge("setVoNrEnabled" + ": CommandException: "
1431 + ar.exception);
1432 } else {
1433 loge("setVoNrEnabled" + ": Unknown exception");
1434 }
1435 }
1436 notifyRequester(request);
1437 break;
1438 }
1439
SongFerngWang3ef3e072020-12-21 16:41:52 +08001440 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001441 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001442 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1443 request);
1444 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001445 break;
1446
SongFerngWang3ef3e072020-12-21 16:41:52 +08001447 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001448 ar = (AsyncResult) msg.obj;
1449 request = (MainThreadRequest) ar.userObj;
1450 if (ar.exception == null && ar.result != null) {
1451 request.result = ar.result; // Integer
1452 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301453 // request.result must be set to something non-null
1454 // for the calling thread to unblock
1455 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001456 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001457 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001458 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001459 loge("getAllowedNetworkTypesBitmask: CommandException: "
1460 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001461 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001462 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001463 }
1464 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001465 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001466 break;
1467
SongFerngWang3ef3e072020-12-21 16:41:52 +08001468 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001469 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001470 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1471 request);
1472 Pair<Integer, Long> reasonWithNetworkTypes =
1473 (Pair<Integer, Long>) request.argument;
1474 getPhoneFromRequest(request).setAllowedNetworkTypes(
1475 reasonWithNetworkTypes.first,
1476 reasonWithNetworkTypes.second,
1477 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001478 break;
1479
SongFerngWang3ef3e072020-12-21 16:41:52 +08001480 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1481 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001482 break;
1483
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001484 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1485 request = (MainThreadRequest)msg.obj;
1486 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001487 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001488 break;
1489
1490 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1491 ar = (AsyncResult)msg.obj;
1492 request = (MainThreadRequest)ar.userObj;
1493 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001494 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001495 break;
1496
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001497 case CMD_SET_VOICEMAIL_NUMBER:
1498 request = (MainThreadRequest) msg.obj;
1499 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1500 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001501 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1502 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001503 break;
1504
1505 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1506 handleNullReturnEvent(msg, "setVoicemailNumber");
1507 break;
1508
Stuart Scott54788802015-03-30 13:18:01 -07001509 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1510 request = (MainThreadRequest) msg.obj;
1511 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1512 request);
1513 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1514 break;
1515
1516 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1517 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1518 break;
1519
Shishir Agrawal302c8692015-06-19 13:49:39 -07001520 case CMD_PERFORM_NETWORK_SCAN:
1521 request = (MainThreadRequest) msg.obj;
1522 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1523 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1524 break;
1525
Hall Liu27d24262020-09-18 19:04:59 -07001526 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001527 request = (MainThreadRequest) msg.obj;
1528 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001529 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1530 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1531 request.argument;
1532 int callForwardingReason = args.first;
1533 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001534 break;
Hall Liu27d24262020-09-18 19:04:59 -07001535 }
1536 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001537 ar = (AsyncResult) msg.obj;
1538 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001539 TelephonyManager.CallForwardingInfoCallback callback =
1540 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1541 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001542 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001543 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001544 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1545 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1546 // Service Class is a bit mask per 3gpp 27.007. Search for
1547 // any service for voice call.
1548 if ((callForwardInfo.serviceClass
1549 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001550 callForwardingInfo = new CallForwardingInfo(
1551 callForwardInfo.status
1552 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001553 callForwardInfo.reason,
1554 callForwardInfo.number,
1555 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001556 break;
1557 }
1558 }
1559 // Didn't find a call forward info for voice call.
1560 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001561 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1562 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001563 }
Hall Liu27d24262020-09-18 19:04:59 -07001564 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001565 } else {
1566 if (ar.result == null) {
1567 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1568 }
1569 if (ar.exception != null) {
1570 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1571 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001572 int errorCode = TelephonyManager
1573 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001574 if (ar.exception instanceof CommandException) {
1575 CommandException.Error error =
1576 ((CommandException) (ar.exception)).getCommandError();
1577 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001578 errorCode = TelephonyManager
1579 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001580 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001581 errorCode = TelephonyManager
1582 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001583 }
1584 }
Hall Liu27d24262020-09-18 19:04:59 -07001585 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001586 }
Shuo Qian4a594052020-01-23 11:59:30 -08001587 break;
Hall Liu27d24262020-09-18 19:04:59 -07001588 }
Shuo Qian4a594052020-01-23 11:59:30 -08001589
Hall Liu27d24262020-09-18 19:04:59 -07001590 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001591 request = (MainThreadRequest) msg.obj;
1592 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001593 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001594 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001595 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1596 request.argument).first;
1597 request.phone.setCallForwardingOption(
1598 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001599 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001600 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001601 callForwardingInfoToSet.getReason(),
1602 callForwardingInfoToSet.getNumber(),
1603 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1604 break;
Hall Liu27d24262020-09-18 19:04:59 -07001605 }
Shuo Qian4a594052020-01-23 11:59:30 -08001606
Hall Liu27d24262020-09-18 19:04:59 -07001607 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001608 ar = (AsyncResult) msg.obj;
1609 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001610 Consumer<Integer> callback =
1611 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1612 request.argument).second;
1613 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001614 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001615 int errorCode = TelephonyManager.CallForwardingInfoCallback
1616 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001617 if (ar.exception instanceof CommandException) {
1618 CommandException.Error error =
1619 ((CommandException) (ar.exception)).getCommandError();
1620 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001621 errorCode = TelephonyManager.CallForwardingInfoCallback
1622 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001623 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001624 errorCode = TelephonyManager.CallForwardingInfoCallback
1625 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001626 }
1627 }
1628 callback.accept(errorCode);
1629 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001630 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001631 }
Shuo Qian4a594052020-01-23 11:59:30 -08001632 break;
Hall Liu27d24262020-09-18 19:04:59 -07001633 }
Shuo Qian4a594052020-01-23 11:59:30 -08001634
Hall Liu27d24262020-09-18 19:04:59 -07001635 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001636 request = (MainThreadRequest) msg.obj;
1637 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1638 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1639 break;
Hall Liu27d24262020-09-18 19:04:59 -07001640 }
Shuo Qian4a594052020-01-23 11:59:30 -08001641
Hall Liu27d24262020-09-18 19:04:59 -07001642 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001643 ar = (AsyncResult) msg.obj;
1644 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001645 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001646 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001647 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001648 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001649 // Service Class is a bit mask per 3gpp 27.007.
1650 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001651 if (callForwardResults.length > 1
1652 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001653 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001654 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001655 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1656 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001657 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001658 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001659 }
1660 } else {
1661 if (ar.result == null) {
1662 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1663 }
1664 if (ar.exception != null) {
1665 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1666 }
1667 if (ar.exception instanceof CommandException) {
1668 CommandException.Error error =
1669 ((CommandException) (ar.exception)).getCommandError();
1670 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001671 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001672 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001673 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1674 callWaitingStatus =
1675 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001676 }
1677 }
1678 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001679 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001680 break;
Hall Liu27d24262020-09-18 19:04:59 -07001681 }
Shuo Qian4a594052020-01-23 11:59:30 -08001682
Hall Liu27d24262020-09-18 19:04:59 -07001683 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001684 request = (MainThreadRequest) msg.obj;
1685 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001686 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1687 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001688 break;
Hall Liu27d24262020-09-18 19:04:59 -07001689 }
Shuo Qian4a594052020-01-23 11:59:30 -08001690
Hall Liu27d24262020-09-18 19:04:59 -07001691 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001692 ar = (AsyncResult) msg.obj;
1693 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001694 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1695 Consumer<Integer> callback =
1696 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1697 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001698 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001699 if (ar.exception instanceof CommandException) {
1700 CommandException.Error error =
1701 ((CommandException) (ar.exception)).getCommandError();
1702 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1703 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001704 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1705 callback.accept(
1706 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001707 } else {
1708 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1709 }
1710 } else {
1711 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1712 }
1713 } else {
1714 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1715 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001716 }
Shuo Qian4a594052020-01-23 11:59:30 -08001717 break;
Hall Liu27d24262020-09-18 19:04:59 -07001718 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001719 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1720 ar = (AsyncResult) msg.obj;
1721 request = (MainThreadRequest) ar.userObj;
1722 CellNetworkScanResult cellScanResult;
1723 if (ar.exception == null && ar.result != null) {
1724 cellScanResult = new CellNetworkScanResult(
1725 CellNetworkScanResult.STATUS_SUCCESS,
1726 (List<OperatorInfo>) ar.result);
1727 } else {
1728 if (ar.result == null) {
1729 loge("getCellNetworkScanResults: Empty response");
1730 }
1731 if (ar.exception != null) {
1732 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1733 }
1734 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1735 if (ar.exception instanceof CommandException) {
1736 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001737 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001738 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1739 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1740 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1741 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1742 }
1743 }
1744 cellScanResult = new CellNetworkScanResult(errorCode, null);
1745 }
1746 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001747 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001748 break;
1749
1750 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1751 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001752 ManualNetworkSelectionArgument selArg =
1753 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001754 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1755 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001756 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1757 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001758 break;
1759
1760 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001761 ar = (AsyncResult) msg.obj;
1762 request = (MainThreadRequest) ar.userObj;
1763 if (ar.exception == null) {
1764 request.result = true;
1765 } else {
1766 request.result = false;
1767 loge("setNetworkSelectionModeManual " + ar.exception);
1768 }
1769 notifyRequester(request);
1770 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001771 break;
1772
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001773 case CMD_GET_MODEM_ACTIVITY_INFO:
1774 request = (MainThreadRequest) msg.obj;
1775 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001776 if (defaultPhone != null) {
1777 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001778 } else {
1779 ResultReceiver result = (ResultReceiver) request.argument;
1780 Bundle bundle = new Bundle();
1781 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001782 new ModemActivityInfo(0, 0, 0,
1783 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001784 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001785 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001786 break;
1787
Hall Liud0f208c2020-10-14 16:54:44 -07001788 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001789 ar = (AsyncResult) msg.obj;
1790 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001791 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001792 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001793 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001794 if (mLastModemActivityInfo == null) {
1795 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1796 mLastModemActivitySpecificInfo[0] =
1797 new ActivityStatsTechSpecificInfo(
1798 0,
1799 0,
1800 new int[ModemActivityInfo.getNumTxPowerLevels()],
1801 0);
1802 mLastModemActivityInfo =
1803 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1804 }
1805
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001806 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001807 // Update the last modem activity info and the result of the request.
1808 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1809 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001810 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001811 } else {
1812 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001813 }
Kai Shi917fdc62022-11-28 14:01:02 -08001814 // This is needed to decouple ret from mLastModemActivityInfo
1815 // We don't want to return mLastModemActivityInfo which is updated
1816 // inside mergeModemActivityInfo()
1817 ret = new ModemActivityInfo(
1818 mLastModemActivityInfo.getTimestampMillis(),
1819 mLastModemActivityInfo.getSleepTimeMillis(),
1820 mLastModemActivityInfo.getIdleTimeMillis(),
1821 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001822
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001823 } else {
1824 if (ar.result == null) {
1825 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001826 error = TelephonyManager.ModemActivityInfoException
1827 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001828 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001829 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001830 error = TelephonyManager.ModemActivityInfoException
1831 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001832 } else {
1833 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001834 error = TelephonyManager.ModemActivityInfoException
1835 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001836 }
1837 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001838 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001839 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001840 bundle.putParcelable(
1841 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001842 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001843 } else {
1844 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1845 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001846 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001847 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001848 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001849 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001850
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001851 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001852 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001853 CarrierRestrictionRules argument =
1854 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001855 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001856 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001857 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001858 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001859
1860 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1861 ar = (AsyncResult) msg.obj;
1862 request = (MainThreadRequest) ar.userObj;
1863 if (ar.exception == null && ar.result != null) {
1864 request.result = ar.result;
1865 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001866 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1867 if (ar.exception instanceof CommandException) {
1868 loge("setAllowedCarriers: CommandException: " + ar.exception);
1869 CommandException.Error error =
1870 ((CommandException) (ar.exception)).getCommandError();
1871 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1872 request.result =
1873 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1874 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001875 } else {
1876 loge("setAllowedCarriers: Unknown exception");
1877 }
1878 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001879 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001880 break;
1881
1882 case CMD_GET_ALLOWED_CARRIERS:
1883 request = (MainThreadRequest) msg.obj;
1884 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001885 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001886 break;
1887
1888 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1889 ar = (AsyncResult) msg.obj;
1890 request = (MainThreadRequest) ar.userObj;
1891 if (ar.exception == null && ar.result != null) {
1892 request.result = ar.result;
1893 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001894 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001895 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001896 if (ar.result == null) {
1897 loge("getAllowedCarriers: Empty response");
1898 } else if (ar.exception instanceof CommandException) {
1899 loge("getAllowedCarriers: CommandException: " +
1900 ar.exception);
1901 } else {
1902 loge("getAllowedCarriers: Unknown exception");
1903 }
1904 }
arunvoddud7401012022-12-15 16:08:12 +00001905 if (request.argument != null) {
1906 // This is for the implementation of carrierRestrictionStatus.
1907 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1908 Consumer<Integer> callback = callbackInfo.getConsumer();
1909 int callerCarrierId = callbackInfo.getCarrierId();
1910 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1911 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1912 CarrierRestrictionRules carrierRestrictionRules =
1913 (CarrierRestrictionRules) ar.result;
1914 int carrierId = -1;
1915 try {
1916 CarrierIdentifier carrierIdentifier =
1917 carrierRestrictionRules.getAllowedCarriers().get(0);
1918 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1919 carrierIdentifier);
1920 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1921 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1922 }
1923 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1924 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1925 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001926 lockStatus = TelephonyManager
1927 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001928 }
1929 } else {
1930 Rlog.e(LOG_TAG,
1931 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1932 }
1933 callback.accept(lockStatus);
1934 } else {
1935 // This is for the implementation of getAllowedCarriers.
1936 notifyRequester(request);
1937 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001938 break;
1939
Nathan Haroldb3014052017-01-25 15:57:32 -08001940 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1941 ar = (AsyncResult) msg.obj;
1942 request = (MainThreadRequest) ar.userObj;
1943 if (ar.exception == null && ar.result != null) {
1944 request.result = ar.result;
1945 } else {
1946 request.result = new IllegalArgumentException(
1947 "Failed to retrieve Forbidden Plmns");
1948 if (ar.result == null) {
1949 loge("getForbiddenPlmns: Empty response");
1950 } else {
1951 loge("getForbiddenPlmns: Unknown exception");
1952 }
1953 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001954 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001955 break;
1956
1957 case CMD_GET_FORBIDDEN_PLMNS:
1958 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001959 uiccPort = getUiccPortFromRequest(request);
1960 if (uiccPort == null) {
1961 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001962 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001963 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001964 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001965 break;
1966 }
1967 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001968 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001969 if (uiccApp == null) {
1970 loge("getForbiddenPlmns() no app with specified type -- "
1971 + appType);
1972 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001973 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001974 break;
1975 } else {
1976 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1977 + " specified type -- " + appType);
1978 }
1979 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1980 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001981 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001982 break;
1983
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001984 case CMD_SWITCH_SLOTS:
1985 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001986 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001987 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001988 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001989 break;
1990
1991 case EVENT_SWITCH_SLOTS_DONE:
1992 ar = (AsyncResult) msg.obj;
1993 request = (MainThreadRequest) ar.userObj;
1994 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001995 notifyRequester(request);
1996 break;
1997 case CMD_GET_NETWORK_SELECTION_MODE:
1998 request = (MainThreadRequest) msg.obj;
1999 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
2000 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
2001 break;
2002
2003 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
2004 ar = (AsyncResult) msg.obj;
2005 request = (MainThreadRequest) ar.userObj;
2006 if (ar.exception != null) {
2007 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2008 } else {
2009 int mode = ((int[]) ar.result)[0];
2010 if (mode == 0) {
2011 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
2012 } else {
2013 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
2014 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00002015 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002016 notifyRequester(request);
2017 break;
2018 case CMD_GET_CDMA_ROAMING_MODE:
2019 request = (MainThreadRequest) msg.obj;
2020 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
2021 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
2022 break;
2023 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
2024 ar = (AsyncResult) msg.obj;
2025 request = (MainThreadRequest) ar.userObj;
2026 if (ar.exception != null) {
2027 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
2028 } else {
2029 request.result = ((int[]) ar.result)[0];
2030 }
2031 notifyRequester(request);
2032 break;
2033 case CMD_SET_CDMA_ROAMING_MODE:
2034 request = (MainThreadRequest) msg.obj;
2035 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
2036 int mode = (int) request.argument;
2037 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
2038 break;
2039 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
2040 ar = (AsyncResult) msg.obj;
2041 request = (MainThreadRequest) ar.userObj;
2042 request.result = ar.exception == null;
2043 notifyRequester(request);
2044 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07002045 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
2046 request = (MainThreadRequest) msg.obj;
2047 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
2048 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
2049 break;
2050 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
2051 ar = (AsyncResult) msg.obj;
2052 request = (MainThreadRequest) ar.userObj;
2053 if (ar.exception != null) {
2054 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
2055 } else {
2056 request.result = ((int[]) ar.result)[0];
2057 }
2058 notifyRequester(request);
2059 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07002060 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
2061 request = (MainThreadRequest) msg.obj;
2062 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
2063 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07002064 getPhoneFromRequest(request).setCdmaSubscriptionMode(
2065 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07002066 break;
2067 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
2068 ar = (AsyncResult) msg.obj;
2069 request = (MainThreadRequest) ar.userObj;
2070 request.result = ar.exception == null;
2071 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00002072 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07002073 case CMD_GET_ALL_CELL_INFO:
2074 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07002075 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07002076 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07002077 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07002078 case EVENT_GET_ALL_CELL_INFO_DONE:
2079 ar = (AsyncResult) msg.obj;
2080 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07002081 // If a timeout occurs, the response will be null
2082 request.result = (ar.exception == null && ar.result != null)
2083 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07002084 synchronized (request) {
2085 request.notifyAll();
2086 }
2087 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002088 case CMD_REQUEST_CELL_INFO_UPDATE:
2089 request = (MainThreadRequest) msg.obj;
2090 request.phone.requestCellInfoUpdate(request.workSource,
2091 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
2092 break;
2093 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
2094 ar = (AsyncResult) msg.obj;
2095 request = (MainThreadRequest) ar.userObj;
2096 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
2097 try {
2098 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002099 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07002100 cb.onError(
2101 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
2102 ar.exception.getClass().getName(),
2103 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002104 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002105 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07002106 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002107 } else {
2108 // use the result as returned
2109 cb.onCellInfo((List<CellInfo>) ar.result);
2110 }
2111 } catch (RemoteException re) {
2112 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
2113 }
2114 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08002115 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07002116 request = (MainThreadRequest) msg.obj;
2117 WorkSource ws = (WorkSource) request.argument;
2118 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08002119 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07002120 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08002121 }
2122 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07002123 ar = (AsyncResult) msg.obj;
2124 request = (MainThreadRequest) ar.userObj;
2125 if (ar.exception == null) {
2126 request.result = ar.result;
2127 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08002128 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07002129 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08002130 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07002131 }
2132
2133 synchronized (request) {
2134 request.notifyAll();
2135 }
2136 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08002137 }
chen xu6dac5ab2018-10-26 17:39:23 -07002138 case CMD_MODEM_REBOOT:
2139 request = (MainThreadRequest) msg.obj;
2140 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002141 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07002142 break;
chen xu6dac5ab2018-10-26 17:39:23 -07002143 case EVENT_CMD_MODEM_REBOOT_DONE:
2144 handleNullReturnEvent(msg, "rebootModem");
2145 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002146 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002147 request = (MainThreadRequest) msg.obj;
2148 boolean enable = (boolean) request.argument;
2149 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08002150 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002151 PhoneConfigurationManager.getInstance()
2152 .enablePhone(request.phone, enable, onCompleted);
2153 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002154 }
Michele Berionne5e411512020-11-13 02:36:59 +00002155 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002156 ar = (AsyncResult) msg.obj;
2157 request = (MainThreadRequest) ar.userObj;
2158 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07002159 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08002160 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07002161 if ((boolean) request.result) {
2162 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
2163 updateModemStateMetrics();
2164 } else {
2165 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
2166 + ar.exception);
2167 }
2168 notifyRequester(request);
2169 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002170 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07002171 case CMD_GET_MODEM_STATUS:
2172 request = (MainThreadRequest) msg.obj;
2173 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
2174 PhoneConfigurationManager.getInstance()
2175 .getPhoneStatusFromModem(request.phone, onCompleted);
2176 break;
2177 case EVENT_GET_MODEM_STATUS_DONE:
2178 ar = (AsyncResult) msg.obj;
2179 request = (MainThreadRequest) ar.userObj;
2180 int id = request.phone.getPhoneId();
2181 if (ar.exception == null && ar.result != null) {
2182 request.result = ar.result;
2183 //update the cache as modem status has changed
2184 mPhoneConfigurationManager.addToPhoneStatusCache(id,
2185 (boolean) request.result);
2186 } else {
2187 // Return true if modem status cannot be retrieved. For most cases,
2188 // modem status is on. And for older version modems, GET_MODEM_STATUS
2189 // and disable modem are not supported. Modem is always on.
2190 // TODO: this should be fixed in R to support a third
2191 // status UNKNOWN b/131631629
2192 request.result = true;
2193 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
2194 + ar.exception);
2195 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002196 notifyRequester(request);
2197 break;
Hall Liu73f5d362020-01-20 13:42:00 -08002198 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
2199 request = (MainThreadRequest) msg.obj;
2200 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
2201 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
2202 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
2203 request.phone.setSystemSelectionChannels(args.first, onCompleted);
2204 break;
2205 }
2206 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
2207 ar = (AsyncResult) msg.obj;
2208 request = (MainThreadRequest) ar.userObj;
2209 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
2210 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
2211 args.second.accept(ar.exception == null);
2212 notifyRequester(request);
2213 break;
2214 }
Sarah Chin679c08a2020-11-18 13:39:35 -08002215 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
2216 request = (MainThreadRequest) msg.obj;
2217 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
2218 Phone phone = getPhoneFromRequest(request);
2219 if (phone != null) {
2220 phone.getSystemSelectionChannels(onCompleted);
2221 } else {
2222 loge("getSystemSelectionChannels: No phone object");
2223 request.result = new ArrayList<RadioAccessSpecifier>();
2224 notifyRequester(request);
2225 }
2226 break;
2227 }
2228 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
2229 ar = (AsyncResult) msg.obj;
2230 request = (MainThreadRequest) ar.userObj;
2231 if (ar.exception == null && ar.result != null) {
2232 request.result = ar.result;
2233 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08002234 request.result = new IllegalStateException(
2235 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08002236 if (ar.result == null) {
2237 loge("getSystemSelectionChannels: Empty response");
2238 } else {
2239 loge("getSystemSelectionChannels: Unknown exception");
2240 }
2241 }
2242 notifyRequester(request);
2243 break;
yincheng zhao2737e882019-09-06 17:06:54 -07002244 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
2245 ar = (AsyncResult) msg.obj;
2246 request = (MainThreadRequest) ar.userObj;
2247 if (ar.exception == null && ar.result != null) {
2248 request.result = ar.result;
2249 } else {
2250 request.result = -1;
2251 loge("Failed to set Forbidden Plmns");
2252 if (ar.result == null) {
2253 loge("setForbidenPlmns: Empty response");
2254 } else if (ar.exception != null) {
2255 loge("setForbiddenPlmns: Exception: " + ar.exception);
2256 request.result = -1;
2257 } else {
2258 loge("setForbiddenPlmns: Unknown exception");
2259 }
2260 }
2261 notifyRequester(request);
2262 break;
2263 case CMD_SET_FORBIDDEN_PLMNS:
2264 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002265 uiccPort = getUiccPortFromRequest(request);
2266 if (uiccPort == null) {
2267 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07002268 request.result = -1;
2269 notifyRequester(request);
2270 break;
2271 }
2272 Pair<Integer, List<String>> setFplmnsArgs =
2273 (Pair<Integer, List<String>>) request.argument;
2274 appType = setFplmnsArgs.first;
2275 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002276 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07002277 if (uiccApp == null) {
2278 loge("setForbiddenPlmns: no app with specified type -- " + appType);
2279 request.result = -1;
2280 loge("Failed to get UICC App");
2281 notifyRequester(request);
2282 } else {
2283 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
2284 ((SIMRecords) uiccApp.getIccRecords())
2285 .setForbiddenPlmns(onCompleted, fplmns);
2286 }
yinchengzhao4d163c02019-12-12 15:21:47 -08002287 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07002288 case CMD_ERASE_MODEM_CONFIG:
2289 request = (MainThreadRequest) msg.obj;
2290 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
2291 defaultPhone.eraseModemConfig(onCompleted);
2292 break;
2293 case EVENT_ERASE_MODEM_CONFIG_DONE:
2294 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07002295 break;
zoey chene02881a2019-12-30 16:11:23 +08002296
Kai Shif70f46f2021-03-03 13:59:46 -08002297 case CMD_ERASE_DATA_SHARED_PREFERENCES:
2298 request = (MainThreadRequest) msg.obj;
2299 request.result = defaultPhone.eraseDataInSharedPreferences();
2300 notifyRequester(request);
2301 break;
2302
zoey chene02881a2019-12-30 16:11:23 +08002303 case CMD_CHANGE_ICC_LOCK_PASSWORD:
2304 request = (MainThreadRequest) msg.obj;
2305 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
2306 Pair<String, String> changed = (Pair<String, String>) request.argument;
2307 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
2308 changed.first, changed.second, onCompleted);
2309 break;
2310 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2311 ar = (AsyncResult) msg.obj;
2312 request = (MainThreadRequest) ar.userObj;
2313 if (ar.exception == null) {
2314 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002315 // If the operation is successful, update the PIN storage
2316 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2317 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002318 UiccController.getInstance().getPinStorage()
2319 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002320 } else {
2321 request.result = msg.arg1;
2322 }
2323 notifyRequester(request);
2324 break;
2325
Michele Berionne5e411512020-11-13 02:36:59 +00002326 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002327 request = (MainThreadRequest) msg.obj;
2328 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2329 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2330 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2331 enabled.first, enabled.second, onCompleted);
2332 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002333 }
zoey chene02881a2019-12-30 16:11:23 +08002334 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2335 ar = (AsyncResult) msg.obj;
2336 request = (MainThreadRequest) ar.userObj;
2337 if (ar.exception == null) {
2338 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002339 // If the operation is successful, update the PIN storage
2340 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2341 int phoneId = getPhoneFromRequest(request).getPhoneId();
2342 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002343 UiccController.getInstance().getPinStorage()
2344 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002345 } else {
2346 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2347 }
zoey chene02881a2019-12-30 16:11:23 +08002348 } else {
2349 request.result = msg.arg1;
2350 }
Michele Berionne5e411512020-11-13 02:36:59 +00002351
2352
zoey chene02881a2019-12-30 16:11:23 +08002353 notifyRequester(request);
2354 break;
2355
Peter Wangdafb9ac2020-01-15 14:13:38 -08002356 case MSG_NOTIFY_USER_ACTIVITY:
2357 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002358 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002359 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2360 getDefaultPhone().getContext().sendBroadcastAsUser(
2361 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2362 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002363
2364 case CMD_SET_DATA_THROTTLING: {
2365 request = (MainThreadRequest) msg.obj;
2366 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2367 DataThrottlingRequest dataThrottlingRequest =
2368 (DataThrottlingRequest) request.argument;
2369 Phone phone = getPhoneFromRequest(request);
2370 if (phone != null) {
2371 phone.setDataThrottling(onCompleted,
2372 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2373 dataThrottlingRequest.getCompletionDurationMillis());
2374 } else {
2375 loge("setDataThrottling: No phone object");
2376 request.result =
2377 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2378 notifyRequester(request);
2379 }
2380
2381 break;
2382 }
2383 case EVENT_SET_DATA_THROTTLING_DONE:
2384 ar = (AsyncResult) msg.obj;
2385 request = (MainThreadRequest) ar.userObj;
2386
2387 if (ar.exception == null) {
2388 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2389 } else if (ar.exception instanceof CommandException) {
2390 loge("setDataThrottling: CommandException: " + ar.exception);
2391 CommandException.Error error =
2392 ((CommandException) (ar.exception)).getCommandError();
2393
2394 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2395 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002396 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002397 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2398 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002399 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2400 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002401 } else {
2402 request.result =
2403 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2404 }
2405 } else {
2406 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2407 }
2408 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2409 notifyRequester(request);
2410 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002411
2412 case CMD_SET_SIM_POWER: {
2413 request = (MainThreadRequest) msg.obj;
2414 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2415 request = (MainThreadRequest) msg.obj;
2416 int stateToSet =
2417 ((Pair<Integer, IIntegerConsumer>)
2418 request.argument).first;
2419 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2420 break;
2421 }
2422 case EVENT_SET_SIM_POWER_DONE: {
2423 ar = (AsyncResult) msg.obj;
2424 request = (MainThreadRequest) ar.userObj;
2425 IIntegerConsumer callback =
2426 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2427 if (ar.exception != null) {
2428 loge("setSimPower exception: " + ar.exception);
2429 int errorCode = TelephonyManager.CallForwardingInfoCallback
2430 .RESULT_ERROR_UNKNOWN;
2431 if (ar.exception instanceof CommandException) {
2432 CommandException.Error error =
2433 ((CommandException) (ar.exception)).getCommandError();
2434 if (error == CommandException.Error.SIM_ERR) {
2435 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2436 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2437 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2438 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2439 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2440 } else {
2441 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2442 }
2443 }
2444 try {
2445 callback.accept(errorCode);
2446 } catch (RemoteException e) {
2447 // Ignore if the remote process is no longer available to call back.
2448 Log.w(LOG_TAG, "setSimPower: callback not available.");
2449 }
2450 } else {
2451 try {
2452 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2453 } catch (RemoteException e) {
2454 // Ignore if the remote process is no longer available to call back.
2455 Log.w(LOG_TAG, "setSimPower: callback not available.");
2456 }
2457 }
2458 break;
2459 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002460 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2461 request = (MainThreadRequest) msg.obj;
2462
2463 final Phone phone = getPhoneFromRequest(request);
2464 if (phone == null || phone.getServiceStateTracker() == null) {
2465 request.result = new IllegalStateException("Phone or SST is null");
2466 notifyRequester(request);
2467 break;
2468 }
2469
2470 Pair<Integer, SignalStrengthUpdateRequest> pair =
2471 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2472 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2473 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002474 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002475 request.subId, pair.first /*callingUid*/,
2476 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002477 break;
2478 }
2479 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2480 ar = (AsyncResult) msg.obj;
2481 request = (MainThreadRequest) ar.userObj;
2482 // request.result will be the exception of ar if present, true otherwise.
2483 // Be cautious not to leave result null which will wait() forever
2484 request.result = ar.exception != null ? ar.exception : true;
2485 notifyRequester(request);
2486 break;
2487 }
2488 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2489 request = (MainThreadRequest) msg.obj;
2490
2491 Phone phone = getPhoneFromRequest(request);
2492 if (phone == null || phone.getServiceStateTracker() == null) {
2493 request.result = new IllegalStateException("Phone or SST is null");
2494 notifyRequester(request);
2495 break;
2496 }
2497
2498 Pair<Integer, SignalStrengthUpdateRequest> pair =
2499 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2500 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2501 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002502 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002503 request.subId, pair.first /*callingUid*/,
2504 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002505 break;
2506 }
2507 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2508 ar = (AsyncResult) msg.obj;
2509 request = (MainThreadRequest) ar.userObj;
2510 request.result = ar.exception != null ? ar.exception : true;
2511 notifyRequester(request);
2512 break;
2513 }
Jordan Liu109698e2020-11-24 14:50:34 -08002514
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002515 case CMD_GET_SLICING_CONFIG: {
2516 request = (MainThreadRequest) msg.obj;
2517 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2518 request.phone.getSlicingConfig(onCompleted);
2519 break;
2520 }
2521 case EVENT_GET_SLICING_CONFIG_DONE: {
2522 ar = (AsyncResult) msg.obj;
2523 request = (MainThreadRequest) ar.userObj;
2524 ResultReceiver result = (ResultReceiver) request.argument;
2525
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002526 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002527 Bundle bundle = new Bundle();
2528 int resultCode = 0;
2529 if (ar.exception != null) {
2530 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2531 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002532 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002533 } else if (ar.result == null) {
2534 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002535 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002536 } else {
2537 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002538 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2539 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002540 }
2541
2542 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002543 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002544 }
2545 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2546 result.send(resultCode, bundle);
2547 notifyRequester(request);
2548 break;
2549 }
2550
Sarah Chin71b3a852022-09-28 15:54:19 -07002551 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002552 request = (MainThreadRequest) msg.obj;
2553 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002554 PurchasePremiumCapabilityArgument arg =
2555 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002556 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chinb8218c22023-01-04 13:35:29 -08002557 arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002558 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002559 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002560
Sarah Chin71b3a852022-09-28 15:54:19 -07002561 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002562 ar = (AsyncResult) msg.obj;
2563 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002564 PurchasePremiumCapabilityArgument arg =
2565 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002566 try {
2567 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002568 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002569 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002570 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002571 + ", result= "
2572 + TelephonyManager.convertPurchaseResultToString(result));
2573 } catch (RemoteException e) {
2574 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002575 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002576 + " failed: " + e;
2577 if (DBG) log(logStr);
2578 AnomalyReporter.reportAnomaly(
2579 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2580 }
2581 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002582 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002583
Michele Berionne5e411512020-11-13 02:36:59 +00002584 case CMD_PREPARE_UNATTENDED_REBOOT:
2585 request = (MainThreadRequest) msg.obj;
2586 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002587 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002588 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002589 notifyRequester(request);
2590 break;
2591
Sarah Chineccfbd12023-01-20 19:00:35 -08002592 case CMD_START_SATELLITE_POSITION_UPDATES: {
2593 request = (MainThreadRequest) msg.obj;
2594 onCompleted =
2595 obtainMessage(EVENT_START_SATELLITE_POSITION_UPDATES_DONE, request);
Sarah Chin4beb2b72023-02-14 14:47:54 -08002596 if (mIsSatelliteServiceSupported) {
2597 mSatelliteServiceController.startSendingSatellitePointingInfo(onCompleted);
2598 break;
2599 }
Sarah Chineccfbd12023-01-20 19:00:35 -08002600 Phone phone = getPhoneFromRequest(request);
2601 if (phone != null) {
2602 phone.startSatellitePositionUpdates(onCompleted);
2603 } else {
2604 loge("startSatellitePositionUpdates: No phone object");
Thomas Nguyen299d6cd2023-02-14 09:57:15 -08002605 SatellitePositionUpdateArgument arg =
2606 (SatellitePositionUpdateArgument) request.argument;
2607 arg.errorCallback.accept(
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002608 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Sarah Chineccfbd12023-01-20 19:00:35 -08002609 }
2610 break;
2611 }
2612
2613 case EVENT_START_SATELLITE_POSITION_UPDATES_DONE: {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -08002614 handleStartSatellitePositionUpdatesDone((AsyncResult) msg.obj);
Sarah Chineccfbd12023-01-20 19:00:35 -08002615 break;
2616 }
2617
2618 case CMD_STOP_SATELLITE_POSITION_UPDATES: {
2619 request = (MainThreadRequest) msg.obj;
2620 onCompleted =
2621 obtainMessage(EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE, request);
Sarah Chin4beb2b72023-02-14 14:47:54 -08002622 if (mIsSatelliteServiceSupported) {
2623 mSatelliteServiceController.stopSendingSatellitePointingInfo(onCompleted);
2624 break;
2625 }
Sarah Chineccfbd12023-01-20 19:00:35 -08002626 Phone phone = getPhoneFromRequest(request);
2627 if (phone != null) {
2628 phone.stopSatellitePositionUpdates(onCompleted);
2629 } else {
2630 loge("stopSatellitePositionUpdates: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002631 ((Consumer<Integer>) request.argument).accept(
2632 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Sarah Chineccfbd12023-01-20 19:00:35 -08002633 }
2634 break;
2635 }
2636
2637 case EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE: {
2638 ar = (AsyncResult) msg.obj;
2639 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002640 int error = getSatelliteError(ar, "stopSatellitePositionUpdates", false);
2641 ((Consumer<Integer>) request.argument).accept(error);
Sarah Chineccfbd12023-01-20 19:00:35 -08002642 break;
2643 }
2644
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002645 case CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG: {
2646 request = (MainThreadRequest) msg.obj;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002647 onCompleted =
2648 obtainMessage(EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE, request);
2649 if (mIsSatelliteServiceSupported) {
2650 mSatelliteServiceController
2651 .requestMaxCharactersPerMOTextMessage(onCompleted);
2652 break;
2653 }
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002654 Phone phone = getPhoneFromRequest(request);
2655 if (phone != null) {
2656 phone.getMaxCharactersPerSatelliteTextMessage(onCompleted);
2657 } else {
2658 loge("getMaxCharactersPerSatelliteTextMessage: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002659 ((ResultReceiver) request.argument).send(
2660 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002661 }
2662 break;
2663 }
2664
2665 case EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE: {
2666 ar = (AsyncResult) msg.obj;
2667 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002668 int error =
2669 getSatelliteError(ar, "getMaxCharactersPerSatelliteTextMessage", true);
2670 Bundle bundle = new Bundle();
2671 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002672 int maxCharLimit = ((int[]) ar.result)[0];
Sarah Chin503828c2023-02-01 23:54:20 -08002673 if (DBG) log("getMaxCharactersPerSatelliteTextMessage: " + maxCharLimit);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002674 bundle.putInt(SatelliteManager.KEY_MAX_CHARACTERS_PER_SATELLITE_TEXT,
2675 maxCharLimit);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002676 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002677 ((ResultReceiver) request.argument).send(error, bundle);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002678 break;
2679 }
2680
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002681 case CMD_PROVISION_SATELLITE_SERVICE: {
2682 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002683 ProvisionSatelliteServiceArgument argument =
2684 (ProvisionSatelliteServiceArgument) request.argument;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002685 if (mSatelliteProvisionCallbacks.containsKey(argument.subId)) {
2686 argument.callback.accept(
2687 SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS);
2688 notifyRequester(request);
2689 break;
2690 }
2691 mSatelliteProvisionCallbacks.put(argument.subId, argument.callback);
2692 onCompleted = obtainMessage(EVENT_PROVISION_SATELLITE_SERVICE_DONE, request);
2693 if (mIsSatelliteServiceSupported) {
2694 mSatelliteServiceController
2695 .provisionSatelliteService(argument.token, onCompleted);
2696 break;
2697 }
2698 Phone phone = getPhoneFromRequest(request);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002699 if (phone != null) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08002700 phone.provisionSatelliteService(onCompleted, argument.token);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002701 } else {
2702 loge("provisionSatelliteService: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002703 argument.callback.accept(
2704 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002705 notifyRequester(request);
2706 }
2707 break;
2708 }
2709
2710 case EVENT_PROVISION_SATELLITE_SERVICE_DONE: {
2711 ar = (AsyncResult) msg.obj;
2712 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002713 int errorCode = getSatelliteError(ar, "provisionSatelliteService", false);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002714 handleEventProvisionSatelliteServiceDone(
2715 (ProvisionSatelliteServiceArgument) request.argument, errorCode);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002716 notifyRequester(request);
2717 break;
2718 }
2719
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002720 case CMD_DEPROVISION_SATELLITE_SERVICE: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002721 request = (MainThreadRequest) msg.obj;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002722 ProvisionSatelliteServiceArgument argument =
2723 (ProvisionSatelliteServiceArgument) request.argument;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002724 onCompleted = obtainMessage(EVENT_DEPROVISION_SATELLITE_SERVICE_DONE, request);
2725 if (mIsSatelliteServiceSupported) {
2726 mSatelliteServiceController
2727 .deprovisionSatelliteService(argument.token, onCompleted);
2728 break;
2729 }
2730 Phone phone = getPhoneFromRequest(request);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002731 if (phone != null) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08002732 phone.deprovisionSatelliteService(onCompleted, argument.token);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002733 } else {
2734 loge("deprovisionSatelliteService: No phone object");
2735 if (argument.callback != null) {
2736 argument.callback.accept(
2737 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
2738 }
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002739 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002740 break;
2741 }
2742
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002743 case EVENT_DEPROVISION_SATELLITE_SERVICE_DONE: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002744 ar = (AsyncResult) msg.obj;
2745 request = (MainThreadRequest) ar.userObj;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002746 int errorCode = getSatelliteError(ar, "deprovisionSatelliteService", false);
2747 handleEventDeprovisionSatelliteServiceDone(
2748 (ProvisionSatelliteServiceArgument) request.argument, errorCode);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002749 break;
2750 }
2751
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002752 case CMD_SET_SATELLITE_ENABLED: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002753 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002754 Pair<Boolean, Consumer<Integer>> argument =
2755 (Pair<Boolean, Consumer<Integer>>) request.argument;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002756 onCompleted = obtainMessage(EVENT_SET_SATELLITE_ENABLED_DONE, request);
2757 if (mIsSatelliteServiceSupported) {
2758 mSatelliteServiceController
2759 .requestSatelliteEnabled(argument.first, onCompleted);
2760 break;
2761 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002762 Phone phone = getPhoneFromRequest(request);
2763 if (phone != null) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08002764 phone.setSatellitePower(onCompleted, argument.first);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002765 } else {
Sarah Chin4beb2b72023-02-14 14:47:54 -08002766 loge("requestSatelliteEnabled: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002767 argument.second.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002768 }
2769 break;
2770 }
2771
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002772 case EVENT_SET_SATELLITE_ENABLED_DONE: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002773 ar = (AsyncResult) msg.obj;
2774 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002775 Pair<Boolean, Consumer<Integer>> argument =
2776 (Pair<Boolean, Consumer<Integer>>) request.argument;
2777 int error = getSatelliteError(ar, "setSatelliteEnabled", false);
2778 argument.second.accept(error);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002779 break;
2780 }
2781
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002782 case CMD_IS_SATELLITE_ENABLED: {
Sarah Chin503828c2023-02-01 23:54:20 -08002783 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002784 onCompleted = obtainMessage(EVENT_IS_SATELLITE_ENABLED_DONE, request);
Sarah Chin4beb2b72023-02-14 14:47:54 -08002785 if (mIsSatelliteServiceSupported) {
2786 mSatelliteServiceController.requestIsSatelliteEnabled(onCompleted);
2787 break;
2788 }
Sarah Chin503828c2023-02-01 23:54:20 -08002789 Phone phone = getPhoneFromRequest(request);
2790 if (phone != null) {
2791 phone.isSatellitePowerOn(onCompleted);
2792 } else {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002793 loge("isSatelliteEnabled: No phone object");
2794 ((ResultReceiver) request.argument).send(
2795 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002796 }
2797 break;
2798 }
2799
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002800 case EVENT_IS_SATELLITE_ENABLED_DONE: {
Sarah Chin503828c2023-02-01 23:54:20 -08002801 ar = (AsyncResult) msg.obj;
2802 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002803 int error = getSatelliteError(ar, "isSatelliteEnabled", true);
2804 Bundle bundle = new Bundle();
2805 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
2806 boolean enabled = ((int[]) ar.result)[0] == 1;
2807 if (DBG) log("isSatelliteEnabled: " + enabled);
2808 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_ENABLED, enabled);
Sarah Chin503828c2023-02-01 23:54:20 -08002809 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002810 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002811 break;
2812 }
2813
2814 case CMD_IS_SATELLITE_SUPPORTED: {
2815 request = (MainThreadRequest) msg.obj;
2816 onCompleted = obtainMessage(EVENT_IS_SATELLITE_SUPPORTED_DONE, request);
Sarah Chin4beb2b72023-02-14 14:47:54 -08002817 if (mIsSatelliteServiceSupported) {
2818 mSatelliteServiceController.requestIsSatelliteSupported(onCompleted);
2819 break;
2820 }
Sarah Chin503828c2023-02-01 23:54:20 -08002821 Phone phone = getPhoneFromRequest(request);
2822 if (phone != null) {
2823 phone.isSatelliteSupported(onCompleted);
2824 } else {
2825 loge("isSatelliteSupported: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002826 ((ResultReceiver) request.argument).send(
2827 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002828 }
2829 break;
2830 }
2831
2832 case EVENT_IS_SATELLITE_SUPPORTED_DONE: {
2833 ar = (AsyncResult) msg.obj;
2834 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002835 int error = getSatelliteError(ar, "isSatelliteSupported", true);
2836 Bundle bundle = new Bundle();
2837 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
2838 boolean supported = ((int[]) ar.result)[0] == 1;
2839 if (DBG) log("isSatelliteSupported: " + supported);
2840 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, supported);
Thomas Nguyene77de6d2023-02-10 17:42:43 -08002841 synchronized (mIsSatelliteSupportedLock) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002842 mIsSatelliteSupported = supported;
2843 }
2844 } else {
2845 synchronized (mIsSatelliteSupportedLock) {
2846 mIsSatelliteSupported = null;
Thomas Nguyene77de6d2023-02-10 17:42:43 -08002847 }
Sarah Chin503828c2023-02-01 23:54:20 -08002848 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002849 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002850 break;
2851 }
2852
2853 case CMD_GET_SATELLITE_CAPABILITIES: {
2854 request = (MainThreadRequest) msg.obj;
2855 onCompleted = obtainMessage(EVENT_GET_SATELLITE_CAPABILITIES_DONE, request);
Sarah Chin4beb2b72023-02-14 14:47:54 -08002856 if (mIsSatelliteServiceSupported) {
2857 mSatelliteServiceController.requestSatelliteCapabilities(onCompleted);
2858 break;
2859 }
Sarah Chin503828c2023-02-01 23:54:20 -08002860 Phone phone = getPhoneFromRequest(request);
2861 if (phone != null) {
2862 phone.getSatelliteCapabilities(onCompleted);
2863 } else {
2864 loge("getSatelliteCapabilities: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002865 ((ResultReceiver) request.argument).send(
2866 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002867 }
2868 break;
2869 }
2870
2871 case EVENT_GET_SATELLITE_CAPABILITIES_DONE: {
2872 ar = (AsyncResult) msg.obj;
2873 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002874 int error = getSatelliteError(ar, "getSatelliteCapabilities", true);
2875 Bundle bundle = new Bundle();
2876 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
Sarah Chin503828c2023-02-01 23:54:20 -08002877 SatelliteCapabilities capabilities = (SatelliteCapabilities) ar.result;
2878 if (DBG) log("getSatelliteCapabilities: " + capabilities);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002879 bundle.putParcelable(SatelliteManager.KEY_SATELLITE_CAPABILITIES,
2880 capabilities);
Sarah Chin503828c2023-02-01 23:54:20 -08002881 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002882 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002883 break;
2884 }
2885
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +00002886 case CMD_POLL_PENDING_SATELLITE_DATAGRAMS: {
2887 request = (MainThreadRequest) msg.obj;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002888 onCompleted =
2889 obtainMessage(EVENT_POLL_PENDING_SATELLITE_DATAGRAMS_DONE, request);
2890 if (mIsSatelliteServiceSupported) {
2891 mSatelliteServiceController.pollPendingSatelliteDatagrams(onCompleted);
2892 break;
2893 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +00002894 Phone phone = getPhoneFromRequest(request);
2895 if (phone != null) {
2896 phone.pollPendingSatelliteDatagrams(onCompleted);
2897 } else {
2898 loge("pollPendingSatelliteDatagrams: No phone object");
Sarah Chin4beb2b72023-02-14 14:47:54 -08002899 ((Consumer<Integer>) request.argument).accept(
2900 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +00002901 }
2902 break;
2903 }
2904
2905 case EVENT_POLL_PENDING_SATELLITE_DATAGRAMS_DONE: {
2906 ar = (AsyncResult) msg.obj;
2907 request = (MainThreadRequest) ar.userObj;
Aishwarya Mallampati224317a2023-02-13 22:09:30 +00002908 int error = getSatelliteError(ar, "pollPendingSatelliteDatagrams", false);
2909 ((Consumer<Integer>) request.argument).accept(error);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +00002910 break;
2911 }
2912
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +00002913 case CMD_SEND_SATELLITE_DATAGRAM: {
2914 request = (MainThreadRequest) msg.obj;
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +00002915 SendSatelliteDatagramArgument argument =
2916 (SendSatelliteDatagramArgument) request.argument;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002917 onCompleted = obtainMessage(EVENT_SEND_SATELLITE_DATAGRAM_DONE, request);
2918 if (mIsSatelliteServiceSupported) {
2919 // TODO: set isEmergency properly
2920 mSatelliteServiceController
2921 .sendSatelliteDatagram(argument.datagram, false, onCompleted);
2922 break;
2923 }
2924 Phone phone = getPhoneFromRequest(request);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +00002925 if (phone != null) {
2926 phone.sendSatelliteDatagram(onCompleted, argument.datagram);
2927 } else {
2928 loge("sendSatelliteDatagram: No phone object");
Sarah Chin4beb2b72023-02-14 14:47:54 -08002929 argument.callback.accept(
2930 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +00002931 }
2932 break;
2933 }
2934
2935 case EVENT_SEND_SATELLITE_DATAGRAM_DONE: {
2936 ar = (AsyncResult) msg.obj;
2937 request = (MainThreadRequest) ar.userObj;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002938 int error = getSatelliteError(ar, "sendSatelliteDatagram", false);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +00002939 SendSatelliteDatagramArgument argument =
2940 (SendSatelliteDatagramArgument) request.argument;
2941 argument.callback.accept(error);
2942 break;
2943 }
2944
Sarah Chindf715ec2023-02-13 13:46:24 -08002945 case CMD_IS_SATELLITE_COMMUNICATION_ALLOWED: {
2946 request = (MainThreadRequest) msg.obj;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002947 onCompleted =
2948 obtainMessage(EVENT_IS_SATELLITE_COMMUNICATION_ALLOWED_DONE, request);
2949 if (mIsSatelliteServiceSupported) {
2950 mSatelliteServiceController
2951 .requestIsSatelliteCommunicationAllowedForCurrentLocation(
2952 onCompleted);
2953 break;
2954 }
Sarah Chindf715ec2023-02-13 13:46:24 -08002955 Phone phone = getPhoneFromRequest(request);
2956 if (phone != null) {
2957 phone.isSatelliteCommunicationAllowedForCurrentLocation(onCompleted);
2958 } else {
2959 loge("isSatelliteCommunicationAllowedForCurrentLocation: No phone object");
2960 ((ResultReceiver) request.argument).send(
2961 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
2962 }
2963 break;
2964 }
2965
2966 case EVENT_IS_SATELLITE_COMMUNICATION_ALLOWED_DONE: {
2967 ar = (AsyncResult) msg.obj;
2968 request = (MainThreadRequest) ar.userObj;
2969 int error = getSatelliteError(
2970 ar, "isSatelliteCommunicationAllowedForCurrentLocation", true);
2971 Bundle bundle = new Bundle();
2972 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
2973 boolean communicationAllowed = ((int[]) ar.result)[0] == 1;
2974 if (DBG) {
2975 log("isSatelliteCommunicationAllowedForCurrentLocation: "
2976 + communicationAllowed);
2977 }
2978 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_COMMUNICATION_ALLOWED,
2979 communicationAllowed);
2980 }
2981 ((ResultReceiver) request.argument).send(error, bundle);
2982 break;
2983 }
2984
2985 case CMD_GET_TIME_SATELLITE_NEXT_VISIBLE: {
2986 request = (MainThreadRequest) msg.obj;
2987 onCompleted = obtainMessage(EVENT_GET_TIME_SATELLITE_NEXT_VISIBLE_DONE,
2988 request);
Sarah Chin4beb2b72023-02-14 14:47:54 -08002989 if (mIsSatelliteServiceSupported) {
2990 mSatelliteServiceController
2991 .requestTimeForNextSatelliteVisibility(onCompleted);
2992 break;
2993 }
Sarah Chindf715ec2023-02-13 13:46:24 -08002994 Phone phone = getPhoneFromRequest(request);
2995 if (phone != null) {
2996 phone.requestTimeForNextSatelliteVisibility(onCompleted);
2997 } else {
2998 loge("requestTimeForNextSatelliteVisibility: No phone object");
2999 ((ResultReceiver) request.argument).send(
3000 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
3001 }
3002 break;
3003 }
3004
3005 case EVENT_GET_TIME_SATELLITE_NEXT_VISIBLE_DONE: {
3006 ar = (AsyncResult) msg.obj;
3007 request = (MainThreadRequest) ar.userObj;
3008 int error =
3009 getSatelliteError(ar, "requestTimeForNextSatelliteVisibility", true);
3010 Bundle bundle = new Bundle();
3011 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
3012 int nextVisibilityDuration = ((int[]) ar.result)[0];
3013 if (DBG) {
3014 log("requestTimeForNextSatelliteVisibility: " + nextVisibilityDuration);
3015 }
3016 bundle.putInt(SatelliteManager.KEY_SATELLITE_NEXT_VISIBILITY,
3017 nextVisibilityDuration);
3018 }
3019 ((ResultReceiver) request.argument).send(error, bundle);
3020 break;
3021 }
3022
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003023 default:
3024 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
3025 break;
3026 }
3027 }
Jake Hambye994d462014-02-03 13:10:13 -08003028
Pengquan Menga1bb6272018-09-06 09:59:22 -07003029 private void notifyRequester(MainThreadRequest request) {
3030 synchronized (request) {
3031 request.notifyAll();
3032 }
3033 }
3034
Jake Hambye994d462014-02-03 13:10:13 -08003035 private void handleNullReturnEvent(Message msg, String command) {
3036 AsyncResult ar = (AsyncResult) msg.obj;
3037 MainThreadRequest request = (MainThreadRequest) ar.userObj;
3038 if (ar.exception == null) {
3039 request.result = true;
3040 } else {
3041 request.result = false;
3042 if (ar.exception instanceof CommandException) {
3043 loge(command + ": CommandException: " + ar.exception);
3044 } else {
3045 loge(command + ": Unknown exception");
3046 }
3047 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003048 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08003049 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003050 }
3051
3052 /**
3053 * Posts the specified command to be executed on the main thread,
3054 * waits for the request to complete, and returns the result.
3055 * @see #sendRequestAsync
3056 */
3057 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08003058 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
3059 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07003060 }
3061
3062 /**
3063 * Posts the specified command to be executed on the main thread,
3064 * waits for the request to complete, and returns the result.
3065 * @see #sendRequestAsync
3066 */
3067 private Object sendRequest(int command, Object argument, WorkSource workSource) {
3068 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08003069 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07003070 }
3071
3072 /**
3073 * Posts the specified command to be executed on the main thread,
3074 * waits for the request to complete, and returns the result.
3075 * @see #sendRequestAsync
3076 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003077 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08003078 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
3079 }
3080
3081 /**
3082 * Posts the specified command to be executed on the main thread,
3083 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
3084 * if not timeout or null otherwise.
3085 * @see #sendRequestAsync
3086 */
3087 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
3088 long timeoutInMs) {
3089 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07003090 }
3091
3092 /**
3093 * Posts the specified command to be executed on the main thread,
3094 * waits for the request to complete, and returns the result.
3095 * @see #sendRequestAsync
3096 */
Nathan Harold92bed182018-10-12 18:16:49 -07003097 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08003098 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07003099 }
3100
3101 /**
3102 * Posts the specified command to be executed on the main thread,
3103 * waits for the request to complete, and returns the result.
3104 * @see #sendRequestAsync
3105 */
3106 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08003107 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
3108 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07003109 }
3110
3111 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08003112 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
3113 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
3114 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07003115 * @see #sendRequestAsync
3116 */
Rambo Wang0f050d82021-02-12 11:43:36 -08003117 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
3118 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003119 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
3120 throw new RuntimeException("This method will deadlock if called from the main thread.");
3121 }
3122
Nathan Harold92bed182018-10-12 18:16:49 -07003123 MainThreadRequest request = null;
3124 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
3125 throw new IllegalArgumentException("subId and phone cannot both be specified!");
3126 } else if (phone != null) {
3127 request = new MainThreadRequest(argument, phone, workSource);
3128 } else {
3129 request = new MainThreadRequest(argument, subId, workSource);
3130 }
3131
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003132 Message msg = mMainThreadHandler.obtainMessage(command, request);
3133 msg.sendToTarget();
3134
Rambo Wang0f050d82021-02-12 11:43:36 -08003135
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003136 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08003137 if (timeoutInMs >= 0) {
3138 // Wait for at least timeoutInMs before returning null request result
3139 long now = SystemClock.elapsedRealtime();
3140 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07003141 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08003142 try {
3143 request.wait(deadline - now);
3144 } catch (InterruptedException e) {
3145 // Do nothing, go back and check if request is completed or timeout
3146 } finally {
3147 now = SystemClock.elapsedRealtime();
3148 }
3149 }
3150 } else {
3151 // Wait for the request to complete
3152 while (request.result == null) {
3153 try {
3154 request.wait();
3155 } catch (InterruptedException e) {
3156 // Do nothing, go back and wait until the request is complete
3157 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003158 }
3159 }
3160 }
Rambo Wang0f050d82021-02-12 11:43:36 -08003161 if (request.result == null) {
3162 Log.wtf(LOG_TAG,
3163 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
3164 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003165 return request.result;
3166 }
3167
3168 /**
3169 * Asynchronous ("fire and forget") version of sendRequest():
3170 * Posts the specified command to be executed on the main thread, and
3171 * returns immediately.
3172 * @see #sendRequest
3173 */
3174 private void sendRequestAsync(int command) {
3175 mMainThreadHandler.sendEmptyMessage(command);
3176 }
3177
3178 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003179 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003180 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003181 */
3182 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003183 sendRequestAsync(command, argument, null, null);
3184 }
3185
3186 /**
3187 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
3188 * @see {@link #sendRequest(int,Object)}
3189 */
3190 private void sendRequestAsync(
3191 int command, Object argument, Phone phone, WorkSource workSource) {
3192 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003193 Message msg = mMainThreadHandler.obtainMessage(command, request);
3194 msg.sendToTarget();
3195 }
3196
3197 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003198 * Initialize the singleton PhoneInterfaceManager instance.
3199 * This is only done once, at startup, from PhoneApp.onCreate().
3200 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003201 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003202 synchronized (PhoneInterfaceManager.class) {
3203 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003204 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003205 } else {
3206 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
3207 }
3208 return sInstance;
3209 }
3210 }
3211
3212 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00003213 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003214 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003215 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00003216 mImsResolver = ImsResolver.getInstance();
Sarah Chin4beb2b72023-02-14 14:47:54 -08003217 mSatelliteServiceController = SatelliteServiceController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07003218 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003219 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
3220 mMainThreadHandler = new MainThreadHandler();
Jack Yue37dd262022-12-16 11:53:37 -08003221 if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) {
3222 mSubscriptionController = SubscriptionController.getInstance();
3223 } else {
3224 mSubscriptionController = null;
3225 }
Sarah Chin4beb2b72023-02-14 14:47:54 -08003226 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07003227 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07003228 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08003229 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08003230 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07003231 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003232 publish();
arunvoddud7401012022-12-15 16:08:12 +00003233 CarrierAllowListInfo.loadInstance(mApp);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08003234 mSatelliteSupportedReceiver = new ResultReceiver(mMainThreadHandler) {
3235 @Override
3236 protected void onReceiveResult(int resultCode, Bundle resultData) {
3237 if (resultCode == SatelliteManager.SATELLITE_ERROR_NONE
3238 && resultData.containsKey(SatelliteManager.KEY_SATELLITE_SUPPORTED)) {
3239 synchronized (mIsSatelliteSupportedLock) {
3240 mIsSatelliteSupported = resultData.getBoolean(
3241 SatelliteManager.KEY_SATELLITE_SUPPORTED);
3242 }
3243 } else {
3244 synchronized (mIsSatelliteSupportedLock) {
3245 mIsSatelliteSupported = null;
3246 }
3247 }
3248 }
3249 };
3250 requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
3251 mSatelliteSupportedReceiver);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003252 }
3253
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003254 @VisibleForTesting
3255 public SharedPreferences getSharedPreferences() {
3256 return mTelephonySharedPreferences;
3257 }
3258
Gil Cukierman92cc7db2023-01-06 19:25:53 +00003259 /**
3260 * Get the default phone for this device.
3261 */
3262 @VisibleForTesting
3263 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003264 Phone thePhone = getPhone(getDefaultSubscription());
3265 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
3266 }
3267
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003268 private void publish() {
3269 if (DBG) log("publish: " + this);
3270
Peter Wangc035ce42020-01-08 21:00:22 -08003271 TelephonyFrameworkInitializer
3272 .getTelephonyServiceManager()
3273 .getTelephonyServiceRegisterer()
3274 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003275 }
3276
Stuart Scott584921c2015-01-15 17:10:34 -08003277 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08003278 if (request.phone != null) {
3279 return request.phone;
3280 } else {
3281 return getPhoneFromSubId(request.subId);
3282 }
3283 }
3284
3285 private Phone getPhoneFromSubId(int subId) {
3286 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
3287 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08003288 }
3289
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00003290 /**
3291 * Get phone object associated with a subscription.
3292 * Return default phone if phone object associated with subscription is null
3293 * @param subId - subscriptionId
3294 * @return phone object associated with a subscription or default phone if null.
3295 */
3296 private Phone getPhoneFromSubIdOrDefault(int subId) {
3297 Phone phone = getPhoneFromSubId(subId);
3298 if (phone == null) {
3299 phone = getDefaultPhone();
3300 }
3301 return phone;
3302 }
3303
Rambo Wange53e07d2022-05-10 13:01:13 -07003304 @Nullable
3305 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003306 Phone phone = getPhoneFromRequest(request);
3307 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00003308 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003309 }
3310
Wink Saville36469e72014-06-11 15:17:00 -07003311 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07003312 private Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08003313 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07003314 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003315
Kai Shif70f46f2021-03-03 13:59:46 -08003316 private void sendEraseModemConfig(@NonNull Phone phone) {
3317 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
3318 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
3319 }
3320
3321 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
3322 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
3323 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07003324 }
3325
Peter Wang44b186e2020-01-13 23:33:09 -08003326 private boolean isImsAvailableOnDevice() {
3327 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
3328 if (pm == null) {
3329 // For some reason package manger is not available.. This will fail internally anyway,
3330 // so do not throw error and allow.
3331 return true;
3332 }
3333 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
3334 }
3335
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003336 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003337 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07003338 }
3339
Wink Savilleb564aae2014-10-23 10:18:09 -07003340 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003341 if (DBG) log("dial: " + number);
3342 // No permission check needed here: This is just a wrapper around the
3343 // ACTION_DIAL intent, which is available to any app since it puts up
3344 // the UI before it does anything.
3345
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003346 final long identity = Binder.clearCallingIdentity();
3347 try {
3348 String url = createTelUrl(number);
3349 if (url == null) {
3350 return;
3351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003352
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003353 // PENDING: should we just silently fail if phone is offhook or ringing?
3354 PhoneConstants.State state = mCM.getState(subId);
3355 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
3356 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
3357 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3358 mApp.startActivity(intent);
3359 }
3360 } finally {
3361 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003362 }
3363 }
3364
3365 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003366 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07003367 }
3368
Wink Savilleb564aae2014-10-23 10:18:09 -07003369 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003370 if (DBG) log("call: " + number);
3371
3372 // This is just a wrapper around the ACTION_CALL intent, but we still
3373 // need to do a permission check since we're calling startActivity()
3374 // from the context of the phone app.
3375 enforceCallPermission();
3376
Jordan Liu1617b712019-07-10 15:06:26 -07003377 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003378 != AppOpsManager.MODE_ALLOWED) {
3379 return;
3380 }
3381
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003382 final long identity = Binder.clearCallingIdentity();
3383 try {
3384 String url = createTelUrl(number);
3385 if (url == null) {
3386 return;
3387 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003388
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003389 boolean isValid = false;
3390 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
3391 if (slist != null) {
3392 for (SubscriptionInfo subInfoRecord : slist) {
3393 if (subInfoRecord.getSubscriptionId() == subId) {
3394 isValid = true;
3395 break;
3396 }
Wink Saville3ab207e2014-11-20 13:07:20 -08003397 }
Wink Saville08874612014-08-31 19:19:58 -07003398 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003399 if (!isValid) {
3400 return;
3401 }
Wink Saville08874612014-08-31 19:19:58 -07003402
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003403 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
3404 intent.putExtra(SUBSCRIPTION_KEY, subId);
3405 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3406 mApp.startActivity(intent);
3407 } finally {
3408 Binder.restoreCallingIdentity(identity);
3409 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003410 }
3411
Wink Savilleb564aae2014-10-23 10:18:09 -07003412 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003413 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07003414 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
3415 }
3416
Wink Savilleb564aae2014-10-23 10:18:09 -07003417 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003418 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07003419 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
3420 }
3421
Wink Savilleb564aae2014-10-23 10:18:09 -07003422 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003423 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003424
3425 final long identity = Binder.clearCallingIdentity();
3426 try {
Michele Berionne5e411512020-11-13 02:36:59 +00003427 Phone phone = getPhone(subId);
3428 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003429 checkSimPin.start();
3430 return checkSimPin.unlockSim(null, pin);
3431 } finally {
3432 Binder.restoreCallingIdentity(identity);
3433 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003434 }
3435
Wink Savilleb564aae2014-10-23 10:18:09 -07003436 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003437 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003438
3439 final long identity = Binder.clearCallingIdentity();
3440 try {
Michele Berionne5e411512020-11-13 02:36:59 +00003441 Phone phone = getPhone(subId);
3442 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003443 checkSimPuk.start();
3444 return checkSimPuk.unlockSim(puk, pin);
3445 } finally {
3446 Binder.restoreCallingIdentity(identity);
3447 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003448 }
3449
3450 /**
Wink Saville9de0f752013-10-22 19:04:03 -07003451 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003452 * a synchronous one.
3453 */
3454 private static class UnlockSim extends Thread {
3455
3456 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00003457 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003458
3459 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07003460 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
3461 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003462
3463 // For replies from SimCard interface
3464 private Handler mHandler;
3465
3466 // For async handler to identify request type
3467 private static final int SUPPLY_PIN_COMPLETE = 100;
3468
Michele Berionne5e411512020-11-13 02:36:59 +00003469 UnlockSim(int phoneId, IccCard simCard) {
3470 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003471 mSimCard = simCard;
3472 }
3473
3474 @Override
3475 public void run() {
3476 Looper.prepare();
3477 synchronized (UnlockSim.this) {
3478 mHandler = new Handler() {
3479 @Override
3480 public void handleMessage(Message msg) {
3481 AsyncResult ar = (AsyncResult) msg.obj;
3482 switch (msg.what) {
3483 case SUPPLY_PIN_COMPLETE:
3484 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
3485 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07003486 mRetryCount = msg.arg1;
3487 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08003488 CommandException.Error error = null;
3489 if (ar.exception instanceof CommandException) {
3490 error = ((CommandException) (ar.exception))
3491 .getCommandError();
3492 }
3493 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07003494 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08003495 } else if (error == CommandException.Error.ABORTED) {
3496 /* When UiccCardApp dispose, handle message and return
3497 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08003498 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07003499 } else {
3500 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
3501 }
3502 } else {
3503 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
3504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003505 mDone = true;
3506 UnlockSim.this.notifyAll();
3507 }
3508 break;
3509 }
3510 }
3511 };
3512 UnlockSim.this.notifyAll();
3513 }
3514 Looper.loop();
3515 }
3516
3517 /*
3518 * Use PIN or PUK to unlock SIM card
3519 *
3520 * If PUK is null, unlock SIM card with PIN
3521 *
3522 * If PUK is not null, unlock SIM card with PUK and set PIN code
3523 */
Wink Saville9de0f752013-10-22 19:04:03 -07003524 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003525
3526 while (mHandler == null) {
3527 try {
3528 wait();
3529 } catch (InterruptedException e) {
3530 Thread.currentThread().interrupt();
3531 }
3532 }
3533 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
3534
3535 if (puk == null) {
3536 mSimCard.supplyPin(pin, callback);
3537 } else {
3538 mSimCard.supplyPuk(puk, pin, callback);
3539 }
3540
3541 while (!mDone) {
3542 try {
3543 Log.d(LOG_TAG, "wait for done");
3544 wait();
3545 } catch (InterruptedException e) {
3546 // Restore the interrupted status
3547 Thread.currentThread().interrupt();
3548 }
3549 }
3550 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07003551 int[] resultArray = new int[2];
3552 resultArray[0] = mResult;
3553 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00003554
3555 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00003556 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00003557 }
3558
Wink Saville9de0f752013-10-22 19:04:03 -07003559 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003560 }
3561 }
3562
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003563 /**
3564 * This method has been removed due to privacy and stability concerns.
3565 */
3566 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003567 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003568 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
3569 return;
Wink Saville36469e72014-06-11 15:17:00 -07003570 }
3571
Nathan Harold1f889d82020-06-04 17:05:26 -07003572 @Override
3573 public void updateServiceLocationWithPackageName(String callingPackage) {
3574 mApp.getSystemService(AppOpsManager.class)
3575 .checkPackage(Binder.getCallingUid(), callingPackage);
3576
Nathan Haroldf096d982020-11-18 17:18:06 -08003577 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07003578 if (targetSdk > android.os.Build.VERSION_CODES.R) {
3579 // Callers targeting S have no business invoking this method.
3580 return;
3581 }
3582
3583 LocationAccessPolicy.LocationPermissionResult locationResult =
3584 LocationAccessPolicy.checkLocationPermission(mApp,
3585 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3586 .setCallingPackage(callingPackage)
3587 .setCallingFeatureId(null)
3588 .setCallingPid(Binder.getCallingPid())
3589 .setCallingUid(Binder.getCallingUid())
3590 .setMethod("updateServiceLocation")
3591 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3592 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3593 .build());
3594 // Apps that lack location permission have no business calling this method;
3595 // however, because no permission was declared in the public API, denials must
3596 // all be "soft".
3597 switch (locationResult) {
3598 case DENIED_HARD: /* fall through */
3599 case DENIED_SOFT:
3600 return;
3601 }
3602
3603 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003604 final long identity = Binder.clearCallingIdentity();
3605 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07003606 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003607 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07003608 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003609 }
3610 } finally {
3611 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003612 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003613 }
3614
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003615 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003616 @Override
3617 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003618 return isRadioOnWithFeature(callingPackage, null);
3619 }
3620
3621
3622 @Override
3623 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
3624 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
3625 callingFeatureId);
3626 }
3627
3628 @Deprecated
3629 @Override
3630 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
3631 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07003632 }
3633
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003634 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003635 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
3636 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003637 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003638 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003639 return false;
3640 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003641
3642 final long identity = Binder.clearCallingIdentity();
3643 try {
3644 return isRadioOnForSubscriber(subId);
3645 } finally {
3646 Binder.restoreCallingIdentity(identity);
3647 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003648 }
3649
3650 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003651 final long identity = Binder.clearCallingIdentity();
3652 try {
3653 final Phone phone = getPhone(subId);
3654 if (phone != null) {
3655 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
3656 } else {
3657 return false;
3658 }
3659 } finally {
3660 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003661 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003662 }
3663
3664 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003665 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003666 }
Wink Saville36469e72014-06-11 15:17:00 -07003667
Wink Savilleb564aae2014-10-23 10:18:09 -07003668 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003669 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003670
3671 final long identity = Binder.clearCallingIdentity();
3672 try {
3673 final Phone phone = getPhone(subId);
3674 if (phone != null) {
3675 phone.setRadioPower(!isRadioOnForSubscriber(subId));
3676 }
3677 } finally {
3678 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003679 }
Wink Saville36469e72014-06-11 15:17:00 -07003680 }
3681
3682 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003683 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07003684 }
3685
Wink Savilleb564aae2014-10-23 10:18:09 -07003686 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07003687 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003688
3689 final long identity = Binder.clearCallingIdentity();
3690 try {
3691 final Phone phone = getPhone(subId);
3692 if (phone == null) {
3693 return false;
3694 }
3695 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
3696 toggleRadioOnOffForSubscriber(subId);
3697 }
3698 return true;
3699 } finally {
3700 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003701 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003702 }
Wink Saville36469e72014-06-11 15:17:00 -07003703
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003704 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08003705 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003706 /*
3707 * If any of the Radios are available, it will need to be
3708 * shutdown. So return true if any Radio is available.
3709 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003710 final long identity = Binder.clearCallingIdentity();
3711 try {
3712 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3713 Phone phone = PhoneFactory.getPhone(i);
3714 if (phone != null && phone.isRadioAvailable()) return true;
3715 }
3716 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3717 return false;
3718 } finally {
3719 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003720 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003721 }
3722
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003723 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003724 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003725 enforceModifyPermission();
3726
3727 final long identity = Binder.clearCallingIdentity();
3728 try {
3729 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3730 logv("Shutting down Phone " + i);
3731 shutdownRadioUsingPhoneId(i);
3732 }
3733 } finally {
3734 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003735 }
3736 }
3737
3738 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003739 Phone phone = PhoneFactory.getPhone(phoneId);
3740 if (phone != null && phone.isRadioAvailable()) {
3741 phone.shutdownRadio();
3742 }
3743 }
3744
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003745 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003746 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003747
Ling Ma83dc5ea2023-01-12 15:06:04 -08003748 if (!turnOn) {
3749 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3750 }
3751
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003752 final long identity = Binder.clearCallingIdentity();
3753 try {
3754 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3755 if (defaultPhone != null) {
3756 defaultPhone.setRadioPower(turnOn);
3757 return true;
3758 } else {
3759 loge("There's no default phone.");
3760 return false;
3761 }
3762 } finally {
3763 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003764 }
Wink Saville36469e72014-06-11 15:17:00 -07003765 }
3766
Wink Savilleb564aae2014-10-23 10:18:09 -07003767 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003768 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003769
Ling Ma83dc5ea2023-01-12 15:06:04 -08003770 if (!turnOn) {
3771 log("setRadioPowerForSubscriber off: subId=" + subId
3772 + ",callingPackage=" + getCurrentPackageName());
3773 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003774 final long identity = Binder.clearCallingIdentity();
3775 try {
3776 final Phone phone = getPhone(subId);
3777 if (phone != null) {
3778 phone.setRadioPower(turnOn);
3779 return true;
3780 } else {
3781 return false;
3782 }
3783 } finally {
3784 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003785 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003786 }
3787
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003788 /**
3789 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3790 * no reason to power it off. When any of the voters want to power it off, it will be turned
3791 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3792 * powering it off, and these radio off votes will be cleared.
3793 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3794 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3795 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3796 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3797 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3798 * check its vote.
3799 *
3800 * @param subId The subscription ID.
3801 * @param reason The reason for powering off radio.
3802 * @return true on success and false on failure.
3803 */
3804 public boolean requestRadioPowerOffForReason(int subId,
3805 @TelephonyManager.RadioPowerReason int reason) {
3806 enforceModifyPermission();
3807
Ling Ma83dc5ea2023-01-12 15:06:04 -08003808 log("requestRadioPowerOffForReason: subId=" + subId
3809 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003810 final long identity = Binder.clearCallingIdentity();
3811 try {
3812 final Phone phone = getPhone(subId);
3813 if (phone != null) {
3814 phone.setRadioPowerForReason(false, reason);
3815 return true;
3816 } else {
3817 return false;
3818 }
3819 } finally {
3820 Binder.restoreCallingIdentity(identity);
3821 }
3822 }
3823
3824 /**
3825 * Remove the vote on powering off the radio for a reason, as requested by
3826 * {@link requestRadioPowerOffForReason}.
3827 *
3828 * @param subId The subscription ID.
3829 * @param reason The reason for powering off radio.
3830 * @return true on success and false on failure.
3831 */
3832 public boolean clearRadioPowerOffForReason(int subId,
3833 @TelephonyManager.RadioPowerReason int reason) {
3834 enforceModifyPermission();
3835
3836 final long identity = Binder.clearCallingIdentity();
3837 try {
3838 final Phone phone = getPhone(subId);
3839 if (phone != null) {
3840 phone.setRadioPowerForReason(true, reason);
3841 return true;
3842 } else {
3843 return false;
3844 }
3845 } finally {
3846 Binder.restoreCallingIdentity(identity);
3847 }
3848 }
3849
3850 /**
3851 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3852 *
3853 * @param subId The subscription ID.
3854 * @param callingPackage The package making the call.
3855 * @param callingFeatureId The feature in the package.
3856 * @return List of reasons for powering off radio.
3857 */
3858 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3859 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3860
3861 final long identity = Binder.clearCallingIdentity();
3862 List result = new ArrayList();
3863 try {
3864 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3865 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3866 return result;
3867 }
3868
3869 final Phone phone = getPhone(subId);
3870 if (phone != null) {
3871 result.addAll(phone.getRadioPowerOffReasons());
3872 }
3873 } finally {
3874 Binder.restoreCallingIdentity(identity);
3875 }
3876 return result;
3877 }
3878
Wink Saville36469e72014-06-11 15:17:00 -07003879 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003880 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003881 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003882 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003883
3884 final long identity = Binder.clearCallingIdentity();
3885 try {
Jack Yu285100e2022-12-02 22:48:35 -08003886 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003887 final Phone phone = getPhone(subId);
3888 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003889 phone.getDataSettingsManager().setDataEnabled(
3890 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003891 return true;
3892 } else {
3893 return false;
3894 }
3895 } finally {
3896 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003897 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003898 }
3899
Wink Saville36469e72014-06-11 15:17:00 -07003900 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003901 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003902 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003903 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003904
3905 final long identity = Binder.clearCallingIdentity();
3906 try {
Jack Yu285100e2022-12-02 22:48:35 -08003907 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003908 final Phone phone = getPhone(subId);
3909 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003910 phone.getDataSettingsManager().setDataEnabled(
3911 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003912 return true;
3913 } else {
3914 return false;
3915 }
3916 } finally {
3917 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003918 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003919 }
3920
Sanket Padawe356d7632015-06-22 14:03:32 -07003921 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003922 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003923 final long identity = Binder.clearCallingIdentity();
3924 try {
3925 final Phone phone = getPhone(subId);
3926 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003927 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003928 } else {
3929 return false;
3930 }
3931 } finally {
3932 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003933 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003934 }
3935
3936 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003937 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003938 }
3939
pkanwarae03a6b2016-11-06 20:37:09 -08003940 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003941 enforceCallPermission();
3942
3943 final long identity = Binder.clearCallingIdentity();
3944 try {
3945 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3946 return;
3947 }
3948 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3949 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3950 } finally {
3951 Binder.restoreCallingIdentity(identity);
3952 }
pkanwar32d516d2016-10-14 19:37:38 -07003953 };
3954
Wink Savilleb564aae2014-10-23 10:18:09 -07003955 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003956 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003957
3958 final long identity = Binder.clearCallingIdentity();
3959 try {
3960 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3961 return false;
3962 }
3963 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3964 } finally {
3965 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003966 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003967 }
3968
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003969 /**
3970 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3971 * tag on getCallState Binder call.
3972 */
3973 @Deprecated
3974 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003975 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003976 if (CompatChanges.isChangeEnabled(
3977 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3978 Binder.getCallingUid())) {
3979 // Do not allow this API to be called on API version 31+, it should only be
3980 // called on old apps using this Binder call directly.
3981 throw new SecurityException("This method can only be used for applications "
3982 + "targeting API version 30 or less.");
3983 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003984 final long identity = Binder.clearCallingIdentity();
3985 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003986 Phone phone = getPhone(getDefaultSubscription());
3987 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3988 PhoneConstantConversions.convertCallState(phone.getState());
3989 } finally {
3990 Binder.restoreCallingIdentity(identity);
3991 }
3992 }
3993
3994 @Override
3995 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3996 if (CompatChanges.isChangeEnabled(
3997 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3998 Binder.getCallingUid())) {
3999 // Check READ_PHONE_STATE for API version 31+
4000 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4001 featureId, "getCallStateForSubscription")) {
4002 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
4003 + "targeting API level 31+.");
4004 }
4005 }
4006 final long identity = Binder.clearCallingIdentity();
4007 try {
4008 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004009 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
4010 PhoneConstantConversions.convertCallState(phone.getState());
4011 } finally {
4012 Binder.restoreCallingIdentity(identity);
4013 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004014 }
4015
Sanket Padawe356d7632015-06-22 14:03:32 -07004016 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00004017 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08004018 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07004019 }
4020
4021 @Override
4022 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004023 final long identity = Binder.clearCallingIdentity();
4024 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07004025 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004026 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07004027 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004028 } else {
4029 return PhoneConstantConversions.convertDataState(
4030 PhoneConstants.DataState.DISCONNECTED);
4031 }
4032 } finally {
4033 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004034 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004035 }
4036
Sanket Padawe356d7632015-06-22 14:03:32 -07004037 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07004038 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08004039 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07004040 }
4041
4042 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07004043 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004044 final long identity = Binder.clearCallingIdentity();
4045 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07004046 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004047 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07004048 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004049 } else {
4050 return TelephonyManager.DATA_ACTIVITY_NONE;
4051 }
4052 } finally {
4053 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004054 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004055 }
4056
4057 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08004058 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004059 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08004060 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08004061
4062 LocationAccessPolicy.LocationPermissionResult locationResult =
4063 LocationAccessPolicy.checkLocationPermission(mApp,
4064 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4065 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004066 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004067 .setCallingPid(Binder.getCallingPid())
4068 .setCallingUid(Binder.getCallingUid())
4069 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08004070 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08004071 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4072 .build());
4073 switch (locationResult) {
4074 case DENIED_HARD:
4075 throw new SecurityException("Not allowed to access cell location");
4076 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08004077 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
4078 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004079 }
4080
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004081 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004082 final long identity = Binder.clearCallingIdentity();
4083 try {
4084 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08004085 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08004086 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004087 } finally {
4088 Binder.restoreCallingIdentity(identity);
4089 }
Svetoslav64fad262015-04-14 14:35:21 -07004090 }
4091
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004092 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08004093 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07004094 // Reporting the correct network country is ambiguous when IWLAN could conflict with
4095 // registered cell info, so return a NULL country instead.
4096 final long identity = Binder.clearCallingIdentity();
4097 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07004098 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
4099 // Get default phone in this case.
4100 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
4101 }
Jack Yu285100e2022-12-02 22:48:35 -08004102 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004103 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07004104 if (phone == null) return "";
4105 ServiceStateTracker sst = phone.getServiceStateTracker();
4106 if (sst == null) return "";
4107 LocaleTracker lt = sst.getLocaleTracker();
4108 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08004109 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07004110 } finally {
4111 Binder.restoreCallingIdentity(identity);
4112 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07004113 }
4114
Nathan Harold7c8d0f12020-05-28 20:40:31 -07004115 /**
4116 * This method was removed due to potential issues caused by performing partial
4117 * updates of service state, and lack of a credible use case.
4118 *
4119 * This has the ability to break the telephony implementation by disabling notification of
4120 * changes in device connectivity. DO NOT USE THIS!
4121 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07004122 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004123 public void enableLocationUpdates() {
4124 mApp.enforceCallingOrSelfPermission(
4125 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004126 }
4127
Nathan Harold7c8d0f12020-05-28 20:40:31 -07004128 /**
4129 * This method was removed due to potential issues caused by performing partial
4130 * updates of service state, and lack of a credible use case.
4131 *
4132 * This has the ability to break the telephony implementation by disabling notification of
4133 * changes in device connectivity. DO NOT USE THIS!
4134 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004135 @Override
4136 public void disableLocationUpdates() {
4137 mApp.enforceCallingOrSelfPermission(
4138 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004139 }
4140
4141 @Override
4142 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004143 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
4144 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07004145 try {
4146 mApp.getSystemService(AppOpsManager.class)
4147 .checkPackage(Binder.getCallingUid(), callingPackage);
4148 } catch (SecurityException e) {
4149 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
4150 throw e;
4151 }
4152
Nathan Haroldf096d982020-11-18 17:18:06 -08004153 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07004154 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
4155 throw new SecurityException(
4156 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
4157 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07004158
Jordan Liu1617b712019-07-10 15:06:26 -07004159 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004160 callingPackage) != AppOpsManager.MODE_ALLOWED) {
4161 return null;
4162 }
Svetoslav64fad262015-04-14 14:35:21 -07004163
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07004164 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004165
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004166 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07004167 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004168
Nathan Haroldf180aac2018-06-01 18:43:55 -07004169 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
4170 for (CellInfo ci : info) {
4171 if (ci instanceof CellInfoGsm) {
4172 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
4173 } else if (ci instanceof CellInfoWcdma) {
4174 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
4175 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004176 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07004177 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004178 }
4179
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004180 private List<CellInfo> getCachedCellInfo() {
4181 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
4182 for (Phone phone : PhoneFactory.getPhones()) {
4183 List<CellInfo> info = phone.getAllCellInfo();
4184 if (info != null) cellInfos.addAll(info);
4185 }
4186 return cellInfos;
4187 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004188
4189 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004190 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004191 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08004192 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08004193
4194 LocationAccessPolicy.LocationPermissionResult locationResult =
4195 LocationAccessPolicy.checkLocationPermission(mApp,
4196 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4197 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004198 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004199 .setCallingPid(Binder.getCallingPid())
4200 .setCallingUid(Binder.getCallingUid())
4201 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08004202 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08004203 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4204 .build());
4205 switch (locationResult) {
4206 case DENIED_HARD:
4207 throw new SecurityException("Not allowed to access cell info");
4208 case DENIED_SOFT:
4209 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004210 }
4211
Nathan Haroldf096d982020-11-18 17:18:06 -08004212 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004213 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
4214 return getCachedCellInfo();
4215 }
4216
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07004217 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004218 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004219 final long identity = Binder.clearCallingIdentity();
4220 try {
4221 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
4222 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07004223 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07004224 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004225 if (info != null) cellInfos.addAll(info);
4226 }
4227 return cellInfos;
4228 } finally {
4229 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004230 }
4231 }
4232
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07004233 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004234 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
4235 String callingFeatureId) {
4236 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
4237 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004238 }
4239
4240 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004241 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
4242 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004243 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004244 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004245 }
4246
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004247 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
4248 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004249 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004250 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08004251
4252 LocationAccessPolicy.LocationPermissionResult locationResult =
4253 LocationAccessPolicy.checkLocationPermission(mApp,
4254 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4255 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004256 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004257 .setCallingPid(Binder.getCallingPid())
4258 .setCallingUid(Binder.getCallingUid())
4259 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07004260 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
4261 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08004262 .build());
4263 switch (locationResult) {
4264 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08004265 if (TelephonyPermissions
4266 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07004267 // Safetynet logging for b/154934934
4268 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
4269 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004270 throw new SecurityException("Not allowed to access cell info");
4271 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08004272 if (TelephonyPermissions
4273 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07004274 // Safetynet logging for b/154934934
4275 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
4276 }
Nathan Harold5320c422019-05-09 10:26:08 -07004277 try {
4278 cb.onCellInfo(new ArrayList<CellInfo>());
4279 } catch (RemoteException re) {
4280 // Drop without consequences
4281 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004282 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004283 }
4284
Nathan Harolda939a962019-05-09 10:13:47 -07004285
4286 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004287 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
4288
4289 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
4290 }
4291
4292 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00004293 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08004294 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004295 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004296
4297 final long identity = Binder.clearCallingIdentity();
4298 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00004299 Phone phone = getPhone(subId);
4300 if (phone == null) {
4301 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
4302 } else {
4303 phone.setCellInfoListRate(rateInMillis, workSource);
4304 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004305 } finally {
4306 Binder.restoreCallingIdentity(identity);
4307 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004308 }
4309
Shishir Agrawala9f32182016-04-12 12:00:16 -07004310 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004311 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004312 Phone phone = PhoneFactory.getPhone(slotIndex);
4313 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004314 return null;
4315 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004316 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07004317 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07004318 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004319 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004320 return null;
4321 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004322
4323 final long identity = Binder.clearCallingIdentity();
4324 try {
4325 return phone.getImei();
4326 } finally {
4327 Binder.restoreCallingIdentity(identity);
4328 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07004329 }
4330
4331 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00004332 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
4333 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
4334 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
4335 callingFeatureId, "getPrimaryImei")) {
4336 throw new SecurityException("Caller does not have permission");
4337 }
4338 final long identity = Binder.clearCallingIdentity();
4339 try {
4340 for (Phone phone : PhoneFactory.getPhones()) {
4341 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
4342 return phone.getImei();
4343 }
4344 }
4345 throw new UnsupportedOperationException("Operation not supported");
4346 } finally {
4347 Binder.restoreCallingIdentity(identity);
4348 }
4349 }
4350
4351 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00004352 public String getTypeAllocationCodeForSlot(int slotIndex) {
4353 Phone phone = PhoneFactory.getPhone(slotIndex);
4354 String tac = null;
4355 if (phone != null) {
4356 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07004357 try {
4358 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
4359 } catch (IndexOutOfBoundsException e) {
4360 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
4361 return null;
4362 }
David Kelly5e06a7f2018-03-12 14:10:59 +00004363 }
4364 return tac;
4365 }
4366
4367 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004368 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004369 try {
4370 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4371 } catch (SecurityException se) {
4372 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
4373 throw new SecurityException("Package " + callingPackage + " does not belong to "
4374 + Binder.getCallingUid());
4375 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004376 Phone phone = PhoneFactory.getPhone(slotIndex);
4377 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07004378 return null;
4379 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004380
Jeff Davidson913390f2018-02-23 17:11:49 -08004381 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07004382 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004383 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004384 return null;
4385 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004386
4387 final long identity = Binder.clearCallingIdentity();
4388 try {
4389 return phone.getMeid();
4390 } finally {
4391 Binder.restoreCallingIdentity(identity);
4392 }
Jack Yu2af8d712017-03-15 17:14:14 -07004393 }
4394
4395 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00004396 public String getManufacturerCodeForSlot(int slotIndex) {
4397 Phone phone = PhoneFactory.getPhone(slotIndex);
4398 String manufacturerCode = null;
4399 if (phone != null) {
4400 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07004401 try {
4402 manufacturerCode =
4403 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
4404 } catch (IndexOutOfBoundsException e) {
4405 Log.e(LOG_TAG, "MEID length shorter than upper index.");
4406 return null;
4407 }
David Kelly5e06a7f2018-03-12 14:10:59 +00004408 }
4409 return manufacturerCode;
4410 }
4411
4412 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004413 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
4414 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004415 Phone phone = PhoneFactory.getPhone(slotIndex);
4416 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004417 return null;
4418 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004419 int subId = phone.getSubId();
4420 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004421 mApp, subId, callingPackage, callingFeatureId,
4422 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004423 return null;
4424 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004425
4426 final long identity = Binder.clearCallingIdentity();
4427 try {
4428 return phone.getDeviceSvn();
4429 } finally {
4430 Binder.restoreCallingIdentity(identity);
4431 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07004432 }
4433
fionaxu43304da2017-11-27 22:51:16 -08004434 @Override
4435 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004436 final long identity = Binder.clearCallingIdentity();
4437 try {
4438 final Phone phone = getPhone(subId);
4439 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
4440 } finally {
4441 Binder.restoreCallingIdentity(identity);
4442 }
fionaxu43304da2017-11-27 22:51:16 -08004443 }
4444
4445 @Override
4446 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004447 final long identity = Binder.clearCallingIdentity();
4448 try {
4449 final Phone phone = getPhone(subId);
4450 return phone == null ? null : phone.getCarrierName();
4451 } finally {
4452 Binder.restoreCallingIdentity(identity);
4453 }
fionaxu43304da2017-11-27 22:51:16 -08004454 }
4455
calvinpanffe225e2018-11-01 19:43:06 +08004456 @Override
chen xu0026ca62019-03-06 15:28:50 -08004457 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08004458 final long identity = Binder.clearCallingIdentity();
4459 try {
4460 final Phone phone = getPhone(subId);
4461 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08004462 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08004463 } finally {
4464 Binder.restoreCallingIdentity(identity);
4465 }
4466 }
4467
4468 @Override
chen xu0026ca62019-03-06 15:28:50 -08004469 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08004470 final long identity = Binder.clearCallingIdentity();
4471 try {
4472 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08004473 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08004474 } finally {
4475 Binder.restoreCallingIdentity(identity);
4476 }
4477 }
4478
chen xu651eec72018-11-11 19:03:44 -08004479 @Override
chen xu864e11c2018-12-06 22:10:03 -08004480 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
4481 if (!isSubscriptionMccMnc) {
4482 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
4483 }
chen xu651eec72018-11-11 19:03:44 -08004484 final Phone phone = PhoneFactory.getPhone(slotIndex);
4485 if (phone == null) {
4486 return TelephonyManager.UNKNOWN_CARRIER_ID;
4487 }
4488 final long identity = Binder.clearCallingIdentity();
4489 try {
4490 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
4491 } finally {
4492 Binder.restoreCallingIdentity(identity);
4493 }
4494 }
4495
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004496 //
4497 // Internal helper methods.
4498 //
4499
Sanket Padaweee13a9b2016-03-08 17:30:28 -08004500 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07004501 * Make sure the caller is the calling package itself
4502 *
4503 * @throws SecurityException if the caller is not the calling package
4504 */
4505 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
4506 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07004507 PackageManager pm = mApp.getBaseContext().createContextAsUser(
4508 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07004509 try {
Grace Jiadbefca02021-04-26 15:13:31 -07004510 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07004511 } catch (PackageManager.NameNotFoundException e) {
4512 // packageUid is -1
4513 }
4514 if (packageUid != callingUid) {
4515 throw new SecurityException(message + ": Package " + callingPackage
4516 + " does not belong to " + callingUid);
4517 }
4518 }
4519
4520 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004521 * Make sure the caller has the MODIFY_PHONE_STATE permission.
4522 *
4523 * @throws SecurityException if the caller does not have the required permission
4524 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004525 @VisibleForTesting
4526 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004527 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
4528 }
4529
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004530 /**
arunvoddud7401012022-12-15 16:08:12 +00004531 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004532 *
4533 * @throws SecurityException if the caller does not have the required permission
4534 */
4535 @VisibleForTesting
4536 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00004537 enforceReadPermission(null);
4538 }
4539
4540 /**
4541 * Make sure the caller has the READ_PHONE_STATE permissions.
4542 *
4543 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
4544 */
4545 @VisibleForTesting
4546 public void enforceReadPermission(String msg) {
4547 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004548 }
4549
Shuo Qian3b6ee772019-11-13 17:43:31 -08004550 private void enforceActiveEmergencySessionPermission() {
4551 mApp.enforceCallingOrSelfPermission(
4552 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
4553 }
4554
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004555 /**
4556 * Make sure the caller has the CALL_PHONE permission.
4557 *
4558 * @throws SecurityException if the caller does not have the required permission
4559 */
4560 private void enforceCallPermission() {
4561 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
4562 }
4563
paulhu5a773602019-08-23 19:17:33 +08004564 private void enforceSettingsPermission() {
4565 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004566 }
4567
Michele Berionne5e411512020-11-13 02:36:59 +00004568 private void enforceRebootPermission() {
4569 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
4570 }
4571
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00004572 /**
4573 * Make sure the caller has SATELLITE_COMMUNICATION permission.
4574 * @param message - log message to print.
4575 * @throws SecurityException if the caller does not have the required permission
4576 */
4577 private void enforceSatelliteCommunicationPermission(String message) {
4578 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
4579 }
4580
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004581 private String createTelUrl(String number) {
4582 if (TextUtils.isEmpty(number)) {
4583 return null;
4584 }
4585
Jake Hambye994d462014-02-03 13:10:13 -08004586 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004587 }
4588
Ihab Awadf9e92732013-12-05 18:02:52 -08004589 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08004590 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004591 }
4592
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07004593 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08004594 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07004595 }
4596
Ihab Awadf9e92732013-12-05 18:02:52 -08004597 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08004598 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004599 }
4600
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004601 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004602 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07004603 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07004604 }
4605
Sanket Padawe356d7632015-06-22 14:03:32 -07004606 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004607 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004608 final long identity = Binder.clearCallingIdentity();
4609 try {
4610 final Phone phone = PhoneFactory.getPhone(slotIndex);
4611 if (phone == null) {
4612 return PhoneConstants.PHONE_TYPE_NONE;
4613 } else {
4614 return phone.getPhoneType();
4615 }
4616 } finally {
4617 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004618 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004619 }
4620
4621 /**
4622 * Returns the CDMA ERI icon index to display
4623 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004624 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004625 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
4626 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4627 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004628 }
4629
Sanket Padawe356d7632015-06-22 14:03:32 -07004630 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004631 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4632 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004633 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004634 mApp, subId, callingPackage, callingFeatureId,
4635 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004636 return -1;
4637 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004638
4639 final long identity = Binder.clearCallingIdentity();
4640 try {
4641 final Phone phone = getPhone(subId);
4642 if (phone != null) {
4643 return phone.getCdmaEriIconIndex();
4644 } else {
4645 return -1;
4646 }
4647 } finally {
4648 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004649 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004650 }
4651
4652 /**
4653 * Returns the CDMA ERI icon mode,
4654 * 0 - ON
4655 * 1 - FLASHING
4656 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004657 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004658 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4659 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4660 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004661 }
4662
Sanket Padawe356d7632015-06-22 14:03:32 -07004663 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004664 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4665 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004666 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004667 mApp, subId, callingPackage, callingFeatureId,
4668 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004669 return -1;
4670 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004671
4672 final long identity = Binder.clearCallingIdentity();
4673 try {
4674 final Phone phone = getPhone(subId);
4675 if (phone != null) {
4676 return phone.getCdmaEriIconMode();
4677 } else {
4678 return -1;
4679 }
4680 } finally {
4681 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004682 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004683 }
4684
4685 /**
4686 * Returns the CDMA ERI text,
4687 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004688 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004689 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4690 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4691 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004692 }
4693
Sanket Padawe356d7632015-06-22 14:03:32 -07004694 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004695 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4696 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004697 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004698 mApp, subId, callingPackage, callingFeatureId,
4699 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004700 return null;
4701 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004702
4703 final long identity = Binder.clearCallingIdentity();
4704 try {
4705 final Phone phone = getPhone(subId);
4706 if (phone != null) {
4707 return phone.getCdmaEriText();
4708 } else {
4709 return null;
4710 }
4711 } finally {
4712 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004714 }
4715
4716 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004717 * Returns the CDMA MDN.
4718 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004719 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004720 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004721 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4722 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004723
4724 final long identity = Binder.clearCallingIdentity();
4725 try {
4726 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004727 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004728 return phone.getLine1Number();
4729 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004730 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004731 return null;
4732 }
4733 } finally {
4734 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004735 }
4736 }
4737
4738 /**
4739 * Returns the CDMA MIN.
4740 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004741 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004742 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004743 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4744 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004745
4746 final long identity = Binder.clearCallingIdentity();
4747 try {
4748 final Phone phone = getPhone(subId);
4749 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4750 return phone.getCdmaMin();
4751 } else {
4752 return null;
4753 }
4754 } finally {
4755 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004756 }
4757 }
4758
Hall Liud892bec2018-11-30 14:51:45 -08004759 @Override
4760 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4761 INumberVerificationCallback callback, String callingPackage) {
4762 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4763 != PERMISSION_GRANTED) {
4764 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4765 }
4766 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4767
4768 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4769 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004770 throw new SecurityException("Calling package must be configured in the device config: "
4771 + "calling package: " + callingPackage
4772 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004773 }
4774
4775 if (range == null) {
4776 throw new NullPointerException("Range must be non-null");
4777 }
4778
4779 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004780 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004781
4782 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4783 }
4784
Junda Liuca05d5d2014-08-14 22:36:34 -07004785 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004786 * Returns true if CDMA provisioning needs to run.
4787 */
4788 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004789 final long identity = Binder.clearCallingIdentity();
4790 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004791 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004792 } finally {
4793 Binder.restoreCallingIdentity(identity);
4794 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004795 }
4796
4797 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004798 * Sets the voice mail number of a given subId.
4799 */
4800 @Override
4801 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004802 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4803 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004804
4805 final long identity = Binder.clearCallingIdentity();
4806 try {
4807 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4808 new Pair<String, String>(alphaTag, number), new Integer(subId));
4809 return success;
4810 } finally {
4811 Binder.restoreCallingIdentity(identity);
4812 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004813 }
4814
Ta-wei Yen87c49842016-05-13 21:19:52 -07004815 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004816 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4817 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004818 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4819 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004820 if (!TextUtils.equals(callingPackage, systemDialer)) {
4821 throw new SecurityException("caller must be system dialer");
4822 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004823
4824 final long identity = Binder.clearCallingIdentity();
4825 try {
4826 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4827 if (phoneAccountHandle == null) {
4828 return null;
4829 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004830 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004831 } finally {
4832 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004833 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004834 }
4835
4836 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004837 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4838 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004839 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004840 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004841 mApp, subId, callingPackage, callingFeatureId,
4842 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004843 return null;
4844 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004845
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004846 final long identity = Binder.clearCallingIdentity();
4847 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004848 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004849 } finally {
4850 Binder.restoreCallingIdentity(identity);
4851 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004852 }
4853
4854 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004855 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4856 VisualVoicemailSmsFilterSettings settings) {
4857 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004858
4859 final long identity = Binder.clearCallingIdentity();
4860 try {
4861 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004862 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004863 } finally {
4864 Binder.restoreCallingIdentity(identity);
4865 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004866 }
4867
4868 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004869 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4870 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004871
4872 final long identity = Binder.clearCallingIdentity();
4873 try {
4874 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004875 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004876 } finally {
4877 Binder.restoreCallingIdentity(identity);
4878 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004879 }
4880
4881 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004882 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4883 String callingPackage, int subId) {
4884 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004885
4886 final long identity = Binder.clearCallingIdentity();
4887 try {
4888 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004889 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004890 } finally {
4891 Binder.restoreCallingIdentity(identity);
4892 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004893 }
4894
4895 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004896 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004897 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004898
4899 final long identity = Binder.clearCallingIdentity();
4900 try {
4901 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004902 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004903 } finally {
4904 Binder.restoreCallingIdentity(identity);
4905 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004906 }
4907
4908 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004909 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4910 String callingAttributionTag, int subId, String number, int port, String text,
4911 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004912 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004913 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004914 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004915 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004916 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4917 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004918 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004919
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004920 /**
fionaxu0152e512016-11-14 13:36:14 -08004921 * Sets the voice activation state of a given subId.
4922 */
4923 @Override
4924 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004925 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4926 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004927
4928 final long identity = Binder.clearCallingIdentity();
4929 try {
4930 final Phone phone = getPhone(subId);
4931 if (phone != null) {
4932 phone.setVoiceActivationState(activationState);
4933 } else {
4934 loge("setVoiceActivationState fails with invalid subId: " + subId);
4935 }
4936 } finally {
4937 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004938 }
4939 }
4940
4941 /**
4942 * Sets the data activation state of a given subId.
4943 */
4944 @Override
4945 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004946 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4947 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004948
4949 final long identity = Binder.clearCallingIdentity();
4950 try {
4951 final Phone phone = getPhone(subId);
4952 if (phone != null) {
4953 phone.setDataActivationState(activationState);
4954 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004955 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004956 }
4957 } finally {
4958 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004959 }
4960 }
4961
4962 /**
4963 * Returns the voice activation state of a given subId.
4964 */
4965 @Override
4966 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004967 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004968
fionaxu0152e512016-11-14 13:36:14 -08004969 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004970 final long identity = Binder.clearCallingIdentity();
4971 try {
4972 if (phone != null) {
4973 return phone.getVoiceActivationState();
4974 } else {
4975 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4976 }
4977 } finally {
4978 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004979 }
4980 }
4981
4982 /**
4983 * Returns the data activation state of a given subId.
4984 */
4985 @Override
4986 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004987 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004988
fionaxu0152e512016-11-14 13:36:14 -08004989 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004990 final long identity = Binder.clearCallingIdentity();
4991 try {
4992 if (phone != null) {
4993 return phone.getDataActivationState();
4994 } else {
4995 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4996 }
4997 } finally {
4998 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004999 }
5000 }
5001
5002 /**
Wink Saville36469e72014-06-11 15:17:00 -07005003 * Returns the unread count of voicemails for a subId
5004 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005005 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005006 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
5007 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08005008 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005009 mApp, subId, callingPackage, callingFeatureId,
5010 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08005011 return 0;
5012 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005013 final long identity = Binder.clearCallingIdentity();
5014 try {
5015 final Phone phone = getPhone(subId);
5016 if (phone != null) {
5017 return phone.getVoiceMessageCount();
5018 } else {
5019 return 0;
5020 }
5021 } finally {
5022 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005023 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005024 }
5025
5026 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005027 * returns true, if the device is in a state where both voice and data
5028 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08005029 */
5030 @Override
5031 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005032 final long identity = Binder.clearCallingIdentity();
5033 try {
5034 final Phone phone = getPhone(subId);
5035 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
5036 } finally {
5037 Binder.restoreCallingIdentity(identity);
5038 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08005039 }
5040
5041 /**
fionaxu235cc5e2017-03-06 22:25:57 -08005042 * Send the dialer code if called from the current default dialer or the caller has
5043 * carrier privilege.
5044 * @param inputCode The dialer code to send
5045 */
5046 @Override
5047 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005048 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08005049 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07005050 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
5051 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08005052 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005053 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005054 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08005055 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005056
5057 final long identity = Binder.clearCallingIdentity();
5058 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005059 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005060 } finally {
5061 Binder.restoreCallingIdentity(identity);
5062 }
fionaxu235cc5e2017-03-06 22:25:57 -08005063 }
5064
Pengquan Menga1bb6272018-09-06 09:59:22 -07005065 @Override
5066 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08005067 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005068 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5069 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08005070 final long identity = Binder.clearCallingIdentity();
5071 try {
5072 if (!isActiveSubscription(subId)) {
5073 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
5074 }
5075 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
5076 } finally {
5077 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07005078 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005079 }
5080
Brad Ebinger35c841c2018-10-01 10:40:55 -07005081 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07005082 public boolean isInEmergencySmsMode() {
5083 enforceReadPrivilegedPermission("isInEmergencySmsMode");
5084 final long identity = Binder.clearCallingIdentity();
5085 try {
5086 for (Phone phone : PhoneFactory.getPhones()) {
5087 if (phone.isInEmergencySmsMode()) {
5088 return true;
5089 }
5090 }
5091 } finally {
5092 Binder.restoreCallingIdentity(identity);
5093 }
5094 return false;
5095 }
5096
shilu366312e2019-12-17 09:28:10 -08005097 /**
5098 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5099 * @param subId The subscription to use to check the configuration.
5100 * @param c The callback that will be used to send the result.
5101 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07005102 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005103 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
5104 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07005105 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005106 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00005107
5108 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5109 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5110 "IMS not available on device.");
5111 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07005112 final long token = Binder.clearCallingIdentity();
5113 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005114 int slotId = getSlotIndexOrException(subId);
5115 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00005116
5117 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5118 if (controller != null) {
5119 ImsManager imsManager = controller.getImsManager(subId);
5120 if (imsManager != null) {
5121 imsManager.addRegistrationCallbackForSubscription(c, subId);
5122 } else {
5123 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5124 }
5125 } else {
5126 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5127 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005128 } catch (ImsException e) {
5129 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005130 } finally {
5131 Binder.restoreCallingIdentity(token);
5132 }
5133 }
5134
shilu366312e2019-12-17 09:28:10 -08005135 /**
5136 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5137 * @param subId The subscription to use to check the configuration.
5138 * @param c The callback that will be used to send the result.
5139 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005140 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005141 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07005142 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005143 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005144 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5145 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5146 }
Meng Wangafbc5852019-09-19 17:37:13 -07005147 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00005148
Meng Wangafbc5852019-09-19 17:37:13 -07005149 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00005150 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5151 if (controller != null) {
5152 ImsManager imsManager = controller.getImsManager(subId);
5153 if (imsManager != null) {
5154 imsManager.removeRegistrationCallbackForSubscription(c, subId);
5155 } else {
5156 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
5157 + "is inactive, ignoring unregister.");
5158 // If the ImsManager is not valid, just return, since the callback
5159 // will already have been removed internally.
5160 }
5161 }
Meng Wangafbc5852019-09-19 17:37:13 -07005162 } finally {
5163 Binder.restoreCallingIdentity(token);
5164 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07005165 }
5166
Brad Ebingera34a6c22019-10-22 17:36:18 -07005167 /**
5168 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
5169 */
5170 @Override
5171 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
5172 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
5173 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5174 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5175 "IMS not available on device.");
5176 }
5177 final long token = Binder.clearCallingIdentity();
5178 try {
5179 Phone phone = getPhone(subId);
5180 if (phone == null) {
5181 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
5182 + subId + "'");
5183 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5184 }
5185 phone.getImsRegistrationState(regState -> {
5186 try {
5187 consumer.accept((regState == null)
5188 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
5189 } catch (RemoteException e) {
5190 // Ignore if the remote process is no longer available to call back.
5191 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
5192 }
5193 });
5194 } finally {
5195 Binder.restoreCallingIdentity(token);
5196 }
5197 }
5198
5199 /**
5200 * Get the transport type for the IMS service registration state.
5201 */
5202 @Override
5203 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07005204 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005205 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07005206 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5207 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5208 "IMS not available on device.");
5209 }
5210 final long token = Binder.clearCallingIdentity();
5211 try {
5212 Phone phone = getPhone(subId);
5213 if (phone == null) {
5214 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
5215 + subId + "'");
5216 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5217 }
5218 phone.getImsRegistrationTech(regTech -> {
5219 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
5220 int regTechConverted = (regTech == null)
5221 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
5222 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
5223 regTechConverted);
5224 try {
5225 consumer.accept(regTechConverted);
5226 } catch (RemoteException e) {
5227 // Ignore if the remote process is no longer available to call back.
5228 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
5229 }
5230 });
5231 } finally {
5232 Binder.restoreCallingIdentity(token);
5233 }
5234 }
5235
shilu366312e2019-12-17 09:28:10 -08005236 /**
5237 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5238 * @param subId The subscription to use to check the configuration.
5239 * @param c The callback that will be used to send the result.
5240 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005241 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005242 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
5243 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07005244 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005245 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00005246 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5247 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5248 "IMS not available on device.");
5249 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07005250 final long token = Binder.clearCallingIdentity();
5251 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005252 int slotId = getSlotIndexOrException(subId);
5253 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005254
5255 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5256 if (controller != null) {
5257 ImsManager imsManager = controller.getImsManager(subId);
5258 if (imsManager != null) {
5259 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
5260 } else {
5261 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5262 }
5263 } else {
5264 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5265 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005266 } catch (ImsException e) {
5267 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005268 } finally {
5269 Binder.restoreCallingIdentity(token);
5270 }
5271 }
5272
shilu366312e2019-12-17 09:28:10 -08005273 /**
5274 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5275 * @param subId The subscription to use to check the configuration.
5276 * @param c The callback that will be used to send the result.
5277 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005278 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005279 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07005280 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005281 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005282 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5283 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5284 }
Meng Wangafbc5852019-09-19 17:37:13 -07005285
5286 final long token = Binder.clearCallingIdentity();
5287 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005288 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5289 if (controller != null) {
5290 ImsManager imsManager = controller.getImsManager(subId);
5291 if (imsManager != null) {
5292 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
5293 } else {
5294 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
5295 + " is inactive, ignoring unregister.");
5296 // If the ImsManager is not valid, just return, since the callback
5297 // will already have been removed internally.
5298 }
5299 }
Meng Wangafbc5852019-09-19 17:37:13 -07005300 } finally {
5301 Binder.restoreCallingIdentity(token);
5302 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07005303 }
5304
5305 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005306 public boolean isCapable(int subId, int capability, int regTech) {
5307 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005308 final long token = Binder.clearCallingIdentity();
5309 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005310 int slotId = getSlotIndexOrException(subId);
5311 verifyImsMmTelConfiguredOrThrow(slotId);
5312 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
5313 } catch (com.android.ims.ImsException e) {
5314 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
5315 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005316 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08005317 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
5318 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07005319 } finally {
5320 Binder.restoreCallingIdentity(token);
5321 }
5322 }
5323
5324 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005325 public boolean isAvailable(int subId, int capability, int regTech) {
5326 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005327 final long token = Binder.clearCallingIdentity();
5328 try {
5329 Phone phone = getPhone(subId);
5330 if (phone == null) return false;
5331 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07005332 } catch (com.android.ims.ImsException e) {
5333 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
5334 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07005335 } finally {
5336 Binder.restoreCallingIdentity(token);
5337 }
5338 }
5339
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005340 /**
5341 * Determines if the MmTel feature capability is supported by the carrier configuration for this
5342 * subscription.
5343 * @param subId The subscription to use to check the configuration.
5344 * @param callback The callback that will be used to send the result.
5345 * @param capability The MmTelFeature capability that will be used to send the result.
5346 * @param transportType The transport type of the MmTelFeature capability.
5347 */
5348 @Override
5349 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
5350 int transportType) {
5351 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00005352 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5353 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5354 "IMS not available on device.");
5355 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005356 final long token = Binder.clearCallingIdentity();
5357 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005358 int slotId = getSlotIndex(subId);
5359 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5360 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
5361 + subId + "'");
5362 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5363 }
5364 verifyImsMmTelConfiguredOrThrow(slotId);
5365 ImsManager.getInstance(mApp, slotId).isSupported(capability,
5366 transportType, aBoolean -> {
5367 try {
5368 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
5369 } catch (RemoteException e) {
5370 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
5371 + "running. Ignore");
5372 }
5373 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005374 } catch (ImsException e) {
5375 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005376 } finally {
5377 Binder.restoreCallingIdentity(token);
5378 }
5379 }
5380
shilu366312e2019-12-17 09:28:10 -08005381 /**
5382 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5383 * @param subId The subscription to use to check the configuration.
5384 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005385 @Override
5386 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005387 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005388 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08005389
Brad Ebinger35c841c2018-10-01 10:40:55 -07005390 final long token = Binder.clearCallingIdentity();
5391 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005392 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005393 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005394 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005395 } catch (ImsException e) {
5396 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005397 } finally {
5398 Binder.restoreCallingIdentity(token);
5399 }
5400 }
5401
5402 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005403 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005404 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005405 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005406 final long identity = Binder.clearCallingIdentity();
5407 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005408 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005409 // This setting doesn't require an active ImsService connection, so do not verify. The
5410 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005411 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005412 } catch (ImsException e) {
5413 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005414 } finally {
5415 Binder.restoreCallingIdentity(identity);
5416 }
5417 }
5418
shilu366312e2019-12-17 09:28:10 -08005419 /**
5420 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5421 * @param subId The subscription to use to check the configuration.
5422 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005423 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005424 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005425 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005426 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005427 final long identity = Binder.clearCallingIdentity();
5428 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005429 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005430 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005431 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005432 } catch (ImsException e) {
5433 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005434 } finally {
5435 Binder.restoreCallingIdentity(identity);
5436 }
5437 }
5438
5439 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005440 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005441 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005442 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005443 final long identity = Binder.clearCallingIdentity();
5444 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005445 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005446 // This setting doesn't require an active ImsService connection, so do not verify. The
5447 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005448 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005449 } catch (ImsException e) {
5450 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005451 } finally {
5452 Binder.restoreCallingIdentity(identity);
5453 }
5454 }
5455
shilu366312e2019-12-17 09:28:10 -08005456 /**
5457 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5458 * @param subId The subscription to use to check the configuration.
5459 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005460 @Override
5461 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005462 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005463 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005464 final long identity = Binder.clearCallingIdentity();
5465 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005466 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005467 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005468 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005469 } catch (ImsException e) {
5470 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005471 } finally {
5472 Binder.restoreCallingIdentity(identity);
5473 }
5474 }
5475
5476 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005477 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005478 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005479 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005480 final long identity = Binder.clearCallingIdentity();
5481 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005482 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005483 // This setting doesn't require an active ImsService connection, so do not verify. The
5484 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005485 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005486 } catch (ImsException e) {
5487 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005488 } finally {
5489 Binder.restoreCallingIdentity(identity);
5490 }
5491 }
5492
shilu366312e2019-12-17 09:28:10 -08005493 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005494 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5495 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5496 * @param subId The subscription to use to check the configuration.
5497 */
5498 @Override
5499 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005500 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005501 mApp, subId, "isCrossSimCallingEnabledByUser");
5502 final long identity = Binder.clearCallingIdentity();
5503 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005504 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005505 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005506 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005507 } catch (ImsException e) {
5508 throw new ServiceSpecificException(e.getCode());
5509 } finally {
5510 Binder.restoreCallingIdentity(identity);
5511 }
5512 }
5513
5514 /**
5515 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5516 * Requires MODIFY_PHONE_STATE permission.
5517 * @param subId The subscription to use to check the configuration.
5518 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5519 * false otherwise
5520 */
5521 @Override
5522 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5523 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5524 "setCrossSimCallingEnabled");
5525 final long identity = Binder.clearCallingIdentity();
5526 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005527 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005528 // This setting doesn't require an active ImsService connection, so do not verify. The
5529 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005530 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005531 } catch (ImsException e) {
5532 throw new ServiceSpecificException(e.getCode());
5533 } finally {
5534 Binder.restoreCallingIdentity(identity);
5535 }
5536 }
5537
5538 /**
shilu366312e2019-12-17 09:28:10 -08005539 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5540 * @param subId The subscription to use to check the configuration.
5541 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005542 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005543
Brad Ebinger35c841c2018-10-01 10:40:55 -07005544 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005545 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005546 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005547 final long identity = Binder.clearCallingIdentity();
5548 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005549 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005550 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005551 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005552 } catch (ImsException e) {
5553 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005554 } finally {
5555 Binder.restoreCallingIdentity(identity);
5556 }
5557 }
5558
5559 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005560 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005561 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005562 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005563 final long identity = Binder.clearCallingIdentity();
5564 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005565 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005566 // This setting doesn't require an active ImsService connection, so do not verify. The
5567 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005568 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005569 } catch (ImsException e) {
5570 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005571 } finally {
5572 Binder.restoreCallingIdentity(identity);
5573 }
5574 }
5575
5576 @Override
5577 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5579 "setVoWiFiNonPersistent");
5580 final long identity = Binder.clearCallingIdentity();
5581 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005582 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005583 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005584 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005585 } catch (ImsException e) {
5586 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005587 } finally {
5588 Binder.restoreCallingIdentity(identity);
5589 }
5590 }
5591
shilu366312e2019-12-17 09:28:10 -08005592 /**
5593 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5594 * @param subId The subscription to use to check the configuration.
5595 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005596 @Override
5597 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005598 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005599 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005600 final long identity = Binder.clearCallingIdentity();
5601 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005602 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005603 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005604 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005605 } catch (ImsException e) {
5606 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005607 } finally {
5608 Binder.restoreCallingIdentity(identity);
5609 }
5610 }
5611
5612 @Override
5613 public void setVoWiFiModeSetting(int subId, int mode) {
5614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5615 "setVoWiFiModeSetting");
5616 final long identity = Binder.clearCallingIdentity();
5617 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005618 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005619 // This setting doesn't require an active ImsService connection, so do not verify. The
5620 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005621 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005622 } catch (ImsException e) {
5623 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005624 } finally {
5625 Binder.restoreCallingIdentity(identity);
5626 }
5627 }
5628
5629 @Override
5630 public int getVoWiFiRoamingModeSetting(int subId) {
5631 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
5632 final long identity = Binder.clearCallingIdentity();
5633 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005634 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005635 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005636 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005637 } catch (ImsException e) {
5638 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005639 } finally {
5640 Binder.restoreCallingIdentity(identity);
5641 }
5642 }
5643
5644 @Override
5645 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5647 "setVoWiFiRoamingModeSetting");
5648 final long identity = Binder.clearCallingIdentity();
5649 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005650 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005651 // This setting doesn't require an active ImsService connection, so do not verify. The
5652 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005653 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005654 } catch (ImsException e) {
5655 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005656 } finally {
5657 Binder.restoreCallingIdentity(identity);
5658 }
5659 }
5660
5661 @Override
5662 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5664 "setRttCapabilityEnabled");
5665 final long identity = Binder.clearCallingIdentity();
5666 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005667 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005668 // This setting doesn't require an active ImsService connection, so do not verify. The
5669 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005670 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005671 } catch (ImsException e) {
5672 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005673 } finally {
5674 Binder.restoreCallingIdentity(identity);
5675 }
5676 }
5677
shilu366312e2019-12-17 09:28:10 -08005678 /**
5679 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5680 * @param subId The subscription to use to check the configuration.
5681 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005682 @Override
5683 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005684 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005685 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005686 final long identity = Binder.clearCallingIdentity();
5687 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005688 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005689 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005690 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005691 } catch (ImsException e) {
5692 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005693 } finally {
5694 Binder.restoreCallingIdentity(identity);
5695 }
5696 }
5697
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005698 @Override
5699 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5700 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005701
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005702 final long identity = Binder.clearCallingIdentity();
5703 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005704 if (!isImsAvailableOnDevice()) {
5705 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5706 "IMS not available on device.");
5707 }
5708 int slotId = getSlotIndexOrException(subId);
5709 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005710
5711 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5712 if (controller != null) {
5713 ImsManager imsManager = controller.getImsManager(subId);
5714 if (imsManager != null) {
5715 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5716 } else {
5717 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5718 }
5719 } else {
5720 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5721 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005722 } catch (ImsException e) {
5723 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005724 } finally {
5725 Binder.restoreCallingIdentity(identity);
5726 }
5727 }
5728
5729 @Override
5730 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5731 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005732
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005733 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005734 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5735 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5736 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005737 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005738 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5739 if (controller != null) {
5740 ImsManager imsManager = controller.getImsManager(subId);
5741 if (imsManager != null) {
5742 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5743 } else {
5744 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5745 + " is inactive, ignoring unregister.");
5746 // If the ImsManager is not valid, just return, since the callback will already
5747 // have been removed internally.
5748 }
5749 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005750 } finally {
5751 Binder.restoreCallingIdentity(identity);
5752 }
5753 }
5754
joonhunshincffb7fc2021-11-28 07:32:01 +00005755 @Override
5756 public void registerFeatureProvisioningChangedCallback(int subId,
5757 IFeatureProvisioningCallback callback) {
5758 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5759 mApp, subId, "registerFeatureProvisioningChangedCallback");
5760
5761 final long identity = Binder.clearCallingIdentity();
5762 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5763 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5764 }
5765
joonhunshin91bc1952022-04-29 08:47:15 +00005766 try {
5767 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5768 if (controller == null) {
5769 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5770 "Device does not support IMS");
5771 }
5772 controller.addFeatureProvisioningChangedCallback(subId, callback);
5773 } finally {
5774 Binder.restoreCallingIdentity(identity);
5775 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005776 }
5777
5778 @Override
5779 public void unregisterFeatureProvisioningChangedCallback(int subId,
5780 IFeatureProvisioningCallback callback) {
5781 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5782 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5783
5784 final long identity = Binder.clearCallingIdentity();
5785 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5786 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5787 }
5788
joonhunshin91bc1952022-04-29 08:47:15 +00005789 try {
5790 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5791 if (controller == null) {
5792 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5793 return;
5794 }
5795 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5796 } finally {
5797 Binder.restoreCallingIdentity(identity);
5798 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005799 }
allenwtsu99c623b2020-01-03 18:24:23 +08005800
5801 private void checkModifyPhoneStatePermission(int subId, String message) {
5802 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5803 message);
5804 }
5805
allenwtsu99c623b2020-01-03 18:24:23 +08005806 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005807 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005808 boolean isProvisioned) {
5809 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5810
5811 final long identity = Binder.clearCallingIdentity();
5812 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005813 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5814 if (controller == null) {
5815 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5816 return;
5817 }
5818 controller.setRcsProvisioningStatusForCapability(
5819 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005820 } finally {
5821 Binder.restoreCallingIdentity(identity);
5822 }
allenwtsu99c623b2020-01-03 18:24:23 +08005823 }
5824
5825
5826 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005827 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5828 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5829 mApp, subId, "getRcsProvisioningStatusForCapability");
5830
allenwtsu99c623b2020-01-03 18:24:23 +08005831 final long identity = Binder.clearCallingIdentity();
5832 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005833 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5834 if (controller == null) {
5835 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5836
5837 // device does not support IMS, this method will return true always.
5838 return true;
5839 }
5840 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005841 } finally {
5842 Binder.restoreCallingIdentity(identity);
5843 }
5844 }
5845
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005846 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005847 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5848 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005849 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005850
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005851 final long identity = Binder.clearCallingIdentity();
5852 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005853 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5854 if (controller == null) {
5855 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5856 return;
5857 }
5858 controller.setImsProvisioningStatusForCapability(
5859 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005860 } finally {
5861 Binder.restoreCallingIdentity(identity);
5862 }
5863 }
5864
5865 @Override
5866 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005867 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5868 mApp, subId, "getProvisioningStatusForCapability");
5869
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005870 final long identity = Binder.clearCallingIdentity();
5871 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005872 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5873 if (controller == null) {
5874 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005875
joonhunshin91bc1952022-04-29 08:47:15 +00005876 // device does not support IMS, this method will return true always.
5877 return true;
5878 }
5879 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005880 } finally {
5881 Binder.restoreCallingIdentity(identity);
5882 }
5883 }
5884
5885 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005886 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5887 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5888 mApp, subId, "isProvisioningRequiredForCapability");
5889
5890 final long identity = Binder.clearCallingIdentity();
5891 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005892 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5893 if (controller == null) {
5894 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5895
5896 // device does not support IMS, this method will return false
5897 return false;
5898 }
5899 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005900 } finally {
5901 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005902 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005903 }
5904
5905 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005906 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5907 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5908 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005909
joonhunshincffb7fc2021-11-28 07:32:01 +00005910 final long identity = Binder.clearCallingIdentity();
5911 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005912 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5913 if (controller == null) {
5914 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5915
5916 // device does not support IMS, this method will return false
5917 return false;
5918 }
5919 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005920 } finally {
5921 Binder.restoreCallingIdentity(identity);
5922 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005923 }
5924
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005925 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005926 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005927 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5928 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5929 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005930 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5931 mApp, subId, "getImsProvisioningInt");
5932
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005933 final long identity = Binder.clearCallingIdentity();
5934 try {
5935 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005936 int slotId = getSlotIndex(subId);
5937 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5938 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5939 + subId + "' for key:" + key);
5940 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5941 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005942
joonhunshin91bc1952022-04-29 08:47:15 +00005943 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5944 if (controller == null) {
5945 loge("getImsProvisioningInt: Device does not support IMS");
5946
5947 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5948 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5949 }
5950 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005951 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5952 return retVal;
5953 }
5954
calvinpanb5a34062021-02-08 19:59:36 +08005955 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005956 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005957 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5958 + subId + "' for key:" + key);
5959 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005960 } finally {
5961 Binder.restoreCallingIdentity(identity);
5962 }
5963 }
5964
5965 @Override
5966 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005967 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5968 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5969 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005970 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5971 mApp, subId, "getImsProvisioningString");
5972
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005973 final long identity = Binder.clearCallingIdentity();
5974 try {
5975 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005976 int slotId = getSlotIndex(subId);
5977 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5978 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5979 + subId + "' for key:" + key);
5980 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5981 }
calvinpanb5a34062021-02-08 19:59:36 +08005982 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005983 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005984 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5985 + subId + "' for key:" + key);
5986 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005987 } finally {
5988 Binder.restoreCallingIdentity(identity);
5989 }
5990 }
5991
5992 @Override
5993 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005994 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5995 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5996 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005997 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5998 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005999
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07006000 final long identity = Binder.clearCallingIdentity();
6001 try {
6002 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006003 int slotId = getSlotIndex(subId);
6004 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6005 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
6006 + subId + "' for key:" + key);
6007 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
6008 }
joonhunshincffb7fc2021-11-28 07:32:01 +00006009
joonhunshin91bc1952022-04-29 08:47:15 +00006010 ImsProvisioningController controller = ImsProvisioningController.getInstance();
6011 if (controller == null) {
6012 loge("setImsProvisioningInt: Device does not support IMS");
6013
6014 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
6015 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
6016 }
6017 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00006018 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
6019 return retVal;
6020 }
6021
calvinpanb5a34062021-02-08 19:59:36 +08006022 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
6023 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006024 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08006025 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006026 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07006027 } finally {
6028 Binder.restoreCallingIdentity(identity);
6029 }
6030 }
6031
6032 @Override
6033 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006034 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
6035 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
6036 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08006037 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
6038 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07006039 final long identity = Binder.clearCallingIdentity();
6040 try {
6041 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006042 int slotId = getSlotIndex(subId);
6043 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6044 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
6045 + subId + "' for key:" + key);
6046 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
6047 }
calvinpanb5a34062021-02-08 19:59:36 +08006048 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
6049 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006050 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08006051 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006052 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07006053 } finally {
6054 Binder.restoreCallingIdentity(identity);
6055 }
6056 }
6057
Brad Ebinger919631e2021-06-02 17:46:35 -07006058 /**
6059 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
6060 * for the given slot ID or no ImsResolver instance has been created.
6061 * @param slotId The slot ID that the IMS service is created for.
6062 * @throws ImsException If there is no ImsService configured for this slot.
6063 */
6064 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
6065 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
6066 ImsFeature.FEATURE_MMTEL)) {
6067 throw new ImsException("This subscription does not support MMTEL over IMS",
6068 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
6069 }
6070 }
6071
Brad Ebinger1ce9c432019-07-16 13:19:44 -07006072 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006073 int slotId = SubscriptionManager.getSlotIndex(subId);
6074 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07006075 throw new ImsException("Invalid Subscription Id, subId=" + subId,
6076 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07006077 }
6078 return slotId;
6079 }
6080
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006081 private int getSlotIndex(int subId) {
6082 int slotId = SubscriptionManager.getSlotIndex(subId);
6083 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
6084 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
6085 }
6086 return slotId;
6087 }
6088
Wink Saville36469e72014-06-11 15:17:00 -07006089 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07006090 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07006091 */
6092 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006093 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
6094 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07006095 try {
6096 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6097 } catch (SecurityException se) {
6098 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
6099 throw new SecurityException("Package " + callingPackage + " does not belong to "
6100 + Binder.getCallingUid());
6101 }
Nathan Haroldf096d982020-11-18 17:18:06 -08006102 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07006103 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006104 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07006105 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07006106 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006107 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006108 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006109 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
6110 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07006111
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006112 final long identity = Binder.clearCallingIdentity();
6113 try {
6114 final Phone phone = getPhone(subId);
6115 if (phone != null) {
6116 return phone.getServiceState().getDataNetworkType();
6117 } else {
6118 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
6119 }
6120 } finally {
6121 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006122 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006123 }
6124
6125 /**
6126 * Returns the data network type
6127 */
6128 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006129 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08006130 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08006131 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07006132 }
6133
6134 /**
6135 * Returns the data network type for a subId
6136 */
6137 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006138 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
6139 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006140 String functionName = "getDataNetworkTypeForSubscriber";
6141 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
6142 mApp, functionName)) {
6143 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6144 mApp, subId, callingPackage, callingFeatureId, functionName)) {
6145 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
6146 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006147 }
6148
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006149 final long identity = Binder.clearCallingIdentity();
6150 try {
6151 final Phone phone = getPhone(subId);
6152 if (phone != null) {
6153 return phone.getServiceState().getDataNetworkType();
6154 } else {
6155 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
6156 }
6157 } finally {
6158 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006159 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006160 }
6161
6162 /**
Wink Saville36469e72014-06-11 15:17:00 -07006163 * Returns the Voice network type for a subId
6164 */
6165 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006166 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
6167 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006168 String functionName = "getVoiceNetworkTypeForSubscriber";
6169 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
6170 mApp, functionName)) {
6171 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6172 mApp, subId, callingPackage, callingFeatureId, functionName)) {
6173 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
6174 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07006175 }
6176
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006177 final long identity = Binder.clearCallingIdentity();
6178 try {
6179 final Phone phone = getPhone(subId);
6180 if (phone != null) {
6181 return phone.getServiceState().getVoiceNetworkType();
6182 } else {
6183 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
6184 }
6185 } finally {
6186 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006187 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006188 }
6189
6190 /**
6191 * @return true if a ICC card is present
6192 */
6193 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07006194 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08006195 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006196 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07006197 }
6198
6199 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006200 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07006201 */
Sanket Padawe356d7632015-06-22 14:03:32 -07006202 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006203 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006204 final long identity = Binder.clearCallingIdentity();
6205 try {
6206 final Phone phone = PhoneFactory.getPhone(slotIndex);
6207 if (phone != null) {
6208 return phone.getIccCard().hasIccCard();
6209 } else {
6210 return false;
6211 }
6212 } finally {
6213 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08006214 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006215 }
6216
6217 /**
6218 * Return if the current radio is LTE on CDMA. This
6219 * is a tri-state return value as for a period of time
6220 * the mode may be unknown.
6221 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006222 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006223 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08006224 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006225 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006226 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006227 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
6228 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
6229 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07006230 }
6231
Sanket Padawe356d7632015-06-22 14:03:32 -07006232 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006233 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
6234 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08006235 try {
6236 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
6237 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006238 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
6239 }
6240
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006241 final long identity = Binder.clearCallingIdentity();
6242 try {
6243 final Phone phone = getPhone(subId);
6244 if (phone == null) {
6245 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
6246 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07006247 return TelephonyProperties.lte_on_cdma_device()
6248 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006249 }
6250 } finally {
6251 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006252 }
Wink Saville36469e72014-06-11 15:17:00 -07006253 }
6254
Wink Saville36469e72014-06-11 15:17:00 -07006255 /**
6256 * {@hide}
6257 * Returns Default subId, 0 in the case of single standby.
6258 */
Wink Savilleb564aae2014-10-23 10:18:09 -07006259 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08006260 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07006261 }
6262
Shishir Agrawala9f32182016-04-12 12:00:16 -07006263 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08006264 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07006265 }
6266
Wink Savilleb564aae2014-10-23 10:18:09 -07006267 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08006268 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006269 }
Ihab Awadf2177b72013-11-25 13:33:23 -08006270
Pengquan Menge92a50d2018-09-21 15:54:48 -07006271 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08006272 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08006273 return getSubscriptionManagerService().isActiveSubId(subId,
Jack Yu285100e2022-12-02 22:48:35 -08006274 mApp.getOpPackageName(), mApp.getFeatureId());
6275 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07006276 return mSubscriptionController.isActiveSubId(subId);
6277 }
6278
Ihab Awadf2177b72013-11-25 13:33:23 -08006279 /**
6280 * @see android.telephony.TelephonyManager.WifiCallingChoices
6281 */
6282 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006283 final long identity = Binder.clearCallingIdentity();
6284 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006285 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006286 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
6287 getWhenToMakeWifiCallsDefaultPreference());
6288 } finally {
6289 Binder.restoreCallingIdentity(identity);
6290 }
Ihab Awadf2177b72013-11-25 13:33:23 -08006291 }
6292
6293 /**
6294 * @see android.telephony.TelephonyManager.WifiCallingChoices
6295 */
6296 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006297 final long identity = Binder.clearCallingIdentity();
6298 try {
6299 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006300 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006301 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
6302 } finally {
6303 Binder.restoreCallingIdentity(identity);
6304 }
Ihab Awadf9e92732013-12-05 18:02:52 -08006305 }
6306
Sailesh Nepald1e68152013-12-12 19:08:02 -08006307 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07006308 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08006309 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08006310 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08006311
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006312 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
6313 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
6314 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08006315 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006316 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006317 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08006318 }
6319 return PhoneFactory.getPhone(phoneId);
6320 }
6321
Shishir Agrawal566b7612013-10-28 14:41:00 -07006322 @Override
Derek Tan740e1672017-06-27 14:56:27 -07006323 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08006324 @NonNull IccLogicalChannelRequest request) {
6325 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6326 /*message=*/ "iccOpenLogicalChannel");
6327
6328 if (DBG) log("iccOpenLogicalChannel: request=" + request);
6329 // Verify that the callingPackage in the request belongs to the calling UID
6330 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
6331
6332 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006333 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006334
Rambo Wanga1782702021-11-10 20:15:19 -08006335 private Phone getPhoneFromValidIccLogicalChannelRequest(
6336 @NonNull IccLogicalChannelRequest request, String message) {
6337 Phone phone;
6338 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
6339 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6340 mApp, request.subId, message);
6341 phone = getPhoneFromSubId(request.subId);
6342 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6343 enforceModifyPermission();
6344 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
6345 } else {
6346 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08006347 }
Rambo Wanga1782702021-11-10 20:15:19 -08006348 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08006349 }
6350
6351 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08006352 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006353 final long identity = Binder.clearCallingIdentity();
6354 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006355 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006356 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006357 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6358 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08006359 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
6360 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006361 loge("The calling package is not allowed to access ISD-R.");
6362 throw new SecurityException(
6363 "The calling package is not allowed to access ISD-R.");
6364 }
Derek Tan740e1672017-06-27 14:56:27 -07006365 }
Derek Tan740e1672017-06-27 14:56:27 -07006366
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006367 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006368 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6369 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006370 return response;
6371 } finally {
6372 Binder.restoreCallingIdentity(identity);
6373 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006374 }
6375
6376 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006377 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
6378 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6379 /*message=*/"iccCloseLogicalChannel");
6380
6381 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6382
6383 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006384 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006385
Rambo Wanga1782702021-11-10 20:15:19 -08006386 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6387 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006388 // before this feature is enabled, this API should only return false if
6389 // the operation fails instead of throwing runtime exception for
6390 // backward-compatibility.
6391 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6392 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006393 final long identity = Binder.clearCallingIdentity();
6394 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006395 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006396 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006397 }
Chen Xue9d737e2022-01-01 23:41:31 -08006398 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006399 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006400 Boolean success = false;
6401 if (result instanceof RuntimeException) {
6402 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006403 if (shouldThrowExceptionOnFailure) {
6404 throw (RuntimeException) result;
6405 } else {
6406 return false;
6407 }
Chen Xue9d737e2022-01-01 23:41:31 -08006408 } else if (result instanceof Boolean) {
6409 success = (Boolean) result;
6410 } else {
6411 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6412 }
Rambo Wanga1782702021-11-10 20:15:19 -08006413 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006414 return success;
6415 } finally {
6416 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006417 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006418 }
6419
6420 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006421 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006422 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006423 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6424 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08006425 if (DBG) {
6426 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6427 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6428 + p3 + " data=" + data);
6429 }
6430 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6431 command, p1, p2, p3, data);
6432 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006433
Jordan Liu4c733742019-02-28 12:03:40 -08006434 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006435 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006436 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006437 enforceModifyPermission();
6438 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006439 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006440 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6441 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006442 }
6443 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006444 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6445 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006446 }
6447
6448 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6449 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006450 final long identity = Binder.clearCallingIdentity();
6451 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006452 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006453 return "";
6454 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006455
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006456 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006457 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6458 null /* workSource */);
6459 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006460
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006461 // Append the returned status code to the end of the response payload.
6462 String s = Integer.toHexString(
6463 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6464 if (response.payload != null) {
6465 s = IccUtils.bytesToHexString(response.payload) + s;
6466 }
6467 return s;
6468 } finally {
6469 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006470 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006471 }
Jake Hambye994d462014-02-03 13:10:13 -08006472
Evan Charltonc66da362014-05-16 14:06:40 -07006473 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006474 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6475 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006476 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6477 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006478 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08006479 if (DBG) {
6480 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6481 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6482 }
6483 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6484 cla, command, p1, p2, p3, data);
6485 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006486
Jordan Liu4c733742019-02-28 12:03:40 -08006487 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006488 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006489 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006490 enforceModifyPermission();
6491 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6492 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006493 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006494 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6495 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006496 }
6497
6498 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006499 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6500 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006501 }
6502
6503 // open APDU basic channel assuming the caller has sufficient permissions
6504 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6505 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006506 final long identity = Binder.clearCallingIdentity();
6507 try {
6508 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6509 && TextUtils.equals(ISDR_AID, data)) {
6510 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006511 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6512 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006513 if (bestComponent == null
6514 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6515 loge("The calling package is not allowed to select ISD-R.");
6516 throw new SecurityException(
6517 "The calling package is not allowed to select ISD-R.");
6518 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006519 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006520
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006521 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006522 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6523 null /* workSource */);
6524 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006525
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006526 // Append the returned status code to the end of the response payload.
6527 String s = Integer.toHexString(
6528 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6529 if (response.payload != null) {
6530 s = IccUtils.bytesToHexString(response.payload) + s;
6531 }
6532 return s;
6533 } finally {
6534 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006535 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006536 }
6537
6538 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006539 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006540 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006541 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6542 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006543
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006544 final long identity = Binder.clearCallingIdentity();
6545 try {
6546 if (DBG) {
6547 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6548 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6549 }
6550
6551 IccIoResult response =
6552 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6553 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6554 subId);
6555
6556 if (DBG) {
6557 log("Exchange SIM_IO [R]" + response);
6558 }
6559
6560 byte[] result = null;
6561 int length = 2;
6562 if (response.payload != null) {
6563 length = 2 + response.payload.length;
6564 result = new byte[length];
6565 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6566 } else {
6567 result = new byte[length];
6568 }
6569
6570 result[length - 1] = (byte) response.sw2;
6571 result[length - 2] = (byte) response.sw1;
6572 return result;
6573 } finally {
6574 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006575 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006576 }
6577
Nathan Haroldb3014052017-01-25 15:57:32 -08006578 /**
6579 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6580 * on a particular subscription
6581 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006582 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6583 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006584 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006585 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006586 return null;
6587 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006588
6589 final long identity = Binder.clearCallingIdentity();
6590 try {
6591 if (appType != TelephonyManager.APPTYPE_USIM
6592 && appType != TelephonyManager.APPTYPE_SIM) {
6593 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6594 return null;
6595 }
6596 Object response = sendRequest(
6597 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6598 if (response instanceof String[]) {
6599 return (String[]) response;
6600 }
yincheng zhao2737e882019-09-06 17:06:54 -07006601 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006602 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006603 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006604 } finally {
6605 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006606 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006607 }
6608
yincheng zhao2737e882019-09-06 17:06:54 -07006609 /**
6610 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6611 * subscription.
6612 *
6613 * @param subId the id of the subscription.
6614 * @param appType the uicc app type, must be USIM or SIM.
6615 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6616 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006617 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006618 * @return number of fplmns that is successfully written to the SIM.
6619 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006620 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6621 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006622 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6623 mApp, subId, "setForbiddenPlmns");
6624
yincheng zhao2737e882019-09-06 17:06:54 -07006625 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6626 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6627 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6628 }
6629 if (fplmns == null) {
6630 throw new IllegalArgumentException("Fplmn List provided is null");
6631 }
6632 for (String fplmn : fplmns) {
6633 if (!CellIdentity.isValidPlmn(fplmn)) {
6634 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6635 }
6636 }
6637 final long identity = Binder.clearCallingIdentity();
6638 try {
6639 Object response = sendRequest(
6640 CMD_SET_FORBIDDEN_PLMNS,
6641 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6642 subId);
6643 return (int) response;
6644 } finally {
6645 Binder.restoreCallingIdentity(identity);
6646 }
6647 }
6648
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006649 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006650 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006651 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6652 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006653
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006654 final long identity = Binder.clearCallingIdentity();
6655 try {
6656 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6657 if (response.payload == null) {
6658 return "";
6659 }
Evan Charltonc66da362014-05-16 14:06:40 -07006660
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006661 // Append the returned status code to the end of the response payload.
6662 String s = Integer.toHexString(
6663 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6664 s = IccUtils.bytesToHexString(response.payload) + s;
6665 return s;
6666 } finally {
6667 Binder.restoreCallingIdentity(identity);
6668 }
Evan Charltonc66da362014-05-16 14:06:40 -07006669 }
6670
Jake Hambye994d462014-02-03 13:10:13 -08006671 /**
6672 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6673 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6674 *
6675 * @param itemID the ID of the item to read
6676 * @return the NV item as a String, or null on error.
6677 */
6678 @Override
6679 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006680 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6682 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006683
6684 final long identity = Binder.clearCallingIdentity();
6685 try {
6686 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006687 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006688 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6689 return value;
6690 } finally {
6691 Binder.restoreCallingIdentity(identity);
6692 }
Jake Hambye994d462014-02-03 13:10:13 -08006693 }
6694
6695 /**
6696 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6697 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6698 *
6699 * @param itemID the ID of the item to read
6700 * @param itemValue the value to write, as a String
6701 * @return true on success; false on any failure
6702 */
6703 @Override
6704 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006705 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006706 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6707 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006708
6709 final long identity = Binder.clearCallingIdentity();
6710 try {
6711 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6712 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006713 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006714 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6715 return success;
6716 } finally {
6717 Binder.restoreCallingIdentity(identity);
6718 }
Jake Hambye994d462014-02-03 13:10:13 -08006719 }
6720
6721 /**
6722 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6723 * Used for device configuration by some CDMA operators.
6724 *
6725 * @param preferredRoamingList byte array containing the new PRL
6726 * @return true on success; false on any failure
6727 */
6728 @Override
6729 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6731 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006732
6733 final long identity = Binder.clearCallingIdentity();
6734 try {
6735 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6736 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6737 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6738 return success;
6739 } finally {
6740 Binder.restoreCallingIdentity(identity);
6741 }
Jake Hambye994d462014-02-03 13:10:13 -08006742 }
6743
6744 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006745 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006746 * Used for device configuration by some CDMA operators.
6747 *
chen xu6dac5ab2018-10-26 17:39:23 -07006748 * @param slotIndex - device slot.
6749 *
Jake Hambye994d462014-02-03 13:10:13 -08006750 * @return true on success; false on any failure
6751 */
6752 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006753 public boolean resetModemConfig(int slotIndex) {
6754 Phone phone = PhoneFactory.getPhone(slotIndex);
6755 if (phone != null) {
6756 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6757 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006758
chen xu6dac5ab2018-10-26 17:39:23 -07006759 final long identity = Binder.clearCallingIdentity();
6760 try {
6761 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6762 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6763 return success;
6764 } finally {
6765 Binder.restoreCallingIdentity(identity);
6766 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006767 }
chen xu6dac5ab2018-10-26 17:39:23 -07006768 return false;
6769 }
6770
6771 /**
6772 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6773 *
6774 * @param slotIndex - device slot.
6775 *
6776 * @return true on success; false on any failure
6777 */
6778 @Override
6779 public boolean rebootModem(int slotIndex) {
6780 Phone phone = PhoneFactory.getPhone(slotIndex);
6781 if (phone != null) {
6782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6783 mApp, phone.getSubId(), "rebootModem");
6784
6785 final long identity = Binder.clearCallingIdentity();
6786 try {
6787 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6788 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6789 return success;
6790 } finally {
6791 Binder.restoreCallingIdentity(identity);
6792 }
6793 }
6794 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006795 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006796
Brad Ebinger51f743a2017-01-23 13:50:20 -08006797 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006798 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6799 * {@link #disableIms(int)}.
6800 * @param slotIndex device slot.
6801 */
6802 public void resetIms(int slotIndex) {
6803 enforceModifyPermission();
6804
6805 final long identity = Binder.clearCallingIdentity();
6806 try {
6807 if (mImsResolver == null) {
6808 // may happen if the does not support IMS.
6809 return;
6810 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006811 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006812 } finally {
6813 Binder.restoreCallingIdentity(identity);
6814 }
6815 }
6816
6817 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006818 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6819 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006820 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006821 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006822 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006823
6824 final long identity = Binder.clearCallingIdentity();
6825 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006826 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006827 // may happen if the device does not support IMS.
6828 return;
6829 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006830 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006831 } finally {
6832 Binder.restoreCallingIdentity(identity);
6833 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006834 }
6835
6836 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006837 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6838 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006839 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006840 public void disableIms(int slotId) {
6841 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006842
6843 final long identity = Binder.clearCallingIdentity();
6844 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006845 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006846 // may happen if the device does not support IMS.
6847 return;
6848 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006849 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006850 } finally {
6851 Binder.restoreCallingIdentity(identity);
6852 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006853 }
6854
6855 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006856 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6857 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006858 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006859 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006860 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006861 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006862
6863 final long identity = Binder.clearCallingIdentity();
6864 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006865 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006866 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6867 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006868 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006869 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006870 } finally {
6871 Binder.restoreCallingIdentity(identity);
6872 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006873 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006874 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006875 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6876 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006877 @Override
6878 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006879 enforceModifyPermission();
6880
6881 final long identity = Binder.clearCallingIdentity();
6882 try {
6883 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006884 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006885 } finally {
6886 Binder.restoreCallingIdentity(identity);
6887 }
6888 }
6889
6890 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006891 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006892 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006893 */
6894 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6895 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006896
6897 final long identity = Binder.clearCallingIdentity();
6898 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006899 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006900 // may happen if the device does not support IMS.
6901 return null;
6902 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006903 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006904 } finally {
6905 Binder.restoreCallingIdentity(identity);
6906 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006907 }
6908
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006909 /**
6910 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006911 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006912 */
6913 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6914 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006915
6916 final long identity = Binder.clearCallingIdentity();
6917 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006918 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006919 // may happen if the device does not support IMS.
6920 return null;
6921 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006922 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006923 } finally {
6924 Binder.restoreCallingIdentity(identity);
6925 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006926 }
6927
Brad Ebinger884c07b2018-02-15 16:17:40 -08006928 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006929 * Sets the ImsService Package Name that Telephony will bind to.
6930 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006931 * @param slotIndex the slot ID that the ImsService should bind for.
6932 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006933 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006934 * @param featureTypes An integer array of feature types associated with a packageName.
6935 * @param packageName The name of the package that the current configuration will be replaced
6936 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006937 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006938 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006939 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6940 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006941 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006943 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006944
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006945 final long identity = Binder.clearCallingIdentity();
6946 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006947 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006948 // may happen if the device does not support IMS.
6949 return false;
6950 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006951 Map<Integer, String> featureConfig = new HashMap<>();
6952 for (int featureType : featureTypes) {
6953 featureConfig.put(featureType, packageName);
6954 }
6955 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6956 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006957 } finally {
6958 Binder.restoreCallingIdentity(identity);
6959 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006960 }
6961
6962 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006963 * Clears any carrier ImsService overrides for the slot index specified that were previously
6964 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6965 *
6966 * This should only be used for testing.
6967 *
6968 * @param slotIndex the slot ID that the ImsService should bind for.
6969 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6970 */
6971 @Override
6972 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006973 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6974 "clearCarrierImsServiceOverride");
6975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006976 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006977
6978 final long identity = Binder.clearCallingIdentity();
6979 try {
6980 if (mImsResolver == null) {
6981 // may happen if the device does not support IMS.
6982 return false;
6983 }
6984 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6985 } finally {
6986 Binder.restoreCallingIdentity(identity);
6987 }
6988 }
6989
6990 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006991 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006992 *
6993 * @param slotId The slot that the ImsService is associated with.
6994 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6995 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006996 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006997 * @return the package name of the ImsService configuration.
6998 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006999 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
7000 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08007001 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08007002 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
7003 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07007004
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007005 final long identity = Binder.clearCallingIdentity();
7006 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08007007 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08007008 // may happen if the device does not support IMS.
7009 return "";
7010 }
Brad Ebingera80c3312019-12-02 10:59:39 -08007011 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08007012 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
7013 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007014 } finally {
7015 Binder.restoreCallingIdentity(identity);
7016 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07007017 }
7018
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007019 /**
7020 * Get the MmTelFeature state associated with the requested subscription id.
7021 * @param subId The subscription that the MmTelFeature is associated with.
7022 * @param callback A callback with an integer containing the
7023 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
7024 */
7025 @Override
7026 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
7027 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00007028 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
7029 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
7030 "IMS not available on device.");
7031 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007032 final long token = Binder.clearCallingIdentity();
7033 try {
Brad Ebingera2628302022-02-18 03:44:55 +00007034 int slotId = getSlotIndex(subId);
7035 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7036 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
7037 + subId + "'");
7038 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
7039 }
7040 verifyImsMmTelConfiguredOrThrow(slotId);
7041 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
7042 try {
7043 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
7044 } catch (RemoteException e) {
7045 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
7046 + "Ignore");
7047 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007048 });
Brad Ebinger919631e2021-06-02 17:46:35 -07007049 } catch (ImsException e) {
7050 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007051 } finally {
7052 Binder.restoreCallingIdentity(token);
7053 }
7054 }
7055
Daniel Brightbb5840b2021-01-12 15:48:18 -08007056 /**
7057 * Sets the ims registration state on all valid {@link Phone}s.
7058 */
7059 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07007060 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007061
7062 final long identity = Binder.clearCallingIdentity();
7063 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08007064 // NOTE: Before S, this method only set the default phone.
7065 for (final Phone phone : PhoneFactory.getPhones()) {
7066 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
7067 phone.setImsRegistrationState(registered);
7068 }
7069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007070 } finally {
7071 Binder.restoreCallingIdentity(identity);
7072 }
Wink Saville36469e72014-06-11 15:17:00 -07007073 }
7074
7075 /**
Stuart Scott54788802015-03-30 13:18:01 -07007076 * Set the network selection mode to automatic.
7077 *
7078 */
7079 @Override
7080 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7082 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007083
7084 final long identity = Binder.clearCallingIdentity();
7085 try {
shilufc958392020-01-20 11:36:01 -08007086 if (!isActiveSubscription(subId)) {
7087 return;
7088 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007089 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08007090 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
7091 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007092 } finally {
7093 Binder.restoreCallingIdentity(identity);
7094 }
Stuart Scott54788802015-03-30 13:18:01 -07007095 }
7096
Jack Yud10cdd42020-09-28 20:28:01 -07007097 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07007098 * Ask the radio to connect to the input network and change selection mode to manual.
7099 *
7100 * @param subId the id of the subscription.
7101 * @param operatorInfo the operator information, included the PLMN, long name and short name of
7102 * the operator to attach to.
7103 * @param persistSelection whether the selection will persist until reboot. If true, only allows
7104 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
7105 * normal network selection next time.
7106 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07007107 */
7108 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07007109 public boolean setNetworkSelectionModeManual(
7110 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007111 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7112 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07007113
Jack Yu285100e2022-12-02 22:48:35 -08007114 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07007115 if (!isActiveSubscription(subId)) {
7116 return false;
7117 }
7118
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007119 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07007120 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007121 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07007122 if (DBG) {
7123 log("setNetworkSelectionModeManual: subId: " + subId
7124 + " operator: " + operatorInfo);
7125 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007126 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
7127 } finally {
7128 Binder.restoreCallingIdentity(identity);
7129 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07007130 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007131 /**
shilu84f6e8b2019-12-19 13:58:01 -08007132 * Get the manual network selection
7133 *
7134 * @param subId the id of the subscription.
7135 *
7136 * @return the previously saved user selected PLMN
7137 */
7138 @Override
7139 public String getManualNetworkSelectionPlmn(int subId) {
7140 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007141 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
7142 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08007143
7144 final long identity = Binder.clearCallingIdentity();
7145 try {
7146 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07007147 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08007148 }
7149
7150 final Phone phone = getPhone(subId);
7151 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07007152 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08007153 }
7154 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
7155 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007156 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08007157 } finally {
7158 Binder.restoreCallingIdentity(identity);
7159 }
7160 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07007161
7162 /**
7163 * Scans for available networks.
7164 */
7165 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007166 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
7167 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007168 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7169 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08007170 LocationAccessPolicy.LocationPermissionResult locationResult =
7171 LocationAccessPolicy.checkLocationPermission(mApp,
7172 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7173 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007174 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007175 .setCallingPid(Binder.getCallingPid())
7176 .setCallingUid(Binder.getCallingUid())
7177 .setMethod("getCellNetworkScanResults")
7178 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007179 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7180 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007181 .build());
7182 switch (locationResult) {
7183 case DENIED_HARD:
7184 throw new SecurityException("Not allowed to access scan results -- location");
7185 case DENIED_SOFT:
7186 return null;
7187 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007188
Pengquan Menga1bb6272018-09-06 09:59:22 -07007189 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007190 try {
7191 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07007192 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007193 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007194 } finally {
7195 Binder.restoreCallingIdentity(identity);
7196 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07007197 }
7198
7199 /**
Shuo Qian4a594052020-01-23 11:59:30 -08007200 * Get the call forwarding info, given the call forwarding reason.
7201 */
7202 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007203 public void getCallForwarding(int subId, int callForwardingReason,
7204 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007205 enforceReadPrivilegedPermission("getCallForwarding");
7206 long identity = Binder.clearCallingIdentity();
7207 try {
7208 if (DBG) {
7209 log("getCallForwarding: subId " + subId
7210 + " callForwardingReason" + callForwardingReason);
7211 }
Hall Liu27d24262020-09-18 19:04:59 -07007212
7213 Phone phone = getPhone(subId);
7214 if (phone == null) {
7215 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07007216 callback.onError(
7217 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07007218 } catch (RemoteException e) {
7219 // ignore
7220 }
7221 return;
7222 }
7223
7224 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
7225 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
7226 @Override
7227 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
7228 try {
7229 callback.onCallForwardingInfoAvailable(info);
7230 } catch (RemoteException e) {
7231 // ignore
7232 }
7233 }
7234
7235 @Override
7236 public void onError(int error) {
7237 try {
7238 callback.onError(error);
7239 } catch (RemoteException e) {
7240 // ignore
7241 }
7242 }
7243 });
7244 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08007245 } finally {
7246 Binder.restoreCallingIdentity(identity);
7247 }
7248 }
7249
7250 /**
7251 * Sets the voice call forwarding info including status (enable/disable), call forwarding
7252 * reason, the number to forward, and the timeout before the forwarding is attempted.
7253 */
7254 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007255 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
7256 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007257 enforceModifyPermission();
7258 long identity = Binder.clearCallingIdentity();
7259 try {
7260 if (DBG) {
7261 log("setCallForwarding: subId " + subId
7262 + " callForwardingInfo" + callForwardingInfo);
7263 }
Hall Liu27d24262020-09-18 19:04:59 -07007264
7265 Phone phone = getPhone(subId);
7266 if (phone == null) {
7267 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07007268 callback.accept(
7269 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07007270 } catch (RemoteException e) {
7271 // ignore
7272 }
7273 return;
7274 }
7275
7276 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
7277 FunctionalUtils.ignoreRemoteException(callback::accept));
7278
7279 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08007280 } finally {
7281 Binder.restoreCallingIdentity(identity);
7282 }
7283 }
7284
7285 /**
Hall Liu27d24262020-09-18 19:04:59 -07007286 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007287 */
7288 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007289 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08007290 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08007291 long identity = Binder.clearCallingIdentity();
7292 try {
Hall Liu27d24262020-09-18 19:04:59 -07007293 Phone phone = getPhone(subId);
7294 if (phone == null) {
7295 try {
7296 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7297 } catch (RemoteException e) {
7298 // ignore
7299 }
7300 return;
7301 }
SongFerngWang0e767992021-03-31 22:08:45 +08007302 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7303 PersistableBundle c = configManager.getConfigForSubId(subId);
7304 boolean requireUssd = c.getBoolean(
7305 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007306
Shuo Qian4a594052020-01-23 11:59:30 -08007307 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007308 if (requireUssd) {
7309 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7310 getSubscriptionCarrierId(subId));
7311 String newUssdCommand = "";
7312 try {
7313 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007314 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007315 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7316 } catch (NullPointerException e) {
7317 loge("Failed to generate USSD number" + e);
7318 }
7319 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7320 mMainThreadHandler, callback, carrierXmlParser,
7321 CarrierXmlParser.SsEntry.SSAction.QUERY);
7322 final String ussdCommand = newUssdCommand;
7323 Executors.newSingleThreadExecutor().execute(() -> {
7324 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7325 });
7326 } else {
7327 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7328 callback::accept);
7329 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7330 }
Shuo Qian4a594052020-01-23 11:59:30 -08007331 } finally {
7332 Binder.restoreCallingIdentity(identity);
7333 }
7334 }
7335
7336 /**
Hall Liu27d24262020-09-18 19:04:59 -07007337 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007338 */
7339 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007340 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007341 enforceModifyPermission();
7342 long identity = Binder.clearCallingIdentity();
7343 try {
Hall Liu27d24262020-09-18 19:04:59 -07007344 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7345
7346 Phone phone = getPhone(subId);
7347 if (phone == null) {
7348 try {
7349 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7350 } catch (RemoteException e) {
7351 // ignore
7352 }
7353 return;
7354 }
7355
SongFerngWang0e767992021-03-31 22:08:45 +08007356 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7357 PersistableBundle c = configManager.getConfigForSubId(subId);
7358 boolean requireUssd = c.getBoolean(
7359 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007360
SongFerngWang0e767992021-03-31 22:08:45 +08007361 if (DBG) log("getCallWaitingStatus: subId " + subId);
7362 if (requireUssd) {
7363 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7364 getSubscriptionCarrierId(subId));
7365 CarrierXmlParser.SsEntry.SSAction ssAction =
7366 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7367 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7368 String newUssdCommand = "";
7369 try {
7370 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007371 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007372 .makeCommand(ssAction, null);
7373 } catch (NullPointerException e) {
7374 loge("Failed to generate USSD number" + e);
7375 }
7376 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7377 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7378 final String ussdCommand = newUssdCommand;
7379 Executors.newSingleThreadExecutor().execute(() -> {
7380 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7381 });
7382 } else {
7383 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7384 FunctionalUtils.ignoreRemoteException(callback::accept));
7385
7386 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7387 }
Shuo Qian4a594052020-01-23 11:59:30 -08007388 } finally {
7389 Binder.restoreCallingIdentity(identity);
7390 }
7391 }
7392
7393 /**
yinxub1bed742017-04-17 11:45:04 -07007394 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007395 *
yinxub1bed742017-04-17 11:45:04 -07007396 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007397 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7398 * location related information which will be sent if the caller already possess
7399 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007400 * @param request contains the radio access networks with bands/channels to scan
7401 * @param messenger callback messenger for scan results or errors
7402 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007403 * @return the id of the requested scan which can be used to stop the scan.
7404 */
7405 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007406 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7407 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007408 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007409 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7410 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007411 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007412 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7413 if (!renounceFineLocationAccess) {
7414 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007415 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7416 .setCallingPackage(callingPackage)
7417 .setCallingFeatureId(callingFeatureId)
7418 .setCallingPid(Binder.getCallingPid())
7419 .setCallingUid(Binder.getCallingUid())
7420 .setMethod("requestNetworkScan")
7421 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7422 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7423 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7424 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007425 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007426 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007427 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7428 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007429 if (e != null) {
7430 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7431 throw e;
7432 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007433 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007434 return TelephonyScanManager.INVALID_SCAN_ID;
7435 }
7436 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007437 }
Hall Liu912dfd32019-04-25 14:02:26 -07007438 int callingUid = Binder.getCallingUid();
7439 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007440 final long identity = Binder.clearCallingIdentity();
7441 try {
7442 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007443 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007444 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007445 } finally {
7446 Binder.restoreCallingIdentity(identity);
7447 }
yinxu504e1392017-04-12 16:03:22 -07007448 }
7449
Hall Liub2ac8ef2019-02-28 15:56:23 -08007450 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007451 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007452 boolean hasCarrierPriv;
7453 final long identity = Binder.clearCallingIdentity();
7454 try {
7455 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7456 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7457 } finally {
7458 Binder.restoreCallingIdentity(identity);
7459 }
Hall Liu558027f2019-05-15 19:14:05 -07007460 boolean hasNetworkScanPermission =
7461 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007462 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007463
7464 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7465 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7466 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007467 }
7468
7469 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7470 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007471 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7472 return new SecurityException("Specific channels must not be"
7473 + " scanned without location access.");
7474 }
7475 }
7476 }
7477
Hall Liub2ac8ef2019-02-28 15:56:23 -08007478 return null;
7479 }
7480
yinxu504e1392017-04-12 16:03:22 -07007481 /**
7482 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007483 *
7484 * @param subId id of the subscription
7485 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007486 */
7487 @Override
7488 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007489 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7490 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007491
Hall Liu912dfd32019-04-25 14:02:26 -07007492 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007493 final long identity = Binder.clearCallingIdentity();
7494 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007495 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007496 } finally {
7497 Binder.restoreCallingIdentity(identity);
7498 }
yinxu504e1392017-04-12 16:03:22 -07007499 }
7500
7501 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007502 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007503 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007504 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007505 */
7506 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007507 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007508 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007509 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007510 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007511
7512 final long identity = Binder.clearCallingIdentity();
7513 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007514 if (DBG) log("getAllowedNetworkTypesBitmask");
7515 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7516 int networkTypesBitmask = (result != null ? result[0] : -1);
7517 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7518 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007519 } finally {
7520 Binder.restoreCallingIdentity(identity);
7521 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007522 }
7523
7524 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007525 * Get the allowed network types for certain reason.
7526 *
7527 * @param subId the id of the subscription.
7528 * @param reason the reason the allowed network type change is taking place
7529 * @return the allowed network types.
7530 */
7531 @Override
7532 public long getAllowedNetworkTypesForReason(int subId,
7533 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007534 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007535 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007536 final long identity = Binder.clearCallingIdentity();
7537 try {
7538 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
7539 } finally {
7540 Binder.restoreCallingIdentity(identity);
7541 }
7542 }
7543
7544 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007545 * Enable/Disable E-UTRA-NR Dual Connectivity
7546 * @param subId subscription id of the sim card
7547 * @param nrDualConnectivityState expected NR dual connectivity state
7548 * This can be passed following states
7549 * <ol>
7550 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7551 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7552 * <li>Disable NR dual connectivity and force secondary cell to be released
7553 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7554 * </ol>
7555 * @return operation result.
7556 */
7557 @Override
7558 public int setNrDualConnectivityState(int subId,
7559 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7561 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007562 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007563 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7564 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7565 }
7566
Sooraj Sasindran37444802020-08-11 10:40:43 -07007567 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7568 final long identity = Binder.clearCallingIdentity();
7569 try {
7570 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7571 nrDualConnectivityState, subId,
7572 workSource);
7573 if (DBG) log("enableNRDualConnectivity result: " + result);
7574 return result;
7575 } finally {
7576 Binder.restoreCallingIdentity(identity);
7577 }
7578 }
7579
7580 /**
7581 * Is E-UTRA-NR Dual Connectivity enabled
7582 * @return true if dual connectivity is enabled else false
7583 */
7584 @Override
7585 public boolean isNrDualConnectivityEnabled(int subId) {
7586 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007587 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007588 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007589 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007590 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7591 return false;
7592 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007593 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7594 final long identity = Binder.clearCallingIdentity();
7595 try {
7596 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7597 null, subId, workSource);
7598 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7599 return isEnabled;
7600 } finally {
7601 Binder.restoreCallingIdentity(identity);
7602 }
7603 }
7604
7605 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007606 * Set the allowed network types of the device and
7607 * provide the reason triggering the allowed network change.
7608 *
7609 * @param subId the id of the subscription.
7610 * @param reason the reason the allowed network type change is taking place
7611 * @param allowedNetworkTypes the allowed network types.
7612 * @return true on success; false on any failure.
7613 */
7614 @Override
7615 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007616 @TelephonyManager.AllowedNetworkTypesReason int reason,
7617 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7619 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007620 // If the caller only has carrier privileges, then they should not be able to override
7621 // any network types which were set for security reasons.
7622 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7623 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007624 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007625 throw new SecurityException(
7626 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007627 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007628 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08007629 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007630 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007631 return false;
7632 }
7633 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7634 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007635 return false;
7636 }
7637
Jack Yu5b494332023-01-23 18:18:04 +00007638 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7639 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007640
Jack Yue37dd262022-12-16 11:53:37 -08007641 Phone phone = getPhone(subId);
7642 if (phone == null) {
7643 return false;
7644 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007645
Jack Yue37dd262022-12-16 11:53:37 -08007646 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007647 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007648 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007649 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007650
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007651 final long identity = Binder.clearCallingIdentity();
7652 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007653 Boolean success = (Boolean) sendRequest(
7654 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7655 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7656
7657 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7658 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007659 } finally {
7660 Binder.restoreCallingIdentity(identity);
7661 }
7662 }
7663
7664 /**
Miaoa84611c2019-03-15 09:21:10 +08007665 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007666 *
Miaoa84611c2019-03-15 09:21:10 +08007667 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007668 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007669 * @hide
7670 */
7671 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007672 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007673 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007674 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007675 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007676 try {
Miaoa84611c2019-03-15 09:21:10 +08007677 if (phone != null) {
7678 return phone.hasMatchedTetherApnSetting();
7679 } else {
7680 return false;
7681 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007682 } finally {
7683 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007684 }
Junda Liu475951f2014-11-07 16:45:03 -08007685 }
7686
7687 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007688 * Get the user enabled state of Mobile Data.
7689 *
7690 * TODO: remove and use isUserDataEnabled.
7691 * This can't be removed now because some vendor codes
7692 * calls through ITelephony directly while they should
7693 * use TelephonyManager.
7694 *
7695 * @return true on enabled
7696 */
7697 @Override
7698 public boolean getDataEnabled(int subId) {
7699 return isUserDataEnabled(subId);
7700 }
7701
7702 /**
7703 * Get whether mobile data is enabled per user setting.
7704 *
7705 * There are other factors deciding whether mobile data is actually enabled, but they are
7706 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007707 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007708 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7709 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007710 *
7711 * @return {@code true} if data is enabled else {@code false}
7712 */
7713 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007714 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007715 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007716 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007717 try {
7718 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7719 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007720 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007721 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7722 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007723 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007724 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007725 mApp, subId, functionName);
7726
Robert Greenwalt646120a2014-05-23 11:54:03 -07007727 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007728
7729 final long identity = Binder.clearCallingIdentity();
7730 try {
Jack Yu285100e2022-12-02 22:48:35 -08007731 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007732 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7733 Phone phone = PhoneFactory.getPhone(phoneId);
7734 if (phone != null) {
7735 boolean retVal = phone.isUserDataEnabled();
7736 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7737 return retVal;
7738 } else {
7739 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7740 return false;
7741 }
7742 } finally {
7743 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007744 }
7745 }
7746
7747 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007748 * Checks if the device is capable of mobile data by considering whether whether the
7749 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7750 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007751 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007752 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007753 */
7754 @Override
7755 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007756 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007757 try {
7758 try {
7759 mApp.enforceCallingOrSelfPermission(
7760 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007761 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007762 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007763 try {
7764 mApp.enforceCallingOrSelfPermission(
7765 android.Manifest.permission.READ_PHONE_STATE,
7766 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007767 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007768 mApp.enforceCallingOrSelfPermission(
7769 permission.READ_BASIC_PHONE_STATE, functionName);
7770 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007771 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007772 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007773 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007774 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007775
7776 final long identity = Binder.clearCallingIdentity();
7777 try {
Jack Yu285100e2022-12-02 22:48:35 -08007778 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007779 Phone phone = PhoneFactory.getPhone(phoneId);
7780 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007781 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007782 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007783 return retVal;
7784 } else {
7785 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7786 return false;
7787 }
7788 } finally {
7789 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007790 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007791 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007792
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007793 /**
7794 * Check if data is enabled for a specific reason
7795 * @param subId Subscription index
7796 * @param reason the reason the data enable change is taking place
7797 * @return {@code true} if the overall data is enabled; {@code false} if not.
7798 */
7799 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007800 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007801 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007802 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007803 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007804 try {
7805 mApp.enforceCallingOrSelfPermission(
7806 android.Manifest.permission.ACCESS_NETWORK_STATE,
7807 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007808 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007809 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7810 functionName);
7811 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007812 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007813 try {
7814 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007815 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007816 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007818 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007819 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007820 }
7821
7822
7823 final long identity = Binder.clearCallingIdentity();
7824 try {
Jack Yu285100e2022-12-02 22:48:35 -08007825 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007826 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007827 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007828 + " reason=" + reason);
7829 }
7830 Phone phone = PhoneFactory.getPhone(phoneId);
7831 if (phone != null) {
7832 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007833 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007834 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007835 return retVal;
7836 } else {
7837 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007838 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007839 + subId + " retVal=false");
7840 }
7841 return false;
7842 }
7843 } finally {
7844 Binder.restoreCallingIdentity(identity);
7845 }
7846 }
7847
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007848 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007849 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007850 // No permission needed; this only lets the caller inspect their own status.
7851 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007852 }
Junda Liu29340342014-07-10 15:23:27 -07007853
7854 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007855 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007856 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007857 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7858 }
7859
7860 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7861 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007862 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007863 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007864 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7865 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007866 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7867 if (cpt == null) {
7868 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007869 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7870 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007871 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007872 }
7873
7874 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007875 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007876 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007877 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007878 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007879 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007880 Phone phone = getPhone(subId);
7881 if (phone == null) {
7882 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7883 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7884 }
7885 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7886 if (cpt == null) {
7887 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007888 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7889 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007890 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007891 }
7892
7893 @Override
7894 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007895 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007896 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7897 }
7898
7899 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007900 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007901 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007902 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007903 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007904 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7905 Phone phone = PhoneFactory.getPhone(phoneId);
7906 if (phone == null) {
7907 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007908 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007909 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7910 if (cpt == null) {
7911 continue;
7912 }
7913 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007914 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7915 break;
7916 }
7917 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007918 return result;
Junda Liu29340342014-07-10 15:23:27 -07007919 }
Derek Tan89e89d42014-07-08 17:00:10 -07007920
7921 @Override
Junda Liue64de782015-04-16 17:19:16 -07007922 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007923 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007924 Phone phone = PhoneFactory.getPhone(phoneId);
7925 if (phone == null) {
7926 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007927 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007928 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7929 if (cpt == null) {
7930 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007931 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007932 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007933 }
7934
Amith Yamasani6e118872016-02-19 12:53:51 -08007935 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007936 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007937 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007938 Phone phone = PhoneFactory.getPhone(phoneId);
7939 if (phone == null) {
7940 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007941 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007942 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7943 if (cpt == null) {
7944 return Collections.emptyList();
7945 }
7946 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007947 }
7948
chen xuf7e9fe82019-05-09 19:31:02 -07007949 @Override
7950 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007951 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007952 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007953 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007954 try {
7955 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7956 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7957 }
7958 } finally {
7959 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007960 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007961 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007962 }
7963
Rambo Wang6812ffb2022-03-15 16:54:17 -07007964 @Override
7965 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7966 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7967
7968 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7969 if (phone == null) {
7970 return null;
7971 }
7972 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7973 if (cpt == null) {
7974 return null;
7975 }
7976 return cpt.getCarrierServicePackageName();
7977 }
7978
Wink Savilleb564aae2014-10-23 10:18:09 -07007979 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007980 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007981 UiccPort port = phone == null ? null : phone.getUiccPort();
7982 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007983 return null;
7984 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007985 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007986 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007987 return null;
7988 }
7989 return iccId;
7990 }
7991
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007992 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007993 public void setCallComposerStatus(int subId, int status) {
7994 enforceModifyPermission();
7995
7996 final long identity = Binder.clearCallingIdentity();
7997 try {
7998 Phone phone = getPhone(subId);
7999 if (phone != null) {
8000 Phone defaultPhone = phone.getImsPhone();
8001 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8002 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8003 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08008004 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
8005 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08008006 }
8007 }
Shuo Qian284ae752020-12-22 19:10:14 -08008008 } catch (ImsException e) {
8009 throw new ServiceSpecificException(e.getCode());
8010 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08008011 Binder.restoreCallingIdentity(identity);
8012 }
8013 }
8014
8015 @Override
8016 public int getCallComposerStatus(int subId) {
8017 enforceReadPrivilegedPermission("getCallComposerStatus");
8018
8019 final long identity = Binder.clearCallingIdentity();
8020 try {
8021 Phone phone = getPhone(subId);
8022 if (phone != null) {
8023 Phone defaultPhone = phone.getImsPhone();
8024 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8025 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8026 return imsPhone.getCallComposerStatus();
8027 }
8028 }
8029 } finally {
8030 Binder.restoreCallingIdentity(identity);
8031 }
8032 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
8033 }
8034
8035 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08008036 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
8037 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008038 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008039 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07008040
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008041 final long identity = Binder.clearCallingIdentity();
8042 try {
8043 final String iccId = getIccId(subId);
8044 final Phone phone = getPhone(subId);
8045 if (phone == null) {
8046 return false;
8047 }
8048 final String subscriberId = phone.getSubscriberId();
8049
8050 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008051 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008052 + subscriberId + " to " + number);
8053 }
8054
8055 if (TextUtils.isEmpty(iccId)) {
8056 return false;
8057 }
8058
8059 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
8060
8061 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
8062 if (alphaTag == null) {
8063 editor.remove(alphaTagPrefKey);
8064 } else {
8065 editor.putString(alphaTagPrefKey, alphaTag);
8066 }
8067
8068 // Record both the line number and IMSI for this ICCID, since we need to
8069 // track all merged IMSIs based on line number
8070 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
8071 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
8072 if (number == null) {
8073 editor.remove(numberPrefKey);
8074 editor.remove(subscriberPrefKey);
8075 } else {
8076 editor.putString(numberPrefKey, number);
8077 editor.putString(subscriberPrefKey, subscriberId);
8078 }
8079
8080 editor.commit();
8081 return true;
8082 } finally {
8083 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07008084 }
Derek Tan7226c842014-07-02 17:42:23 -07008085 }
8086
8087 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008088 public String getLine1NumberForDisplay(int subId, String callingPackage,
8089 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07008090 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08008091 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008092 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08008093 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07008094 return null;
8095 }
Derek Tan97ebb422014-09-05 16:55:38 -07008096
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008097 final long identity = Binder.clearCallingIdentity();
8098 try {
8099 String iccId = getIccId(subId);
8100 if (iccId != null) {
8101 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
8102 if (DBG_MERGE) {
8103 log("getLine1NumberForDisplay returning "
8104 + mTelephonySharedPreferences.getString(numberPrefKey, null));
8105 }
8106 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08008107 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008108 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
8109 return null;
8110 } finally {
8111 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07008112 }
Derek Tan7226c842014-07-02 17:42:23 -07008113 }
8114
8115 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008116 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
8117 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008118 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008119 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07008120 return null;
8121 }
Derek Tan97ebb422014-09-05 16:55:38 -07008122
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008123 final long identity = Binder.clearCallingIdentity();
8124 try {
8125 String iccId = getIccId(subId);
8126 if (iccId != null) {
8127 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
8128 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
8129 }
8130 return null;
8131 } finally {
8132 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07008133 }
Derek Tan7226c842014-07-02 17:42:23 -07008134 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008135
8136 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008137 public String[] getMergedSubscriberIds(int subId, String callingPackage,
8138 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008139 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
8140 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08008141 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08008142 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008143 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008144 return null;
8145 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008146
Jordan Liub49b04b2019-05-06 14:45:15 -07008147 // Clear calling identity, when calling TelephonyManager, because callerUid must be
8148 // the process, where TelephonyManager was instantiated.
8149 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008150 final long identity = Binder.clearCallingIdentity();
8151 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008152 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008153 final TelephonyManager tele = TelephonyManager.from(context);
8154 final SubscriptionManager sub = SubscriptionManager.from(context);
8155
8156 // Figure out what subscribers are currently active
8157 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008158
Jordan Liub49b04b2019-05-06 14:45:15 -07008159 // Only consider subs which match the current subId
8160 // This logic can be simplified. See b/131189269 for progress.
8161 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008162 activeSubscriberIds.add(tele.getSubscriberId(subId));
8163 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008164
8165 // First pass, find a number override for an active subscriber
8166 String mergeNumber = null;
8167 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
8168 for (String key : prefs.keySet()) {
8169 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
8170 final String subscriberId = (String) prefs.get(key);
8171 if (activeSubscriberIds.contains(subscriberId)) {
8172 final String iccId = key.substring(
8173 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
8174 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
8175 mergeNumber = (String) prefs.get(numberKey);
8176 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008177 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008178 + " for active subscriber " + subscriberId);
8179 }
8180 if (!TextUtils.isEmpty(mergeNumber)) {
8181 break;
8182 }
8183 }
8184 }
8185 }
8186
8187 // Shortcut when no active merged subscribers
8188 if (TextUtils.isEmpty(mergeNumber)) {
8189 return null;
8190 }
8191
8192 // Second pass, find all subscribers under that line override
8193 final ArraySet<String> result = new ArraySet<>();
8194 for (String key : prefs.keySet()) {
8195 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
8196 final String number = (String) prefs.get(key);
8197 if (mergeNumber.equals(number)) {
8198 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
8199 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
8200 final String subscriberId = (String) prefs.get(subscriberKey);
8201 if (!TextUtils.isEmpty(subscriberId)) {
8202 result.add(subscriberId);
8203 }
8204 }
8205 }
8206 }
8207
8208 final String[] resultArray = result.toArray(new String[result.size()]);
8209 Arrays.sort(resultArray);
8210 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008211 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008212 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
8213 }
8214 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008215 } finally {
8216 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08008217 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008218 }
8219
8220 @Override
zoey chen38003472019-12-13 17:16:31 +08008221 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
8222 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07008223
8224 final long identity = Binder.clearCallingIdentity();
8225 try {
8226 final TelephonyManager telephonyManager = mApp.getSystemService(
8227 TelephonyManager.class);
8228 String subscriberId = telephonyManager.getSubscriberId(subId);
8229 if (subscriberId == null) {
8230 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008231 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008232 + subId);
8233 }
8234 return null;
8235 }
8236
Jack Yu285100e2022-12-02 22:48:35 -08008237 ParcelUuid groupUuid;
8238 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008239 final SubscriptionInfo info = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08008240 .getSubscriptionInfo(subId);
8241 groupUuid = info.getGroupUuid();
8242 } else {
8243 final SubscriptionInfo info = mSubscriptionController
8244 .getSubscriptionInfo(subId);
8245 groupUuid = info.getGroupUuid();
8246 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07008247 // If it doesn't belong to any group, return just subscriberId of itself.
8248 if (groupUuid == null) {
8249 return new String[]{subscriberId};
8250 }
8251
8252 // Get all subscriberIds from the group.
8253 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08008254 List<SubscriptionInfo> groupInfos;
8255 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008256 groupInfos = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08008257 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8258 mApp.getAttributionTag());
8259 } else {
8260 groupInfos = mSubscriptionController
8261 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8262 mApp.getAttributionTag());
8263 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07008264 for (SubscriptionInfo subInfo : groupInfos) {
8265 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8266 if (subscriberId != null) {
8267 mergedSubscriberIds.add(subscriberId);
8268 }
8269 }
8270
8271 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8272 } finally {
8273 Binder.restoreCallingIdentity(identity);
8274
8275 }
8276 }
8277
8278 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008279 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008280 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008281 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008282
8283 final long identity = Binder.clearCallingIdentity();
8284 try {
8285 final Phone phone = getPhone(subId);
8286 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8287 } finally {
8288 Binder.restoreCallingIdentity(identity);
8289 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008290 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008291
8292 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008293 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008294 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8295 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008296 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8297 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008298
8299 final long identity = Binder.clearCallingIdentity();
8300 try {
8301 final Phone phone = getPhone(subId);
8302 if (phone == null) {
8303 return false;
8304 }
8305 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8306 cdmaNonRoamingList);
8307 } finally {
8308 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008309 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008310 }
8311
8312 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00008313 @Deprecated
8314 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
8315 enforceModifyPermission();
8316
8317 int returnValue = 0;
8318 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07008319 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00008320 if(result.exception == null) {
8321 if (result.result != null) {
8322 byte[] responseData = (byte[])(result.result);
8323 if(responseData.length > oemResp.length) {
8324 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
8325 responseData.length + "bytes. Buffer Size is " +
8326 oemResp.length + "bytes.");
8327 }
8328 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
8329 returnValue = responseData.length;
8330 }
8331 } else {
8332 CommandException ex = (CommandException) result.exception;
8333 returnValue = ex.getCommandError().ordinal();
8334 if(returnValue > 0) returnValue *= -1;
8335 }
8336 } catch (RuntimeException e) {
8337 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
8338 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
8339 if(returnValue > 0) returnValue *= -1;
8340 }
8341
8342 return returnValue;
8343 }
8344
8345 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008346 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008347 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07008348 try {
8349 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008350 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008351 mApp, phone.getSubId(), "getRadioAccessFamily");
8352 } catch (SecurityException e) {
8353 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8354 throw e;
8355 }
chen xub97461a2018-10-26 14:17:57 -07008356 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008357 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07008358 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08008359 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008360 final long identity = Binder.clearCallingIdentity();
8361 try {
chen xub97461a2018-10-26 14:17:57 -07008362 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008363 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07008364 mApp, phone.getSubId(), "getRadioAccessFamily");
8365 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008366 } finally {
8367 Binder.restoreCallingIdentity(identity);
8368 }
chen xub97461a2018-10-26 14:17:57 -07008369 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008370 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008371
8372 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008373 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008374 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008375 try {
8376 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8377 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008378 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008379 }
8380 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008381 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008382 }
8383 RoleManager rm = mApp.getSystemService(RoleManager.class);
8384 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8385 if (!dialerRoleHolders.contains(callingPackage)) {
8386 throw new SecurityException("App must be the dialer role holder to"
8387 + " upload a call composer pic");
8388 }
8389
8390 Executors.newSingleThreadExecutor().execute(() -> {
8391 ByteArrayOutputStream output = new ByteArrayOutputStream(
8392 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8393 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8394 boolean readUntilEnd = false;
8395 int totalBytesRead = 0;
8396 byte[] buffer = new byte[16 * 1024];
8397 while (true) {
8398 int numRead;
8399 try {
8400 numRead = input.read(buffer);
8401 } catch (IOException e) {
8402 try {
8403 fd.checkError();
8404 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8405 null);
8406 } catch (IOException e1) {
8407 // This means that the other side closed explicitly with an error. If this
8408 // happens, log and ignore.
8409 loge("Remote end of call composer picture pipe closed: " + e1);
8410 }
8411 break;
8412 }
8413 if (numRead == -1) {
8414 readUntilEnd = true;
8415 break;
8416 }
8417 totalBytesRead += numRead;
8418 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8419 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8420 try {
8421 input.close();
8422 } catch (IOException e) {
8423 // ignore
8424 }
8425 break;
8426 }
8427 output.write(buffer, 0, numRead);
8428 }
8429 // Generally, the remote end will close the file descriptors. The only case where we
8430 // close is above, where the picture size is too big.
8431
8432 try {
8433 fd.checkError();
8434 } catch (IOException e) {
8435 loge("Remote end for call composer closed with an error: " + e);
8436 return;
8437 }
8438
Hall Liuaa4211e2021-01-20 15:43:39 -08008439 if (!readUntilEnd) {
8440 loge("Did not finish reading entire image; aborting");
8441 return;
8442 }
Hall Liu82694d52020-12-11 18:22:04 -08008443
Hall Liuaa4211e2021-01-20 15:43:39 -08008444 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8445 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8446 new CallComposerPictureTransfer.Factory() {},
8447 imageData,
8448 (result) -> {
8449 if (result.first != null) {
8450 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8451 Bundle outputResult = new Bundle();
8452 outputResult.putParcelable(
8453 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8454 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8455 outputResult);
8456 } else {
8457 callback.send(result.second, null);
8458 }
8459 }
8460 );
Hall Liu82694d52020-12-11 18:22:04 -08008461 });
8462 }
8463
8464 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008465 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008466 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008467 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008468
8469 final long identity = Binder.clearCallingIdentity();
8470 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008471 ImsManager.getInstance(defaultPhone.getContext(),
8472 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008473 } finally {
8474 Binder.restoreCallingIdentity(identity);
8475 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008476 }
8477
8478 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008479 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008480 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008481 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8482 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008483 return false;
8484 }
Svet Ganovb320e182015-04-16 12:30:10 -07008485
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008486 final long identity = Binder.clearCallingIdentity();
8487 try {
8488 // Check the user preference and the system-level IMS setting. Even if the user has
8489 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8490 // In the long run, we may instead need to check if there exists a connection service
8491 // which can support video calling.
8492 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008493 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008494 return imsManager.isVtEnabledByPlatform()
8495 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8496 && imsManager.isVtEnabledByUser();
8497 } finally {
8498 Binder.restoreCallingIdentity(identity);
8499 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008500 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008501
Andrew Leea1239f22015-03-02 17:44:07 -08008502 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008503 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8504 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008505 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008506 mApp, subId, callingPackage, callingFeatureId,
8507 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008508 return false;
8509 }
8510
8511 final long identity = Binder.clearCallingIdentity();
8512 try {
8513 CarrierConfigManager configManager =
8514 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008515 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008516 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8517 } finally {
8518 Binder.restoreCallingIdentity(identity);
8519 }
Andrew Leea1239f22015-03-02 17:44:07 -08008520 }
8521
8522 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008523 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008524 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008525 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008526 return false;
8527 }
8528
8529 final long identity = Binder.clearCallingIdentity();
8530 try {
8531 CarrierConfigManager configManager =
8532 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008533 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008534 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8535 } finally {
8536 Binder.restoreCallingIdentity(identity);
8537 }
Andrew Leea1239f22015-03-02 17:44:07 -08008538 }
8539
Andrew Lee9431b832015-03-09 18:46:45 -07008540 @Override
8541 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008542 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008543 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008544 }
8545
8546 @Override
8547 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008548 final long identity = Binder.clearCallingIdentity();
8549 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008550 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008551 } finally {
8552 Binder.restoreCallingIdentity(identity);
8553 }
Andrew Lee9431b832015-03-09 18:46:45 -07008554 }
8555
Hall Liuf6668912018-10-31 17:05:23 -07008556 /**
8557 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8558 * support for the feature and device firmware support.
8559 *
8560 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8561 */
8562 @Override
8563 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008564 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008565 final Phone phone = getPhone(subscriptionId);
8566 if (phone == null) {
8567 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8568 return false;
8569 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008570 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008571 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008572 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
8573 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008574 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008575 return isCarrierSupported && isDeviceSupported;
8576 } finally {
8577 Binder.restoreCallingIdentity(identity);
8578 }
Hall Liu98187582018-01-22 19:15:32 -08008579 }
8580
Hall Liuf6668912018-10-31 17:05:23 -07008581 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008582 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8583 * RTT setting, will return true if the device and carrier both support RTT.
8584 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008585 */
8586 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008587 final long identity = Binder.clearCallingIdentity();
8588 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00008589 boolean isRttSupported = isRttSupported(subscriptionId);
8590 boolean isUserRttSettingOn = Settings.Secure.getInt(
8591 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8592 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8593 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8594 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008595 } finally {
8596 Binder.restoreCallingIdentity(identity);
8597 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008598 }
8599
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008600 @Deprecated
8601 @Override
8602 public String getDeviceId(String callingPackage) {
8603 return getDeviceIdWithFeature(callingPackage, null);
8604 }
8605
Sanket Padawe7310cc72015-01-14 09:53:20 -08008606 /**
8607 * Returns the unique device ID of phone, for example, the IMEI for
8608 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8609 *
8610 * <p>Requires Permission:
8611 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8612 */
8613 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008614 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008615 try {
8616 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8617 } catch (SecurityException se) {
8618 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8619 throw new SecurityException("Package " + callingPackage + " does not belong to "
8620 + Binder.getCallingUid());
8621 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008622 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008623 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008624 return null;
8625 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008626 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008627 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008628 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008629 return null;
8630 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008631
8632 final long identity = Binder.clearCallingIdentity();
8633 try {
8634 return phone.getDeviceId();
8635 } finally {
8636 Binder.restoreCallingIdentity(identity);
8637 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008638 }
8639
Ping Sunc67b7c22016-03-02 19:16:45 +08008640 /**
8641 * {@hide}
8642 * Returns the IMS Registration Status on a particular subid
8643 *
8644 * @param subId
8645 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008646 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008647 Phone phone = getPhone(subId);
8648 if (phone != null) {
8649 return phone.isImsRegistered();
8650 } else {
8651 return false;
8652 }
8653 }
8654
Santos Cordon7a1885b2015-02-03 11:15:19 -08008655 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008656 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008657 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008658 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008659 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008660 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8661 }
8662 final long identity = Binder.clearCallingIdentity();
8663 try {
8664 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8665 } finally {
8666 Binder.restoreCallingIdentity(identity);
8667 }
8668 }
8669
8670 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008671 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008672 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008673 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008674 mApp,
8675 subscriptionId,
8676 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8677 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07008678 final long identity = Binder.clearCallingIdentity();
8679 try {
8680 Phone phone = getPhone(subscriptionId);
8681 if (phone == null) {
8682 return null;
8683 }
8684 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8685 } finally {
8686 Binder.restoreCallingIdentity(identity);
8687 }
8688 }
8689
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008690 /**
8691 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008692 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008693 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008694 final long identity = Binder.clearCallingIdentity();
8695 try {
8696 Phone phone = getPhone(subId);
8697 if (phone != null) {
8698 return phone.isWifiCallingEnabled();
8699 } else {
8700 return false;
8701 }
8702 } finally {
8703 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008704 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008705 }
8706
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008707 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008708 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008709 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008710 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008711 final long identity = Binder.clearCallingIdentity();
8712 try {
8713 Phone phone = getPhone(subId);
8714 if (phone != null) {
8715 return phone.isVideoEnabled();
8716 } else {
8717 return false;
8718 }
8719 } finally {
8720 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008721 }
8722 }
8723
8724 /**
8725 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8726 * defined in {@link ImsRegistrationImplBase}.
8727 */
8728 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008729 final long identity = Binder.clearCallingIdentity();
8730 try {
8731 Phone phone = getPhone(subId);
8732 if (phone != null) {
8733 return phone.getImsRegistrationTech();
8734 } else {
8735 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8736 }
8737 } finally {
8738 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008739 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008740 }
8741
Stuart Scott8eef64f2015-04-08 15:13:54 -07008742 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008743 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008744 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07008745 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8746 return;
8747 }
Kai Shif70f46f2021-03-03 13:59:46 -08008748 Phone defaultPhone = getDefaultPhone();
8749 if (defaultPhone != null) {
8750 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8751 mApp, getDefaultPhone().getSubId(), "factoryReset");
8752 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008753 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008754
Svet Ganovcc087f82015-05-12 20:35:54 -07008755 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008756 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8757 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008758 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008759 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008760 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008761 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008762 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008763 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08008764 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008765 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008766 // There has been issues when Sms raw table somehow stores orphan
8767 // fragments. They lead to garbled message when new fragments come
8768 // in and combined with those stale ones. In case this happens again,
8769 // user can reset all network settings which will clean up this table.
8770 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008771 // Clean up IMS settings as well here.
8772 int slotId = getSlotIndex(subId);
8773 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8774 ImsManager.getInstance(mApp, slotId).factoryReset();
8775 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008776
Kai Shif70f46f2021-03-03 13:59:46 -08008777 if (defaultPhone == null) {
8778 return;
8779 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008780 // Erase modem config if erase modem on network setting is enabled.
8781 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8782 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8783 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008784 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008785 }
Kai Shif70f46f2021-03-03 13:59:46 -08008786
8787 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008788 } finally {
8789 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008790 }
8791 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008792
SongFerngWangfd89b102021-05-27 22:44:54 +08008793 @VisibleForTesting
8794 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8795 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8796 return;
8797 }
8798 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8799 RILConstants.PREFERRED_NETWORK_MODE);
8800 SubscriptionManager.setSubscriptionProperty(subId,
8801 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8802 "user=" + defaultNetworkType);
8803 phone.loadAllowedNetworksFromSubscriptionDatabase();
8804 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8805 defaultNetworkType, null);
8806 }
8807
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008808 private void cleanUpSmsRawTable(Context context) {
8809 ContentResolver resolver = context.getContentResolver();
8810 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8811 resolver.delete(uri, null, null);
8812 }
8813
Narayan Kamath1c496c22015-04-16 14:40:19 +01008814 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008815 public String getSimLocaleForSubscriber(int subId) {
8816 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
8817 final Phone phone = getPhone(subId);
8818 if (phone == null) {
8819 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008820 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008821 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008822 final long identity = Binder.clearCallingIdentity();
8823 try {
Jack Yu285100e2022-12-02 22:48:35 -08008824 SubscriptionInfo info;
8825 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008826 info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
Jack Yu285100e2022-12-02 22:48:35 -08008827 phone.getContext().getOpPackageName(),
8828 phone.getContext().getAttributionTag());
8829 if (info == null) {
8830 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8831 return null;
8832 }
8833 } else {
8834 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
8835 phone.getContext().getOpPackageName(),
8836 phone.getContext().getAttributionTag());
8837 if (info == null) {
8838 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8839 return null;
8840 }
chen xu6291c472019-02-04 12:55:53 -08008841 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008842 // Try and fetch the locale from the carrier properties or from the SIM language
8843 // preferences (EF-PL and EF-LI)...
8844 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008845 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008846 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8847 if (localeFromDefaultSim != null) {
8848 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8849 if (DBG) log("Using locale from subId: " + subId + " locale: "
8850 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008851 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008852 } else {
8853 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008854 }
8855 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008856
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008857 // The SIM language preferences only store a language (e.g. fr = French), not an
8858 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8859 // the SIM and carrier preferences does not include a country we add the country
8860 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008861 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008862 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008863 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008864 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008865 }
8866
8867 if (DBG) log("No locale found - returning null");
8868 return null;
8869 } finally {
8870 Binder.restoreCallingIdentity(identity);
8871 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008872 }
8873
tom hsu0b59d292022-09-29 23:49:21 +08008874 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008875 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008876 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008877 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008878 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008879 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8880 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008881 Locale.forLanguageTag(localeTag).getCountry())) {
8882 return localeTag;
8883 }
8884 }
8885 return inputLocale.toLanguageTag();
8886 }
8887
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008888 /**
8889 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8890 */
8891 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08008892 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008893 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Jack Yu285100e2022-12-02 22:48:35 -08008894 mApp.getOpPackageName(), mApp.getAttributionTag());
8895 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008896 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08008897 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008898 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008899
Gary Jian3aa9a762022-01-24 16:41:19 +08008900 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8901 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008902
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008903 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008904 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8905 * representing the state of the modem.
8906 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008907 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8908 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008909 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008910 */
8911 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008912 public void requestModemActivityInfo(ResultReceiver result) {
8913 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008914 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008915
8916 final long identity = Binder.clearCallingIdentity();
8917 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008918 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008919 } finally {
8920 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008921 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008922 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008923
Gary Jian76280a42022-12-07 16:18:33 +08008924 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008925 // less than total activity duration.
8926 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8927 if (info == null) {
8928 return false;
8929 }
8930 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008931 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008932 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8933
Hall Liu49656c02020-10-09 19:00:11 -07008934 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8935
Siddharth Rayb8114062018-06-17 15:02:38 -07008936 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008937 && (info.getSleepTimeMillis() <= activityDurationMs)
8938 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008939 }
8940
Gary Jian3aa9a762022-01-24 16:41:19 +08008941 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8942 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8943 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8944 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8945
8946 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8947 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8948 }
8949
8950 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8951 mLastModemActivityInfo.setReceiveTimeMillis(
8952 rat,
8953 freq,
8954 info.getReceiveTimeMillis(rat, freq)
8955 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8956 }
8957
8958 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8959 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8960 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8961 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8962
8963 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8964 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8965 }
8966 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8967 mLastModemActivityInfo.setReceiveTimeMillis(
8968 rat,
8969 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8970 }
8971
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008972 /**
8973 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8974 * @param info recent ModemActivityInfo
8975 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008976 private void mergeModemActivityInfo(ModemActivityInfo info) {
8977 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008978 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008979 boolean matched;
8980 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8981 matched = false;
8982 int rat = info.getSpecificInfoRat(i);
8983 int freq = info.getSpecificInfoFrequencyRange(i);
8984 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8985 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8986 //if it already exists
8987 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8988 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8989 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8990 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8991 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8992 updateLastModemActivityInfo(info, rat, freq);
8993 matched = true;
8994 }
8995 } else {
8996 updateLastModemActivityInfo(info, rat);
8997 matched = true;
8998 }
8999 }
9000 }
9001
9002 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08009003 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08009004 new ActivityStatsTechSpecificInfo(
9005 rat,
9006 freq,
9007 info.getTransmitTimeMillis(rat, freq),
9008 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08009009 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08009010 }
9011 }
9012 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
9013 mLastModemActivitySpecificInfo =
9014 new ActivityStatsTechSpecificInfo[merged.size()];
9015 merged.toArray(mLastModemActivitySpecificInfo);
9016
9017 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
9018 mLastModemActivityInfo.setSleepTimeMillis(
9019 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009020 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08009021 mLastModemActivityInfo.setIdleTimeMillis(
9022 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009023 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08009024
9025 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009026 new ModemActivityInfo(
9027 mLastModemActivityInfo.getTimestampMillis(),
9028 mLastModemActivityInfo.getSleepTimeMillis(),
9029 mLastModemActivityInfo.getIdleTimeMillis(),
9030 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08009031 }
9032
9033 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
9034 ActivityStatsTechSpecificInfo[] info) {
9035 int infoSize = info.length;
9036 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
9037 for (int i = 0; i < infoSize; i++) {
9038 ret[i] = new ActivityStatsTechSpecificInfo(
9039 info[i].getRat(), info[i].getFrequencyRange(),
9040 info[i].getTransmitTimeMillis(),
9041 (int) info[i].getReceiveTimeMillis());
9042 }
9043 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08009044 }
9045
Jack Yu85bd38a2015-11-09 11:34:32 -08009046 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08009047 * Returns the service state information on specified subscription.
9048 */
9049 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08009050 public ServiceState getServiceStateForSubscriber(int subId,
9051 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
9052 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009053 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009054 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08009055 return null;
9056 }
9057
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08009058 boolean hasFinePermission = false;
9059 boolean hasCoarsePermission = false;
9060 if (!renounceFineLocationAccess) {
9061 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
9062 LocationAccessPolicy.checkLocationPermission(mApp,
9063 new LocationAccessPolicy.LocationPermissionQuery.Builder()
9064 .setCallingPackage(callingPackage)
9065 .setCallingFeatureId(callingFeatureId)
9066 .setCallingPid(Binder.getCallingPid())
9067 .setCallingUid(Binder.getCallingUid())
9068 .setMethod("getServiceStateForSubscriber")
9069 .setLogAsInfo(true)
9070 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
9071 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
9072 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
9073 .build());
9074 hasFinePermission =
9075 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
9076 }
Hall Liuf19c44f2018-11-27 14:38:17 -08009077
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08009078 if (!renounceCoarseLocationAccess) {
9079 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
9080 LocationAccessPolicy.checkLocationPermission(mApp,
9081 new LocationAccessPolicy.LocationPermissionQuery.Builder()
9082 .setCallingPackage(callingPackage)
9083 .setCallingFeatureId(callingFeatureId)
9084 .setCallingPid(Binder.getCallingPid())
9085 .setCallingUid(Binder.getCallingUid())
9086 .setMethod("getServiceStateForSubscriber")
9087 .setLogAsInfo(true)
9088 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
9089 .setMinSdkVersionForFine(Integer.MAX_VALUE)
9090 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
9091 .build());
9092 hasCoarsePermission =
9093 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
9094 }
Hall Liuf19c44f2018-11-27 14:38:17 -08009095
Jack Yu479f40e2020-10-27 21:29:25 -07009096 final Phone phone = getPhone(subId);
9097 if (phone == null) {
9098 return null;
9099 }
9100
Jordan Liu0f2bc442020-11-18 16:47:37 -08009101 final long identity = Binder.clearCallingIdentity();
9102
Jack Yu479f40e2020-10-27 21:29:25 -07009103 boolean isCallingPackageDataService = phone.getDataServicePackages()
9104 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009105 try {
Jordan Liuc437b192020-08-17 10:59:12 -07009106 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08009107 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08009108 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08009109 .getSubscriptionInfoInternal(subId);
9110 if (subInfo == null || !subInfo.isActive()) {
9111 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
9112 + "subId=" + subId);
9113 return null;
9114 }
9115 } else {
9116 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
9117 callingFeatureId)) {
9118 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
9119 + "subId=" + subId);
9120 return null;
9121 }
Jordan Liuc437b192020-08-17 10:59:12 -07009122 }
9123
Hall Liuf19c44f2018-11-27 14:38:17 -08009124 ServiceState ss = phone.getServiceState();
9125
9126 // Scrub out the location info in ServiceState depending on what level of access
9127 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07009128 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08009129 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
9130 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009131 } finally {
9132 Binder.restoreCallingIdentity(identity);
9133 }
Jack Yu85bd38a2015-11-09 11:34:32 -08009134 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009135
9136 /**
9137 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
9138 *
9139 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
9140 * voicemail ringtone.
9141 * @return The URI for the ringtone to play when receiving a voicemail from a specific
9142 * PhoneAccount.
9143 */
9144 @Override
9145 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009146 final long identity = Binder.clearCallingIdentity();
9147 try {
9148 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9149 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009150 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009151 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009152
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009153 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
9154 } finally {
9155 Binder.restoreCallingIdentity(identity);
9156 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009157 }
9158
9159 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009160 * Sets the per-account voicemail ringtone.
9161 *
9162 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9163 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9164 *
9165 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9166 * voicemail ringtone.
9167 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
9168 * PhoneAccount.
9169 */
9170 @Override
9171 public void setVoicemailRingtoneUri(String callingPackage,
9172 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009173 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009174 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009175 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9176 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009177 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9178 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9179 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009180 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009181
9182 final long identity = Binder.clearCallingIdentity();
9183 try {
9184 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9185 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009186 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009187 }
9188 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
9189 } finally {
9190 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009191 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009192 }
9193
9194 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08009195 * Returns whether vibration is set for voicemail notification in Phone settings.
9196 *
9197 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
9198 * voicemail vibration setting.
9199 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
9200 */
9201 @Override
9202 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009203 final long identity = Binder.clearCallingIdentity();
9204 try {
9205 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9206 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009207 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009208 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009209
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009210 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
9211 } finally {
9212 Binder.restoreCallingIdentity(identity);
9213 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009214 }
9215
Youhan Wange64578a2016-05-02 15:32:42 -07009216 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009217 * Sets the per-account voicemail vibration.
9218 *
9219 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9220 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9221 *
9222 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9223 * voicemail vibration setting.
9224 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9225 * specific PhoneAccount.
9226 */
9227 @Override
9228 public void setVoicemailVibrationEnabled(String callingPackage,
9229 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009230 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009231 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009232 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9233 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9235 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9236 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009237 }
9238
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009239 final long identity = Binder.clearCallingIdentity();
9240 try {
9241 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9242 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009243 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009244 }
9245 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9246 } finally {
9247 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009248 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009249 }
9250
9251 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009252 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9253 *
9254 * @throws SecurityException if the caller does not have the required permission
9255 */
arunvoddud7401012022-12-15 16:08:12 +00009256 @VisibleForTesting
9257 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009258 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009259 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009260 }
9261
9262 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009263 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9264 * permission.
9265 *
9266 * @throws SecurityException if the caller does not have the required permission
9267 */
9268 private void enforceSendSmsPermission() {
9269 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9270 }
9271
9272 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009273 * Make sure either called from same process as self (phone) or IPC caller has interact across
9274 * users permission.
9275 *
9276 * @throws SecurityException if the caller does not have the required permission
9277 */
9278 private void enforceInteractAcrossUsersPermission(String message) {
9279 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9280 }
9281
9282 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009283 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009284 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009285 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009286 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009287 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009288 final long identity = Binder.clearCallingIdentity();
9289 try {
9290 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009291 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009292 if (componentName == null) {
9293 throw new SecurityException(
9294 "Caller not current active visual voicemail package[null]");
9295 }
9296 String vvmPackage = componentName.getPackageName();
9297 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009298 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009299 }
9300 } finally {
9301 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009302 }
9303 }
9304
9305 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009306 * Return the application ID for the app type.
9307 *
9308 * @param subId the subscription ID that this request applies to.
9309 * @param appType the uicc app type.
9310 * @return Application ID for specificied app type, or null if no uicc.
9311 */
9312 @Override
9313 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009314 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07009315 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009316
9317 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009318 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009319 if (phone == null) {
9320 return null;
9321 }
9322 String aid = null;
9323 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009324 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009325 .getApplicationByType(appType).getAid();
9326 } catch (Exception e) {
9327 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9328 }
9329 return aid;
9330 } finally {
9331 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009332 }
Youhan Wange64578a2016-05-02 15:32:42 -07009333 }
9334
Youhan Wang4001d252016-05-11 10:29:41 -07009335 /**
9336 * Return the Electronic Serial Number.
9337 *
9338 * @param subId the subscription ID that this request applies to.
9339 * @return ESN or null if error.
9340 */
9341 @Override
9342 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009343 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009344 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009345
9346 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009347 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009348 if (phone == null) {
9349 return null;
9350 }
9351 String esn = null;
9352 try {
9353 esn = phone.getEsn();
9354 } catch (Exception e) {
9355 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9356 }
9357 return esn;
9358 } finally {
9359 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009360 }
Youhan Wang4001d252016-05-11 10:29:41 -07009361 }
9362
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009363 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009364 * Return the Preferred Roaming List Version.
9365 *
9366 * @param subId the subscription ID that this request applies to.
9367 * @return PRLVersion or null if error.
9368 */
9369 @Override
9370 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009371 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07009372 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009373
9374 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009375 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009376 if (phone == null) {
9377 return null;
9378 }
9379 String cdmaPrlVersion = null;
9380 try {
9381 cdmaPrlVersion = phone.getCdmaPrlVersion();
9382 } catch (Exception e) {
9383 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9384 }
9385 return cdmaPrlVersion;
9386 } finally {
9387 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009388 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009389 }
9390
9391 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009392 * Get snapshot of Telephony histograms
9393 * @return List of Telephony histograms
9394 * @hide
9395 */
9396 @Override
9397 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9399 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009400
9401 final long identity = Binder.clearCallingIdentity();
9402 try {
9403 return RIL.getTelephonyRILTimingHistograms();
9404 } finally {
9405 Binder.restoreCallingIdentity(identity);
9406 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009407 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009408
9409 /**
9410 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009411 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9412 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009413 * Require system privileges. In the future we may add this to carrier APIs.
9414 *
Michele Berionne482f8202018-11-27 18:57:59 -08009415 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009416 */
9417 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009418 @TelephonyManager.SetCarrierRestrictionResult
9419 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009420 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07009421 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009422
Michele Berionne482f8202018-11-27 18:57:59 -08009423 if (carrierRestrictionRules == null) {
9424 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009425 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009426
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009427 final long identity = Binder.clearCallingIdentity();
9428 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009429 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009430 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009431 } finally {
9432 Binder.restoreCallingIdentity(identity);
9433 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009434 }
9435
9436 /**
9437 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009438 * Get the allowed carrier list and the excluded carrier list, including the priority between
9439 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009440 * Require system privileges. In the future we may add this to carrier APIs.
9441 *
Michele Berionne482f8202018-11-27 18:57:59 -08009442 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009443 */
9444 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009445 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009446 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07009447 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009448
9449 final long identity = Binder.clearCallingIdentity();
9450 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009451 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9452 if (response instanceof CarrierRestrictionRules) {
9453 return (CarrierRestrictionRules) response;
9454 }
9455 // Response is an Exception of some kind,
9456 // which is signalled to the user as a NULL retval
9457 return null;
9458 } catch (Exception e) {
9459 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9460 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009461 } finally {
9462 Binder.restoreCallingIdentity(identity);
9463 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009464 }
9465
fionaxu59545b42016-05-25 15:53:37 -07009466 /**
arunvoddud7401012022-12-15 16:08:12 +00009467 * Fetches the carrier restriction status of the device and sends the status to the caller
9468 * through the callback.
9469 *
9470 * @param callback The callback that will be used to send the result.
9471 * @throws SecurityException if the caller does not have the required permission/privileges or
9472 * the caller is not allowlisted.
9473 */
9474 @Override
9475 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9476 enforceReadPermission("getCarrierRestrictionStatus");
9477 int carrierId = validateCallerAndGetCarrierId(packageName);
9478 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
9479 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9480 throw new SecurityException("Not an authorized caller");
9481 }
9482 final long identity = Binder.clearCallingIdentity();
9483 try {
9484 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
9485 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
9486 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9487 } finally {
9488 Binder.restoreCallingIdentity(identity);
9489 }
9490 }
9491
9492 @VisibleForTesting
9493 public int validateCallerAndGetCarrierId(String packageName) {
9494 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9495 return allowListInfo.validateCallerAndGetCarrierId(packageName);
9496 }
9497
9498 /**
fionaxu59545b42016-05-25 15:53:37 -07009499 * Action set from carrier signalling broadcast receivers to enable/disable radio
9500 * @param subId the subscription ID that this action applies to.
9501 * @param enabled control enable or disable radio.
9502 * {@hide}
9503 */
9504 @Override
9505 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9506 enforceModifyPermission();
9507 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009508
9509 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009510 if (phone == null) {
9511 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9512 return;
9513 }
9514 try {
9515 phone.carrierActionSetRadioEnabled(enabled);
9516 } catch (Exception e) {
9517 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009518 } finally {
9519 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009520 }
9521 }
9522
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009523 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009524 * Enable or disable Voice over NR (VoNR)
9525 * @param subId the subscription ID that this action applies to.
9526 * @param enabled enable or disable VoNR.
9527 * @return operation result.
9528 */
9529 @Override
9530 public int setVoNrEnabled(int subId, boolean enabled) {
9531 enforceModifyPermission();
9532 final Phone phone = getPhone(subId);
9533
9534 final long identity = Binder.clearCallingIdentity();
9535 if (phone == null) {
9536 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9537 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9538 }
9539
9540 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9541 try {
9542 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9543 workSource);
9544 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009545
9546 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9547 if (DBG) {
9548 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9549 }
9550 SubscriptionManager.setSubscriptionProperty(
9551 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9552 (enabled ? "1" : "0"));
9553 }
9554
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009555 return result;
9556 } finally {
9557 Binder.restoreCallingIdentity(identity);
9558 }
9559 }
9560
9561 /**
9562 * Is voice over NR enabled
9563 * @return true if VoNR is enabled else false
9564 */
9565 @Override
9566 public boolean isVoNrEnabled(int subId) {
9567 enforceReadPrivilegedPermission("isVoNrEnabled");
9568 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9569 final long identity = Binder.clearCallingIdentity();
9570 try {
9571 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9572 null, subId, workSource);
9573 if (DBG) log("isVoNrEnabled: " + isEnabled);
9574 return isEnabled;
9575 } finally {
9576 Binder.restoreCallingIdentity(identity);
9577 }
9578 }
9579
9580 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009581 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9582 * network status based on which carrier apps could apply actions accordingly,
9583 * enable/disable default url handler for example.
9584 *
9585 * @param subId the subscription ID that this action applies to.
9586 * @param report control start/stop reporting the default network status.
9587 * {@hide}
9588 */
9589 @Override
9590 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9591 enforceModifyPermission();
9592 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009593
9594 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009595 if (phone == null) {
9596 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9597 return;
9598 }
9599 try {
9600 phone.carrierActionReportDefaultNetworkStatus(report);
9601 } catch (Exception e) {
9602 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009603 } finally {
9604 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009605 }
9606 }
9607
9608 /**
fionaxud9622282017-07-17 17:51:30 -07009609 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9610 * @param subId the subscription ID that this action applies to.
9611 * {@hide}
9612 */
9613 @Override
9614 public void carrierActionResetAll(int subId) {
9615 enforceModifyPermission();
9616 final Phone phone = getPhone(subId);
9617 if (phone == null) {
9618 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9619 return;
9620 }
9621 try {
9622 phone.carrierActionResetAll();
9623 } catch (Exception e) {
9624 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9625 }
9626 }
9627
9628 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009629 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9630 * bug report is being generated.
9631 */
9632 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009633 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009634 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9635 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009636 writer.println("Permission Denial: can't dump Phone from pid="
9637 + Binder.getCallingPid()
9638 + ", uid=" + Binder.getCallingUid()
9639 + "without permission "
9640 + android.Manifest.permission.DUMP);
9641 return;
9642 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009643 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009644 }
Jack Yueb89b242016-06-22 13:27:47 -07009645
Brad Ebingerdac2f002018-04-03 15:17:52 -07009646 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009647 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9648 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9649 @NonNull String[] args) {
9650 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9651 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009652 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009653 }
9654
Jack Yueb89b242016-06-22 13:27:47 -07009655 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009656 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009657 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009658 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009659 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009660 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009661 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009662 */
9663 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009664 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009665 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009666 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9667 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9668 try {
9669 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009670 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009671 } catch (SecurityException se) {
9672 enforceModifyPermission();
9673 }
9674 } else {
9675 enforceModifyPermission();
9676 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009677
9678 final long identity = Binder.clearCallingIdentity();
9679 try {
9680 Phone phone = getPhone(subId);
9681 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009682 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9683 phone.carrierActionSetMeteredApnsEnabled(enabled);
9684 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009685 phone.getDataSettingsManager().setDataEnabled(
9686 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009687 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009688 }
9689 } finally {
9690 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009691 }
9692 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009693
9694 /**
9695 * Get Client request stats
9696 * @return List of Client Request Stats
9697 * @hide
9698 */
9699 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009700 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9701 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009702 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009703 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009704 return null;
9705 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009706 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009707
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009708 final long identity = Binder.clearCallingIdentity();
9709 try {
9710 if (phone != null) {
9711 return phone.getClientRequestStats();
9712 }
9713
9714 return null;
9715 } finally {
9716 Binder.restoreCallingIdentity(identity);
9717 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009718 }
9719
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009720 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009721 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009722 if (uid == Process.ROOT_UID && packageName == null) {
9723 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9724 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9725 // exception. ROOT_UID seems not to have a valid package name returned by
9726 // PackageManager, so just fake it here to avoid issues when running telephony shell
9727 // commands that plumb through the RIL as root, like so:
9728 // $ adb root
9729 // $ adb shell cmd phone ...
9730 packageName = "root";
9731 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009732 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009733 }
Jack Yueb4124c2017-02-16 15:32:43 -08009734
9735 /**
Grace Chen70990072017-03-24 17:21:30 -07009736 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009737 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009738 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009739 * @param state State of SIM (power down, power up, pass through)
9740 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9741 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9742 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009743 *
9744 **/
9745 @Override
Grace Chen70990072017-03-24 17:21:30 -07009746 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009747 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009748 Phone phone = PhoneFactory.getPhone(slotIndex);
9749
vagdeviaf9a5b92018-08-15 16:01:53 -07009750 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9751
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009752 final long identity = Binder.clearCallingIdentity();
9753 try {
9754 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009755 phone.setSimPowerState(state, null, workSource);
9756 }
9757 } finally {
9758 Binder.restoreCallingIdentity(identity);
9759 }
9760 }
9761
9762 /**
9763 * Set SIM card power state.
9764 *
9765 * @param slotIndex SIM slot id.
9766 * @param state State of SIM (power down, power up, pass through)
9767 * @param callback callback to trigger after success or failure
9768 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9769 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9770 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9771 *
9772 **/
9773 @Override
9774 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9775 IIntegerConsumer callback) {
9776 enforceModifyPermission();
9777 Phone phone = PhoneFactory.getPhone(slotIndex);
9778
9779 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9780
9781 final long identity = Binder.clearCallingIdentity();
9782 try {
9783 if (phone != null) {
9784 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9785 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009786 }
9787 } finally {
9788 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009789 }
9790 }
Shuo Qiandd210312017-04-12 22:11:33 +00009791
Tyler Gunn65d45c22017-06-05 11:22:26 -07009792 private boolean isUssdApiAllowed(int subId) {
9793 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009794 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009795 if (configManager == null) {
9796 return false;
9797 }
9798 PersistableBundle pb = configManager.getConfigForSubId(subId);
9799 if (pb == null) {
9800 return false;
9801 }
9802 return pb.getBoolean(
9803 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9804 }
9805
Shuo Qiandd210312017-04-12 22:11:33 +00009806 /**
9807 * Check if phone is in emergency callback mode
9808 * @return true if phone is in emergency callback mode
9809 * @param subId sub id
9810 */
goneil9c5f4872017-12-05 14:07:56 -08009811 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009812 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009813 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00009814 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009815
9816 final long identity = Binder.clearCallingIdentity();
9817 try {
9818 if (phone != null) {
9819 return phone.isInEcm();
9820 } else {
9821 return false;
9822 }
9823 } finally {
9824 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009825 }
9826 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009827
9828 /**
9829 * Get the current signal strength information for the given subscription.
9830 * Because this information is not updated when the device is in a low power state
9831 * it should not be relied-upon to be current.
9832 * @param subId Subscription index
9833 * @return the most recent cached signal strength info from the modem
9834 */
9835 @Override
9836 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009837 final long identity = Binder.clearCallingIdentity();
9838 try {
9839 Phone p = getPhone(subId);
9840 if (p == null) {
9841 return null;
9842 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009843
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009844 return p.getSignalStrength();
9845 } finally {
9846 Binder.restoreCallingIdentity(identity);
9847 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009848 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009849
Pengquan Meng77b7f132018-08-22 14:49:57 -07009850 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009851 * Get the current modem radio state for the given slot.
9852 * @param slotIndex slot index.
9853 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009854 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009855 * @return the current radio power state from the modem
9856 */
9857 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009858 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009859 Phone phone = PhoneFactory.getPhone(slotIndex);
9860 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009861 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9862 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009863 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9864 }
9865
9866 final long identity = Binder.clearCallingIdentity();
9867 try {
9868 return phone.getRadioPowerState();
9869 } finally {
9870 Binder.restoreCallingIdentity(identity);
9871 }
9872 }
9873 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9874 }
9875
9876 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009877 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9878 *
9879 * <p>Requires one of the following permissions:
9880 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009881 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009882 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9883 * privileges.
9884 *
9885 * @param subId subscription id
9886 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9887 * {@code false}.
9888 */
9889 @Override
9890 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009891 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009892 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009893 try {
9894 mApp.enforceCallingOrSelfPermission(
9895 android.Manifest.permission.ACCESS_NETWORK_STATE,
9896 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009897 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009898 mApp.enforceCallingOrSelfPermission(
9899 permission.READ_BASIC_PHONE_STATE, functionName);
9900 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009901 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009902 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009903 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009904 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009905
Pengquan Menga1bb6272018-09-06 09:59:22 -07009906 boolean isEnabled = false;
9907 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009908 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009909 Phone phone = getPhone(subId);
9910 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009911 } finally {
9912 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009913 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009914 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009915 }
9916
9917
9918 /**
9919 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9920 *
9921 * <p> Requires permission:
9922 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9923 * privileges.
9924 *
9925 * @param subId subscription id
9926 * @param isEnabled {@code true} means enable, {@code false} means disable.
9927 */
9928 @Override
9929 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009930 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9931 mApp, subId, "setDataRoamingEnabled");
9932
Pengquan Menga1bb6272018-09-06 09:59:22 -07009933 final long identity = Binder.clearCallingIdentity();
9934 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009935 Phone phone = getPhone(subId);
9936 if (phone != null) {
9937 phone.setDataRoamingEnabled(isEnabled);
9938 }
9939 } finally {
9940 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009941 }
9942 }
9943
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009944 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009945 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009946 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009947 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009948 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009949
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009950 boolean isAllowed = true;
9951 final long identity = Binder.clearCallingIdentity();
9952 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009953 Phone phone = getPhone(subId);
9954 if (phone != null) {
9955 isAllowed = phone.isCspPlmnEnabled();
9956 }
9957 } finally {
9958 Binder.restoreCallingIdentity(identity);
9959 }
9960 return isAllowed;
9961 }
9962
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009963 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9964 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009965 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009966 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009967 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009968 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9969 if (phone == null) {
9970 return false;
9971 }
9972 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9973 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9974 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009975 }
9976
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009977 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009978 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009979 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009980 mApp.getSystemService(AppOpsManager.class)
9981 .checkPackage(Binder.getCallingUid(), callingPackage);
9982
Jordan Liu1e142fc2019-04-22 15:10:43 -07009983 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009984 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009985 try {
9986 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009987 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009988 } catch (SecurityException e) {
9989 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9990 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009991 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009992 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009993 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009994 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009995 }
sandeepjsb6c87872021-09-27 15:34:44 +00009996 // checking compatibility, if calling app's target SDK is T and beyond.
9997 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9998 Binder.getCallingUid())) {
9999 isIccIdAccessRestricted = true;
10000 }
Jordan Liu5aa07002018-12-18 15:44:48 -080010001 final long identity = Binder.clearCallingIdentity();
10002 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -080010003 UiccController uiccController = UiccController.getInstance();
10004 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -070010005 if (hasReadPermission) {
10006 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -080010007 }
Jordan Liu1e142fc2019-04-22 15:10:43 -070010008
10009 // Remove private info if the caller doesn't have access
10010 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
10011 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +000010012 //setting the value after compatibility check
10013 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -070010014 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
10015 // is available
sandeepjsb6c87872021-09-27 15:34:44 +000010016 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010017 if (card == null) {
10018 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +000010019 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -070010020 continue;
10021 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010022 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
10023 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +000010024 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010025 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -070010026 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010027 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
10028 for (UiccPortInfo portInfo : portInfos) {
10029 UiccPort port = uiccController.getUiccPortForSlot(
10030 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
10031 if (port == null) {
10032 // assume no access if port is null
10033 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
10034 continue;
10035 }
10036 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10037 uiccPortInfos.add(portInfo);
10038 } else {
10039 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
10040 }
10041 }
10042 filteredInfos.add(new UiccCardInfo(
10043 cardInfo.isEuicc(),
10044 cardInfo.getCardId(),
10045 null,
10046 cardInfo.getPhysicalSlotIndex(),
10047 cardInfo.isRemovable(),
10048 cardInfo.isMultipleEnabledProfilesSupported(),
10049 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -070010050 }
10051 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -080010052 } finally {
10053 Binder.restoreCallingIdentity(identity);
10054 }
10055 }
10056
sandeepjsb6c87872021-09-27 15:34:44 +000010057 /**
10058 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
10059 * generally private and require carrier privileges to view.
10060 *
10061 * @hide
10062 */
10063 @NonNull
10064 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
10065 List<UiccPortInfo> portinfo = new ArrayList<>();
10066 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
10067 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
10068 }
10069 return new UiccCardInfo(
10070 cardInfo.isEuicc(),
10071 cardInfo.getCardId(),
10072 null,
10073 cardInfo.getPhysicalSlotIndex(),
10074 cardInfo.isRemovable(),
10075 cardInfo.isMultipleEnabledProfilesSupported(),
10076 portinfo
10077 );
10078 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010079
sandeepjsb6c87872021-09-27 15:34:44 +000010080 /**
10081 * @hide
10082 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
10083 * These values are generally private and require carrier privileges to view.
10084 */
10085 @NonNull
10086 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
10087 return new UiccPortInfo(
10088 UiccPortInfo.ICCID_REDACTED,
10089 portInfo.getPortIndex(),
10090 portInfo.getLogicalSlotIndex(),
10091 portInfo.isActive()
10092 );
10093 }
10094 @Override
10095 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +000010096 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +000010097 mApp.getSystemService(AppOpsManager.class)
10098 .checkPackage(Binder.getCallingUid(), callingPackage);
10099
sandeepjsb6c87872021-09-27 15:34:44 +000010100 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +000010101
Aman Guptaf3c90b32022-03-17 04:54:16 +000010102 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
10103 // we are reading iccId which is PII data.
10104 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +000010105
10106 // checking compatibility, if calling app's target SDK is T and beyond.
10107 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
10108 Binder.getCallingUid())) {
10109 isLogicalSlotAccessRestricted = true;
10110 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010111 final long identity = Binder.clearCallingIdentity();
10112 try {
10113 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +000010114 if (slots == null || slots.length == 0) {
10115 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010116 return null;
10117 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010118 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
10119 for (int i = 0; i < slots.length; i++) {
10120 UiccSlot slot = slots[i];
10121 if (slot == null) {
10122 continue;
10123 }
10124
Jordan Liu7be7e652019-05-06 18:55:02 +000010125 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010126 UiccCard card = slot.getUiccCard();
10127 if (card != null) {
10128 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +000010129 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -070010130 cardId = slot.getEid();
10131 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +000010132 // If cardId is null, use iccId of default port as cardId.
10133 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -070010134 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010135 }
10136
Jordan Liu857451f2019-05-09 16:35:35 -070010137 if (cardId != null) {
10138 // if cardId is an ICCID, strip off trailing Fs before exposing to user
10139 // if cardId is an EID, it's all digits so this is fine
10140 cardId = IccUtils.stripTrailingFs(cardId);
10141 }
10142
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010143 int cardState = 0;
10144 switch (slot.getCardState()) {
10145 case CARDSTATE_ABSENT:
10146 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
10147 break;
10148 case CARDSTATE_PRESENT:
10149 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
10150 break;
10151 case CARDSTATE_ERROR:
10152 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
10153 break;
10154 case CARDSTATE_RESTRICTED:
10155 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
10156 break;
10157 default:
10158 break;
10159
10160 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010161 List<UiccPortInfo> portInfos = new ArrayList<>();
10162 int[] portIndexes = slot.getPortList();
10163 for (int portIdx : portIndexes) {
10164 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010165 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010166 portInfos.add(new UiccPortInfo(iccId, portIdx,
10167 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010168 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010169 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010170 slot.isEuicc(),
10171 cardId,
10172 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010173 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010174 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010175 //setting the value after compatibility check
10176 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010177 }
10178 return infos;
10179 } finally {
10180 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010181 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010182 }
10183
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010184 /* Returns null if doesn't have read permission or carrier privilege access. */
10185 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10186 boolean hasReadPermission) {
10187 String iccId = slot.getIccId(portIndex);
10188 if (hasReadPermission) { // if has read permission
10189 return iccId;
10190 } else {
10191 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10192 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10193 // if no read permission, checking carrier privilege access
10194 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10195 return iccId;
10196 }
10197 }
10198 }
10199 // No read permission or carrier privilege access.
10200 return UiccPortInfo.ICCID_REDACTED;
10201 }
10202
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010203 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010204 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010205 public boolean switchSlots(int[] physicalSlots) {
10206 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010207
10208 final long identity = Binder.clearCallingIdentity();
10209 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010210 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10211 for (int i = 0; i < physicalSlots.length; i++) {
10212 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10213 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10214 physicalSlots[i], i));
10215 }
10216 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010217 } finally {
10218 Binder.restoreCallingIdentity(identity);
10219 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010220 }
Jack Yu4c988042018-02-27 15:30:01 -080010221
10222 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010223 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10224 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10225 enforceModifyPermission();
10226
10227 final long identity = Binder.clearCallingIdentity();
10228 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010229 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010230 } finally {
10231 Binder.restoreCallingIdentity(identity);
10232 }
10233 }
10234
10235 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010236 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -080010237 final long identity = Binder.clearCallingIdentity();
10238 try {
10239 return UiccController.getInstance().getCardIdForDefaultEuicc();
10240 } finally {
10241 Binder.restoreCallingIdentity(identity);
10242 }
10243 }
10244
Pengquan Meng85728fb2018-03-12 16:31:21 -070010245 /**
goneil47ffb6e2018-04-06 15:40:58 -070010246 * A test API to reload the UICC profile.
10247 *
10248 * <p>Requires that the calling app has permission
10249 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10250 * @hide
10251 */
10252 @Override
10253 public void refreshUiccProfile(int subId) {
10254 enforceModifyPermission();
10255
10256 final long identity = Binder.clearCallingIdentity();
10257 try {
10258 Phone phone = getPhone(subId);
10259 if (phone == null) {
10260 return;
10261 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010262 UiccPort uiccPort = phone.getUiccPort();
10263 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010264 return;
10265 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010266 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010267 if (uiccProfile == null) {
10268 return;
10269 }
10270 uiccProfile.refresh();
10271 } finally {
10272 Binder.restoreCallingIdentity(identity);
10273 }
10274 }
10275
10276 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010277 * Returns false if the mobile data is disabled by default, otherwise return true.
10278 */
10279 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010280 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010281 }
10282
10283 /**
10284 * Returns true if the data roaming is enabled by default, i.e the system property
10285 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
10286 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
10287 */
10288 private boolean getDefaultDataRoamingEnabled(int subId) {
10289 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010290 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -070010291 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010292 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
10293 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
10294 return isDataRoamingEnabled;
10295 }
10296
10297 /**
10298 * Returns the default network type for the given {@code subId}, if the default network type is
10299 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10300 */
10301 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010302 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010303 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010304 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10305 return list.get(phoneId);
10306 }
10307 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010308 }
fionaxua13278b2018-03-21 00:08:13 -070010309
10310 @Override
10311 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010312 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010313 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010314
10315 final long identity = Binder.clearCallingIdentity();
10316 try {
10317 final Phone phone = getPhone(subId);
10318 if (phone == null) {
10319 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10320 return;
10321 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010322 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10323 if (cpt != null) {
10324 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10325 }
10326 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010327 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10328 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010329 if (carrierPrivilegeRules == null) {
10330 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10331 } else {
10332 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10333 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010334 } finally {
10335 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010336 }
fionaxua13278b2018-03-21 00:08:13 -070010337 }
10338
10339 @Override
10340 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010341 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010342
10343 final long identity = Binder.clearCallingIdentity();
10344 try {
10345 final Phone phone = getPhone(subId);
10346 if (phone == null) {
10347 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10348 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10349 }
10350 return phone.getCarrierIdListVersion();
10351 } finally {
10352 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010353 }
fionaxua13278b2018-03-21 00:08:13 -070010354 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010355
10356 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010357 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10358 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010359 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010360 mApp, subId, callingPackage, callingFeatureId,
10361 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010362 return -1;
10363 }
10364
10365 final long identity = Binder.clearCallingIdentity();
10366 try {
10367 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10368 } finally {
10369 Binder.restoreCallingIdentity(identity);
10370 }
10371 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010372
10373 @Override
10374 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010375 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010376 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010377 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010378
10379 final long identity = Binder.clearCallingIdentity();
10380 try {
10381 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10382 } finally {
10383 Binder.restoreCallingIdentity(identity);
10384 }
10385 }
10386
10387 @Override
10388 public boolean setCdmaRoamingMode(int subId, int mode) {
10389 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10390 mApp, subId, "setCdmaRoamingMode");
10391
10392 final long identity = Binder.clearCallingIdentity();
10393 try {
10394 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10395 } finally {
10396 Binder.restoreCallingIdentity(identity);
10397 }
10398 }
10399
10400 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010401 public int getCdmaSubscriptionMode(int subId) {
10402 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010403 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010404 mApp, subId, "getCdmaSubscriptionMode");
10405
10406 final long identity = Binder.clearCallingIdentity();
10407 try {
10408 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10409 } finally {
10410 Binder.restoreCallingIdentity(identity);
10411 }
10412 }
10413
10414 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010415 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10416 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10417 mApp, subId, "setCdmaSubscriptionMode");
10418
10419 final long identity = Binder.clearCallingIdentity();
10420 try {
10421 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10422 } finally {
10423 Binder.restoreCallingIdentity(identity);
10424 }
10425 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010426
sqianc5eccab2018-10-19 18:46:41 -070010427 @Override
sqian8c685422019-02-22 15:55:18 -080010428 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010429 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010430 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010431 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10432 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010433 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10434 }
10435 final long identity = Binder.clearCallingIdentity();
10436 try {
sqian854d44b2018-12-12 16:48:18 -080010437 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10438 for (Phone phone: PhoneFactory.getPhones()) {
10439 if (phone.getEmergencyNumberTracker() != null
10440 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10441 emergencyNumberListInternal.put(
10442 phone.getSubId(),
10443 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10444 }
sqian11b7a0e2018-12-05 18:48:28 -080010445 }
sqian854d44b2018-12-12 16:48:18 -080010446 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010447 } finally {
10448 Binder.restoreCallingIdentity(identity);
10449 }
sqianc5eccab2018-10-19 18:46:41 -070010450 }
10451
10452 @Override
sqian8c685422019-02-22 15:55:18 -080010453 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010454 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010455 if (!exactMatch) {
10456 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010457 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010458 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010459 }
10460 final long identity = Binder.clearCallingIdentity();
10461 try {
sqian854d44b2018-12-12 16:48:18 -080010462 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010463 //Note: we ignore passed in param exactMatch. We can remove it once
10464 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010465 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010466 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010467 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010468 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010469 }
sqian11b7a0e2018-12-05 18:48:28 -080010470 }
10471 return false;
10472 } finally {
10473 Binder.restoreCallingIdentity(identity);
10474 }
10475 }
10476
sqianf4ca7ed2019-01-15 18:32:07 -080010477 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010478 * Start emergency callback mode for GsmCdmaPhone for testing.
10479 */
10480 @Override
10481 public void startEmergencyCallbackMode() {
10482 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10483 "startEmergencyCallbackMode");
10484 enforceModifyPermission();
10485 final long identity = Binder.clearCallingIdentity();
10486 try {
10487 for (Phone phone : PhoneFactory.getPhones()) {
10488 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10489 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10490 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10491 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10492 gsmCdmaPhone.obtainMessage(
10493 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10494 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10495 }
10496 }
10497 } finally {
10498 Binder.restoreCallingIdentity(identity);
10499 }
10500 }
10501
10502 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010503 * Update emergency number list for test mode.
10504 */
10505 @Override
10506 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10507 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10508 "updateEmergencyNumberListTestMode");
10509
10510 final long identity = Binder.clearCallingIdentity();
10511 try {
10512 for (Phone phone: PhoneFactory.getPhones()) {
10513 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10514 if (tracker != null) {
10515 tracker.executeEmergencyNumberTestModeCommand(action, num);
10516 }
10517 }
10518 } finally {
10519 Binder.restoreCallingIdentity(identity);
10520 }
10521 }
10522
10523 /**
10524 * Get the full emergency number list for test mode.
10525 */
10526 @Override
10527 public List<String> getEmergencyNumberListTestMode() {
10528 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10529 "getEmergencyNumberListTestMode");
10530
10531 final long identity = Binder.clearCallingIdentity();
10532 try {
10533 Set<String> emergencyNumbers = new HashSet<>();
10534 for (Phone phone: PhoneFactory.getPhones()) {
10535 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10536 if (tracker != null) {
10537 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10538 emergencyNumbers.add(num.getNumber());
10539 }
10540 }
10541 }
10542 return new ArrayList<>(emergencyNumbers);
10543 } finally {
10544 Binder.restoreCallingIdentity(identity);
10545 }
10546 }
10547
chen xud6b45bd2018-10-30 22:27:10 -070010548 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010549 public int getEmergencyNumberDbVersion(int subId) {
10550 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10551
10552 final long identity = Binder.clearCallingIdentity();
10553 try {
10554 final Phone phone = getPhone(subId);
10555 if (phone == null) {
10556 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10557 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10558 }
10559 return phone.getEmergencyNumberDbVersion();
10560 } finally {
10561 Binder.restoreCallingIdentity(identity);
10562 }
10563 }
10564
10565 @Override
10566 public void notifyOtaEmergencyNumberDbInstalled() {
10567 enforceModifyPermission();
10568
10569 final long identity = Binder.clearCallingIdentity();
10570 try {
10571 for (Phone phone: PhoneFactory.getPhones()) {
10572 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10573 if (tracker != null) {
10574 tracker.updateOtaEmergencyNumberDatabase();
10575 }
10576 }
10577 } finally {
10578 Binder.restoreCallingIdentity(identity);
10579 }
10580 }
10581
10582 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010583 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010584 enforceActiveEmergencySessionPermission();
10585
10586 final long identity = Binder.clearCallingIdentity();
10587 try {
10588 for (Phone phone: PhoneFactory.getPhones()) {
10589 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10590 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010591 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10592 }
10593 }
10594 } finally {
10595 Binder.restoreCallingIdentity(identity);
10596 }
10597 }
10598
10599 @Override
10600 public void resetOtaEmergencyNumberDbFilePath() {
10601 enforceActiveEmergencySessionPermission();
10602
10603 final long identity = Binder.clearCallingIdentity();
10604 try {
10605 for (Phone phone: PhoneFactory.getPhones()) {
10606 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10607 if (tracker != null) {
10608 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010609 }
10610 }
10611 } finally {
10612 Binder.restoreCallingIdentity(identity);
10613 }
10614 }
10615
10616 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010617 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10618 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10619 Phone phone = getPhone(subId);
10620 if (phone == null) {
10621 return null;
10622 }
10623 final long identity = Binder.clearCallingIdentity();
10624 try {
10625 UiccProfile profile = UiccController.getInstance()
10626 .getUiccProfileForPhone(phone.getPhoneId());
10627 if (profile != null) {
10628 return profile.getCertsFromCarrierPrivilegeAccessRules();
10629 }
10630 } finally {
10631 Binder.restoreCallingIdentity(identity);
10632 }
10633 return null;
10634 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010635
10636 /**
10637 * Enable or disable a modem stack.
10638 */
10639 @Override
10640 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10641 enforceModifyPermission();
10642
10643 final long identity = Binder.clearCallingIdentity();
10644 try {
10645 Phone phone = PhoneFactory.getPhone(slotIndex);
10646 if (phone == null) {
10647 return false;
10648 } else {
10649 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10650 }
10651 } finally {
10652 Binder.restoreCallingIdentity(identity);
10653 }
10654 }
Michelecea4cf22018-12-21 15:00:11 -080010655
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010656 /**
10657 * Whether a modem stack is enabled or not.
10658 */
10659 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010660 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10661 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010662 Phone phone = PhoneFactory.getPhone(slotIndex);
10663 if (phone == null) return false;
10664
10665 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010666 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10667 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010668 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10669 }
10670
10671 final long identity = Binder.clearCallingIdentity();
10672 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010673 try {
10674 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10675 } catch (NoSuchElementException ex) {
10676 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10677 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010678 } finally {
10679 Binder.restoreCallingIdentity(identity);
10680 }
10681 }
10682
Michelecea4cf22018-12-21 15:00:11 -080010683 @Override
Michele0ea7d782019-03-19 14:58:42 -070010684 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010685 enforceModifyPermission();
10686
10687 final long identity = Binder.clearCallingIdentity();
10688 try {
10689 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010690 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010691 .commit();
10692 } finally {
10693 Binder.restoreCallingIdentity(identity);
10694 }
10695 }
10696
10697 @Override
Michele0ea7d782019-03-19 14:58:42 -070010698 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010699 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010700 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010701 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10702 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010703 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010704 }
Michelecea4cf22018-12-21 15:00:11 -080010705
10706 final long identity = Binder.clearCallingIdentity();
10707 try {
Michele0ea7d782019-03-19 14:58:42 -070010708 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010709 } finally {
10710 Binder.restoreCallingIdentity(identity);
10711 }
10712 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010713
Michele0ea7d782019-03-19 14:58:42 -070010714 @TelephonyManager.IsMultiSimSupportedResult
10715 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010716 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10717 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10718 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010719 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10720 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010721 }
10722 // Check if the hardware supports multisim functionality. If usage of multisim is not
10723 // supported by the modem, indicate that it is restricted.
10724 PhoneCapability staticCapability =
10725 mPhoneConfigurationManager.getStaticPhoneCapability();
10726 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010727 loge("isMultiSimSupportedInternal: no static configuration available");
10728 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010729 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010730 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010731 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10732 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010733 }
10734 // Check if support of multiple SIMs is restricted by carrier
10735 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010736 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010737 }
10738
Michele0ea7d782019-03-19 14:58:42 -070010739 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010740 }
10741
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010742 /**
10743 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010744 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10745 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10746 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010747 * @param numOfSims number of active sims we want to switch to
10748 */
10749 @Override
10750 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010751 if (numOfSims == 1) {
10752 enforceModifyPermission();
10753 } else {
10754 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10755 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10756 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010757 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010758
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010759 try {
Michele30b57b22019-03-01 12:01:14 -080010760 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010761 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010762 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10763 return;
10764 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010765 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10766 } finally {
10767 Binder.restoreCallingIdentity(identity);
10768 }
10769 }
10770
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010771 @Override
10772 public boolean isApplicationOnUicc(int subId, int appType) {
10773 enforceReadPrivilegedPermission("isApplicationOnUicc");
10774 Phone phone = getPhone(subId);
10775 if (phone == null) {
10776 return false;
10777 }
10778 final long identity = Binder.clearCallingIdentity();
10779 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010780 UiccPort uiccPort = phone.getUiccPort();
10781 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010782 return false;
10783 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010784 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010785 if (uiccProfile == null) {
10786 return false;
10787 }
10788 if (TelephonyManager.APPTYPE_SIM <= appType
10789 && appType <= TelephonyManager.APPTYPE_ISIM) {
10790 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10791 }
10792 return false;
10793 } finally {
10794 Binder.restoreCallingIdentity(identity);
10795 }
10796 }
10797
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010798 /**
chen xub4baa772019-04-03 10:23:41 -070010799 * Get whether making changes to modem configurations will trigger reboot.
10800 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010801 */
10802 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010803 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10804 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010805 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010806 mApp, subId, callingPackage, callingFeatureId,
10807 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010808 return false;
10809 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010810 final long identity = Binder.clearCallingIdentity();
10811 try {
10812 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10813 } finally {
10814 Binder.restoreCallingIdentity(identity);
10815 }
10816 }
10817
Nathan Harold29f5f052019-02-15 13:41:57 -080010818 private void updateModemStateMetrics() {
10819 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10820 // TODO: check the state for each modem if the api is ready.
10821 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10822 }
10823
Pengquan Meng3889a572019-01-23 11:16:29 -080010824 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010825 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010826 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010827 // Verify that the callingPackage belongs to the calling UID
10828 mApp.getSystemService(AppOpsManager.class)
10829 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010830 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010831 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010832 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010833 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10834 if (slotInfos != null) {
10835 for (int i = 0; i < slotInfos.length; i++) {
10836 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10837 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10838 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10839 portInfo.getLogicalSlotIndex()));
10840 }
10841 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010842 }
10843 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010844 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010845 } finally {
10846 Binder.restoreCallingIdentity(identity);
10847 }
10848 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010849
10850 /**
10851 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010852 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010853 */
jimsunf9ec1622022-09-13 21:18:43 +080010854 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010855 @Override
10856 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010857 return getHalVersion(HAL_SERVICE_RADIO);
10858 }
10859
10860 /**
10861 * Get the HAL Version of a specific service
10862 */
10863 @Override
10864 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010865 Phone phone = getDefaultPhone();
10866 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010867 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010868 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10869 return hv.major * 100 + hv.minor;
10870 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010871
10872 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010873 * Get the current calling package name.
10874 * @return the current calling package name
10875 */
10876 @Override
10877 public String getCurrentPackageName() {
10878 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10879 }
10880
10881 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010882 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10883 * corresponding network requests on a subId.
10884 *
10885 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010886 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010887 * 2) APN is un-metered for this subscription, or
10888 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010889 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010890 *
10891 * @return whether data is allowed for a apn type.
10892 *
10893 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010894 */
10895 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010896 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010897 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10898 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010899
10900 // Now that all security checks passes, perform the operation as ourselves.
10901 final long identity = Binder.clearCallingIdentity();
10902 try {
10903 Phone phone = getPhone(subId);
10904 if (phone == null) return false;
10905
Jack Yu27422a52022-03-21 10:38:05 -070010906 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010907 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010908 isMetered = phone.getDataNetworkController().getDataConfigManager()
10909 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10910 phone.getServiceState().getDataRoaming());
10911 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010912 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010913 } finally {
10914 Binder.restoreCallingIdentity(identity);
10915 }
10916 }
10917
10918 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010919 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010920 enforceReadPrivilegedPermission("isApnMetered");
10921
10922 // Now that all security checks passes, perform the operation as ourselves.
10923 final long identity = Binder.clearCallingIdentity();
10924 try {
10925 Phone phone = getPhone(subId);
10926 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010927 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10928 DataUtils.apnTypeToNetworkCapability(apnType),
10929 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010930 } finally {
10931 Binder.restoreCallingIdentity(identity);
10932 }
10933 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010934
10935 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010936 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10937 int subscriptionId, IBooleanConsumer resultCallback) {
10938 enforceModifyPermission();
10939 long token = Binder.clearCallingIdentity();
10940 try {
10941 Phone phone = getPhone(subscriptionId);
10942 if (phone == null) {
10943 try {
10944 if (resultCallback != null) {
10945 resultCallback.accept(false);
10946 }
10947 } catch (RemoteException e) {
10948 // ignore
10949 }
10950 return;
10951 }
10952 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10953 Pair.create(specifiers, (x) -> {
10954 try {
10955 if (resultCallback != null) {
10956 resultCallback.accept(x);
10957 }
10958 } catch (RemoteException e) {
10959 // ignore
10960 }
10961 });
10962 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10963 } finally {
10964 Binder.restoreCallingIdentity(token);
10965 }
10966 }
10967
10968 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010969 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10970 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010971 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010972 mApp, subId, "getSystemSelectionChannels");
10973 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10974 final long identity = Binder.clearCallingIdentity();
10975 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010976 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10977 if (result instanceof IllegalStateException) {
10978 throw (IllegalStateException) result;
10979 }
10980 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010981 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10982 return specifiers;
10983 } finally {
10984 Binder.restoreCallingIdentity(identity);
10985 }
10986 }
10987
10988 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010989 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010990 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010991 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010992 }
10993
10994 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010995 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10996 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010997 if (callingPackage == null) {
10998 callingPackage = getCurrentPackageName();
10999 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070011000 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
11001 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011002 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
11003 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070011004 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
11005 }
11006 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
11007 Intent intent = new Intent();
11008 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
11009 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11010 // Bring up choose default SMS subscription dialog right now
11011 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
11012 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
11013 mApp.startActivity(intent);
11014 }
chen xud5ca2d52019-05-28 15:20:57 -070011015
11016 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000011017 public void showSwitchToManagedProfileDialog() {
11018 enforceModifyPermission();
11019
11020 Intent intent = new Intent();
11021 intent.setClass(mApp, ErrorDialogActivity.class);
11022 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11023 mApp.startActivity(intent);
11024 }
11025
11026 @Override
chen xud5ca2d52019-05-28 15:20:57 -070011027 public String getMmsUAProfUrl(int subId) {
11028 //TODO investigate if this API should require proper permission check in R b/133791609
11029 final long identity = Binder.clearCallingIdentity();
11030 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011031 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
11032 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
11033 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
11034 return carrierUAProfUrl;
11035 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011036 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11037 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070011038 } finally {
11039 Binder.restoreCallingIdentity(identity);
11040 }
11041 }
11042
11043 @Override
11044 public String getMmsUserAgent(int subId) {
11045 //TODO investigate if this API should require proper permission check in R b/133791609
11046 final long identity = Binder.clearCallingIdentity();
11047 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011048 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
11049 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
11050 if (!TextUtils.isEmpty(carrierUserAgent)) {
11051 return carrierUserAgent;
11052 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011053 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11054 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011055 } finally {
11056 Binder.restoreCallingIdentity(identity);
11057 }
11058 }
Jack Yub07d4972019-05-28 16:12:25 -070011059
11060 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011061 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11062 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011063
Jack Yub07d4972019-05-28 16:12:25 -070011064 final long identity = Binder.clearCallingIdentity();
11065 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011066 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070011067 if (phone == null) return false;
11068
Ling Maf188d502022-09-16 15:22:36 -070011069 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011070 } finally {
11071 Binder.restoreCallingIdentity(identity);
11072 }
11073 }
11074
11075 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011076 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011077 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011078 enforceModifyPermission();
11079
changbettyd5c246e2019-12-24 15:40:37 +080011080 final long identity = Binder.clearCallingIdentity();
11081 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011082 Phone phone = getPhone(subscriptionId);
11083 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011084
Ling Maf188d502022-09-16 15:22:36 -070011085 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011086 } finally {
11087 Binder.restoreCallingIdentity(identity);
11088 }
11089 }
11090
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011091 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011092 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011093 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11094 * otherwise.
11095 */
11096 @Override
11097 public void setCepEnabled(boolean isCepEnabled) {
11098 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11099
11100 final long identity = Binder.clearCallingIdentity();
11101 try {
11102 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11103 for (Phone phone : PhoneFactory.getPhones()) {
11104 Phone defaultPhone = phone.getImsPhone();
11105 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11106 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11107 ImsPhoneCallTracker imsPhoneCallTracker =
11108 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11109 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11110 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11111 + imsPhone.getMsisdn());
11112 }
11113 }
11114 } finally {
11115 Binder.restoreCallingIdentity(identity);
11116 }
11117 }
allenwtsu46dcc572020-01-08 18:24:03 +080011118
11119 /**
11120 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11121 *
11122 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11123 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11124 * before being read.
11125 */
11126 @Override
11127 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11128 isCompressed) {
11129 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11130 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011131 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11132 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11133 }
11134 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011135 // ProvisioningManager can not handle ServiceSpecificException.
11136 // Throw the IllegalStateException and annotate ProvisioningManager.
11137 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000011138 }
11139
11140 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011141 try {
Hui Wang761a6682020-10-31 05:12:53 +000011142 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11143 } finally {
11144 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011145 }
11146 }
zoey chene02881a2019-12-30 16:11:23 +080011147
11148 @Override
11149 public boolean isIccLockEnabled(int subId) {
11150 enforceReadPrivilegedPermission("isIccLockEnabled");
11151
11152 // Now that all security checks passes, perform the operation as ourselves.
11153 final long identity = Binder.clearCallingIdentity();
11154 try {
11155 Phone phone = getPhone(subId);
11156 if (phone != null && phone.getIccCard() != null) {
11157 return phone.getIccCard().getIccLockEnabled();
11158 } else {
11159 return false;
11160 }
11161 } finally {
11162 Binder.restoreCallingIdentity(identity);
11163 }
11164 }
11165
11166 /**
11167 * Set the ICC pin lock enabled or disabled.
11168 *
11169 * @return an integer representing the status of IccLock enabled or disabled in the following
11170 * three cases:
11171 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11172 * successfully.
11173 * - Positive number and zero for remaining password attempts.
11174 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11175 *
11176 */
11177 @Override
11178 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11179 enforceModifyPermission();
11180
11181 Phone phone = getPhone(subId);
11182 if (phone == null) {
11183 return 0;
11184 }
11185 // Now that all security checks passes, perform the operation as ourselves.
11186 final long identity = Binder.clearCallingIdentity();
11187 try {
11188 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11189 new Pair<Boolean, String>(enabled, password), phone, null);
11190 return attemptsRemaining;
11191
11192 } catch (Exception e) {
11193 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11194 } finally {
11195 Binder.restoreCallingIdentity(identity);
11196 }
11197 return 0;
11198 }
11199
11200 /**
11201 * Change the ICC password used in ICC pin lock.
11202 *
11203 * @return an integer representing the status of IccLock changed in the following three cases:
11204 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11205 * - Positive number and zero for remaining password attempts.
11206 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11207 *
11208 */
11209 @Override
11210 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11211 enforceModifyPermission();
11212
11213 Phone phone = getPhone(subId);
11214 if (phone == null) {
11215 return 0;
11216 }
11217 // Now that all security checks passes, perform the operation as ourselves.
11218 final long identity = Binder.clearCallingIdentity();
11219 try {
11220 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11221 new Pair<String, String>(oldPassword, newPassword), phone, null);
11222 return attemptsRemaining;
11223
11224 } catch (Exception e) {
11225 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11226 } finally {
11227 Binder.restoreCallingIdentity(identity);
11228 }
11229 return 0;
11230 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011231
11232 /**
11233 * Request for receiving user activity notification
11234 */
11235 @Override
11236 public void requestUserActivityNotification() {
11237 if (!mNotifyUserActivity.get()
11238 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11239 mNotifyUserActivity.set(true);
11240 }
11241 }
11242
11243 /**
11244 * Called when userActivity is signalled in the power manager.
11245 * This is safe to call from any thread, with any window manager locks held or not.
11246 */
11247 @Override
11248 public void userActivity() {
11249 // ***************************************
11250 // * Inherited from PhoneWindowManager *
11251 // ***************************************
11252 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11253 // WITH ITS LOCKS HELD.
11254 //
11255 // This code must be VERY careful about the locks
11256 // it acquires.
11257 // In fact, the current code acquires way too many,
11258 // and probably has lurking deadlocks.
11259
11260 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11261 throw new SecurityException("Only the OS may call notifyUserActivity()");
11262 }
11263
11264 if (mNotifyUserActivity.getAndSet(false)) {
11265 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11266 USER_ACTIVITY_NOTIFICATION_DELAY);
11267 }
11268 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011269
11270 @Override
11271 public boolean canConnectTo5GInDsdsMode() {
11272 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11273 }
Jack Yud10cdd42020-09-28 20:28:01 -070011274
11275 @Override
11276 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11277 String callingFeatureId) {
11278 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11279 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11280 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11281 }
11282
11283 Phone phone = getPhone(subId);
11284 if (phone == null) {
11285 throw new RuntimeException("phone is not available");
11286 }
11287 // Now that all security checks passes, perform the operation as ourselves.
11288 final long identity = Binder.clearCallingIdentity();
11289 try {
11290 return phone.getEquivalentHomePlmns();
11291 } finally {
11292 Binder.restoreCallingIdentity(identity);
11293 }
11294 }
Daniel Bright59e67312020-11-13 11:49:37 -080011295
11296 @Override
11297 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011298 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
11299 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011300 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011301 if (radioInterfaceCapabilities == null) {
11302 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011303 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011304 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011305 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011306
Hui Wang641e81c2020-10-12 12:14:23 -070011307 @Override
11308 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11309 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011310 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11311 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11312 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11313 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11314 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070011315 if (DBG) {
11316 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11317 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11318 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11319 }
11320
11321 if (!SubscriptionManager.isValidSubscriptionId(subId)
11322 || appType < TelephonyManager.APPTYPE_UNKNOWN
11323 || appType > TelephonyManager.APPTYPE_ISIM
11324 || nafUrl == null || securityProtocol == null || callback == null) {
11325 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11326 if (callback != null) {
11327 try {
11328 callback.onAuthenticationFailure(
11329 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11330 } catch (RemoteException exception) {
11331 log("Fail to notify onAuthenticationFailure due to " + exception);
11332 }
11333 return;
11334 }
11335 }
11336
11337 final long token = Binder.clearCallingIdentity();
11338 try {
11339 getGbaManager(subId).bootstrapAuthenticationRequest(
11340 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011341 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011342 } finally {
11343 Binder.restoreCallingIdentity(token);
11344 }
11345 }
11346
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011347 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011348 * Attempts to set the radio power state for all phones for thermal reason.
11349 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011350 * requested radio power state will actually be set. See {@link
11351 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11352 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011353 * @param enable {@code true} if trying to turn radio on.
11354 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11355 * false}.
11356 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011357 private boolean setRadioPowerForThermal(boolean enable) {
11358 boolean isPhoneAvailable = false;
11359 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11360 Phone phone = PhoneFactory.getPhone(i);
11361 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011362 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011363 isPhoneAvailable = true;
11364 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011365 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011366
11367 // return true if successfully informed the phone object about the thermal radio power
11368 // request.
11369 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011370 }
11371
11372 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011373 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011374 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11375 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11376 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11377 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11378 throw new IllegalArgumentException("modem does not support data throttling");
11379 }
11380
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011381 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11382 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011383 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011384 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11385 }
11386
Sarah Chinecc78c42022-03-31 21:16:48 -070011387 setDataEnabledForReason(
11388 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011389
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011390 if (isDataThrottlingSupported) {
11391 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011392 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011393 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11394 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11395 } else if (thermalMitigationResult
11396 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011397 log("Modem likely does not support data throttling on secondary carrier. Data " +
11398 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11399 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011400 }
11401 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011402 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011403
11404 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011405 }
11406
Jack Nudelman644b91a2021-03-12 14:09:48 -080011407 private static List<String> getThermalMitigationAllowlist(Context context) {
11408 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11409 for (String pckg : context.getResources()
11410 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11411 sThermalMitigationAllowlistedPackages.add(pckg);
11412 }
11413 }
11414
11415 return sThermalMitigationAllowlistedPackages;
11416 }
11417
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011418 private boolean isAnyPhoneInEmergencyState() {
11419 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11420 if (tm.isInEmergencyCall()) {
11421 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11422 return true;
11423 }
11424 for (Phone phone : PhoneFactory.getPhones()) {
11425 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11426 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011427 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11428 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011429 return true;
11430 }
11431 }
11432
11433 return false;
11434 }
11435
Jack Nudelman644b91a2021-03-12 14:09:48 -080011436 /**
11437 * Used by shell commands to add an authorized package name for thermal mitigation.
11438 * @param packageName name of package to be allowlisted
11439 * @param context
11440 */
11441 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11442 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11443 sThermalMitigationAllowlistedPackages.add(packageName);
11444 }
11445
11446 /**
11447 * Used by shell commands to remove an authorized package name for thermal mitigation.
11448 * @param packageName name of package to remove from allowlist
11449 * @param context
11450 */
11451 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11452 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11453 sThermalMitigationAllowlistedPackages.remove(packageName);
11454 }
11455
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011456 /**
11457 * Thermal mitigation request to control functionalities at modem.
11458 *
11459 * @param subId the id of the subscription.
11460 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011461 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011462 *
11463 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11464 */
11465 @Override
11466 @ThermalMitigationResult
11467 public int sendThermalMitigationRequest(
11468 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011469 ThermalMitigationRequest thermalMitigationRequest,
11470 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011471 enforceModifyPermission();
11472
Jack Nudelman644b91a2021-03-12 14:09:48 -080011473 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11474 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11475 .contains(callingPackage)) {
11476 throw new SecurityException("Calling package must be configured in the device config. "
11477 + "calling package: " + callingPackage);
11478 }
11479
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011480 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11481 final long identity = Binder.clearCallingIdentity();
11482
11483 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11484 try {
11485 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11486 switch (thermalMitigationAction) {
11487 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11488 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011489 handleDataThrottlingRequest(subId,
11490 thermalMitigationRequest.getDataThrottlingRequest(),
11491 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011492 break;
11493 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11494 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11495 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11496 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11497 }
11498
11499 // Ensure that radio is on. If not able to power on due to phone being
11500 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011501 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011502 thermalMitigationResult =
11503 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11504 break;
11505 }
11506
11507 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011508 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011509 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11510 break;
11511 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11512 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11513 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11514 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11515 }
11516
11517 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11518 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011519 Phone phone = getPhone(subId);
11520 if (phone == null) {
11521 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011522 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011523 break;
11524 }
11525
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011526 TelephonyConnectionService service =
11527 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011528 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011529 Log.e(LOG_TAG, "An emergency call is pending");
11530 thermalMitigationResult =
11531 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11532 break;
11533 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011534 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011535 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011536 break;
11537 }
11538 } else {
11539 thermalMitigationResult =
11540 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11541 break;
11542 }
11543
11544 // Turn radio off. If not able to power off due to phone being unavailable,
11545 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011546 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011547 thermalMitigationResult =
11548 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11549 break;
11550 }
11551 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011552 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011553 break;
11554 default:
11555 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11556 + "not exist. Requested action: " + thermalMitigationAction);
11557 }
11558 } catch (IllegalArgumentException e) {
11559 throw e;
11560 } catch (Exception e) {
11561 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11562 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11563 } finally {
11564 Binder.restoreCallingIdentity(identity);
11565 }
11566
11567 if (DBG) {
11568 log("thermalMitigationRequest returning with thermalMitigationResult: "
11569 + thermalMitigationResult);
11570 }
11571
11572 return thermalMitigationResult;
11573 }
Hui Wang641e81c2020-10-12 12:14:23 -070011574
11575 /**
11576 * Set the GbaService Package Name that Telephony will bind to.
11577 *
11578 * @param subId The sim that the GbaService is associated with.
11579 * @param packageName The name of the package to be replaced with.
11580 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11581 */
11582 @Override
11583 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11584 enforceModifyPermission();
11585
11586 final long identity = Binder.clearCallingIdentity();
11587 try {
11588 return getGbaManager(subId).overrideServicePackage(packageName);
11589 } finally {
11590 Binder.restoreCallingIdentity(identity);
11591 }
11592 }
11593
11594 /**
11595 * Return the package name of the currently bound GbaService.
11596 *
11597 * @param subId The sim that the GbaService is associated with.
11598 * @return the package name of the GbaService configuration, null if GBA is not supported.
11599 */
11600 @Override
11601 public String getBoundGbaService(int subId) {
11602 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11603
11604 final long identity = Binder.clearCallingIdentity();
11605 try {
11606 return getGbaManager(subId).getServicePackage();
11607 } finally {
11608 Binder.restoreCallingIdentity(identity);
11609 }
11610 }
11611
11612 /**
11613 * Set the release time for telephony to unbind GbaService.
11614 *
11615 * @param subId The sim that the GbaService is associated with.
11616 * @param interval The release time to unbind GbaService by millisecond.
11617 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11618 */
11619 @Override
11620 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11621 enforceModifyPermission();
11622
11623 final long identity = Binder.clearCallingIdentity();
11624 try {
11625 return getGbaManager(subId).overrideReleaseTime(interval);
11626 } finally {
11627 Binder.restoreCallingIdentity(identity);
11628 }
11629 }
11630
11631 /**
11632 * Return the release time for telephony to unbind GbaService.
11633 *
11634 * @param subId The sim that the GbaService is associated with.
11635 * @return The release time to unbind GbaService by millisecond.
11636 */
11637 @Override
11638 public int getGbaReleaseTime(int subId) {
11639 enforceReadPrivilegedPermission("getGbaReleaseTime");
11640
11641 final long identity = Binder.clearCallingIdentity();
11642 try {
11643 return getGbaManager(subId).getReleaseTime();
11644 } finally {
11645 Binder.restoreCallingIdentity(identity);
11646 }
11647 }
11648
11649 private GbaManager getGbaManager(int subId) {
11650 GbaManager instance = GbaManager.getInstance(subId);
11651 if (instance == null) {
11652 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11653 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11654 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11655 }
11656 return instance;
11657 }
Hui Wang761a6682020-10-31 05:12:53 +000011658
11659 /**
11660 * indicate whether the device and the carrier can support
11661 * RCS VoLTE single registration.
11662 */
11663 @Override
11664 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011665 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11666 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11667 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11668 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011669
11670 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11671 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11672 }
11673
11674 final long identity = Binder.clearCallingIdentity();
11675 try {
11676 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11677 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011678 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11679 if (isCapable != null) {
11680 return isCapable;
11681 }
Hui Wang761a6682020-10-31 05:12:53 +000011682 }
Hui Wang67af90e2021-06-04 16:57:15 -070011683 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11684 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011685 } finally {
11686 Binder.restoreCallingIdentity(identity);
11687 }
11688 }
11689
11690 /**
11691 * Register RCS provisioning callback.
11692 */
11693 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011694 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011695 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011696 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011697 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011698 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11699 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011700
11701 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11702 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11703 }
11704 if (!isImsAvailableOnDevice()) {
11705 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11706 "IMS not available on device.");
11707 }
11708
11709 final long identity = Binder.clearCallingIdentity();
11710 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011711 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011712 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011713 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11714 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011715 }
Hui Wang761a6682020-10-31 05:12:53 +000011716 } finally {
11717 Binder.restoreCallingIdentity(identity);
11718 }
11719 }
11720
11721 /**
11722 * Unregister RCS provisioning callback.
11723 */
11724 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011725 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011726 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011727 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011728 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011729 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11730 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011731
11732 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11733 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11734 }
11735 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011736 // operation failed silently
11737 Rlog.w(LOG_TAG, "IMS not available on device.");
11738 return;
Hui Wang761a6682020-10-31 05:12:53 +000011739 }
11740
11741 final long identity = Binder.clearCallingIdentity();
11742 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011743 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011744 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011745 } finally {
11746 Binder.restoreCallingIdentity(identity);
11747 }
11748 }
11749
11750 /**
11751 * trigger RCS reconfiguration.
11752 */
11753 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011754 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11755 "triggerRcsReconfiguration",
11756 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011757
11758 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11759 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11760 }
11761 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011762 // ProvisioningManager can not handle ServiceSpecificException.
11763 // Throw the IllegalStateException and annotate ProvisioningManager.
11764 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000011765 }
11766
11767 final long identity = Binder.clearCallingIdentity();
11768 try {
11769 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11770 } finally {
11771 Binder.restoreCallingIdentity(identity);
11772 }
11773 }
11774
11775 /**
11776 * Provide the client configuration parameters of the RCS application.
11777 */
11778 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011779 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11780 "setRcsClientConfiguration",
11781 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011782
11783 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11784 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11785 }
11786 if (!isImsAvailableOnDevice()) {
11787 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11788 "IMS not available on device.");
11789 }
11790
11791 final long identity = Binder.clearCallingIdentity();
11792
11793 try {
11794 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11795 if (configBinder == null) {
11796 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011797 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11798 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011799 } else {
11800 configBinder.setRcsClientConfiguration(rcc);
11801 }
joonhunshin3e154242021-09-17 06:33:39 +000011802
11803 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11804 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011805 } catch (RemoteException e) {
11806 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011807 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11808 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011809 } finally {
11810 Binder.restoreCallingIdentity(identity);
11811 }
11812 }
11813
11814 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011815 * Enables or disables the test mode for RCS VoLTE single registration.
11816 */
11817 @Override
11818 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11819 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11820 "setRcsSingleRegistrationTestModeEnabled");
11821
11822 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11823 }
11824
11825 /**
11826 * Gets the test mode for RCS VoLTE single registration.
11827 */
11828 @Override
11829 public boolean getRcsSingleRegistrationTestModeEnabled() {
11830 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11831 "getRcsSingleRegistrationTestModeEnabled");
11832
11833 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11834 }
11835
11836 /**
Hui Wang761a6682020-10-31 05:12:53 +000011837 * Overrides the config of RCS VoLTE single registration enabled for the device.
11838 */
11839 @Override
11840 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11841 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11842 "setDeviceSingleRegistrationEnabledOverride");
11843 enforceModifyPermission();
11844
11845 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11846 : Boolean.parseBoolean(enabledStr);
11847 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011848 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011849 }
11850
11851 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011852 * Sends a device to device communication message. Only usable via shell.
11853 * @param message message to send.
11854 * @param value message value.
11855 */
11856 @Override
11857 public void sendDeviceToDeviceMessage(int message, int value) {
11858 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011859 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011860 enforceModifyPermission();
11861
11862 final long identity = Binder.clearCallingIdentity();
11863 try {
11864 TelephonyConnectionService service =
11865 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11866 if (service == null) {
11867 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11868 return;
11869 }
11870 service.sendTestDeviceToDeviceMessage(message, value);
11871 } finally {
11872 Binder.restoreCallingIdentity(identity);
11873 }
11874 }
11875
Tyler Gunnbabbda02021-02-10 11:05:02 -080011876 /**
11877 * Sets the specified device to device transport active.
11878 * @param transport The transport to set active.
11879 */
11880 @Override
11881 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11882 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11883 "setActiveDeviceToDeviceTransport");
11884 enforceModifyPermission();
11885
11886 final long identity = Binder.clearCallingIdentity();
11887 try {
11888 TelephonyConnectionService service =
11889 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11890 if (service == null) {
11891 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11892 return;
11893 }
11894 service.setActiveDeviceToDeviceTransport(transport);
11895 } finally {
11896 Binder.restoreCallingIdentity(identity);
11897 }
11898 }
Tyler Gunn92479152021-01-20 16:30:10 -080011899
Tyler Gunnd4339262021-05-03 14:46:49 -070011900 @Override
11901 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11902 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11903 "setDeviceToDeviceForceEnabled");
11904
11905 final long identity = Binder.clearCallingIdentity();
11906 try {
11907 Arrays.stream(PhoneFactory.getPhones()).forEach(
11908 p -> {
11909 Phone thePhone = p.getImsPhone();
11910 if (thePhone != null && thePhone instanceof ImsPhone) {
11911 ImsPhone imsPhone = (ImsPhone) thePhone;
11912 CallTracker tracker = imsPhone.getCallTracker();
11913 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11914 ImsPhoneCallTracker imsPhoneCallTracker =
11915 (ImsPhoneCallTracker) tracker;
11916 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11917 }
11918 }
11919 }
11920 );
11921 } finally {
11922 Binder.restoreCallingIdentity(identity);
11923 }
11924 }
11925
Tyler Gunn92479152021-01-20 16:30:10 -080011926 /**
Hui Wang761a6682020-10-31 05:12:53 +000011927 * Gets the config of RCS VoLTE single registration enabled for the device.
11928 */
11929 @Override
11930 public boolean getDeviceSingleRegistrationEnabled() {
11931 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11932 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11933 }
11934
11935 /**
11936 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11937 */
11938 @Override
11939 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11940 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11941 "setCarrierSingleRegistrationEnabledOverride");
11942 enforceModifyPermission();
11943
11944 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11945 : Boolean.parseBoolean(enabledStr);
11946 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11947 subId, enabled);
11948 }
11949
11950 /**
11951 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11952 */
11953 @Override
11954 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11955 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11956 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11957 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011958
11959 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011960 * Overrides the ims feature validation result
11961 */
11962 @Override
11963 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11964 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11965 "setImsFeatureValidationOverride");
11966
11967 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11968 : Boolean.parseBoolean(enabledStr);
11969 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11970 subId, enabled);
11971 }
11972
11973 /**
11974 * Gets the ims feature validation override value
11975 */
11976 @Override
11977 public boolean getImsFeatureValidationOverride(int subId) {
11978 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11979 "getImsFeatureValidationOverride");
11980 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11981 }
11982
11983 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011984 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11985 * their mobile plan.
11986 */
11987 @Override
11988 public String getMobileProvisioningUrl() {
11989 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11990 final long identity = Binder.clearCallingIdentity();
11991 try {
11992 return getDefaultPhone().getMobileProvisioningUrl();
11993 } finally {
11994 Binder.restoreCallingIdentity(identity);
11995 }
11996 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011997
James.cf Linbcdf8b32021-01-14 16:44:13 +080011998 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011999 * Get the EAB contact from the EAB database.
12000 */
12001 @Override
12002 public String getContactFromEab(String contact) {
12003 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12004 enforceModifyPermission();
12005 final long identity = Binder.clearCallingIdentity();
12006 try {
12007 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12008 } finally {
12009 Binder.restoreCallingIdentity(identity);
12010 }
12011 }
12012
12013 /**
Calvin Pana1434322021-07-01 19:27:01 +080012014 * Get the EAB capability from the EAB database.
12015 */
12016 @Override
12017 public String getCapabilityFromEab(String contact) {
12018 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12019 enforceModifyPermission();
12020 final long identity = Binder.clearCallingIdentity();
12021 try {
12022 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12023 } finally {
12024 Binder.restoreCallingIdentity(identity);
12025 }
12026 }
12027
12028 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012029 * Remove the EAB contacts from the EAB database.
12030 */
12031 @Override
12032 public int removeContactFromEab(int subId, String contacts) {
12033 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12034 enforceModifyPermission();
12035 final long identity = Binder.clearCallingIdentity();
12036 try {
12037 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12038 } finally {
12039 Binder.restoreCallingIdentity(identity);
12040 }
12041 }
12042
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012043 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012044 public boolean getDeviceUceEnabled() {
12045 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12046 final long identity = Binder.clearCallingIdentity();
12047 try {
12048 return mApp.getDeviceUceEnabled();
12049 } finally {
12050 Binder.restoreCallingIdentity(identity);
12051 }
12052 }
12053
12054 @Override
12055 public void setDeviceUceEnabled(boolean isEnabled) {
12056 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12057 final long identity = Binder.clearCallingIdentity();
12058 try {
12059 mApp.setDeviceUceEnabled(isEnabled);
12060 } finally {
12061 Binder.restoreCallingIdentity(identity);
12062 }
12063 }
12064
Brad Ebinger14d467f2021-02-12 06:18:28 +000012065 /**
12066 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12067 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12068 */
12069 // Used for SHELL command only right now.
12070 @Override
12071 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12072 List<String> featureTags) {
12073 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12074 "addUceRegistrationOverrideShell");
12075 final long identity = Binder.clearCallingIdentity();
12076 try {
12077 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12078 new ArraySet<>(featureTags));
12079 } catch (ImsException e) {
12080 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12081 } finally {
12082 Binder.restoreCallingIdentity(identity);
12083 }
12084 }
12085
12086 /**
12087 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12088 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12089 */
12090 // Used for SHELL command only right now.
12091 @Override
12092 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12093 List<String> featureTags) {
12094 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12095 "removeUceRegistrationOverrideShell");
12096 final long identity = Binder.clearCallingIdentity();
12097 try {
12098 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12099 new ArraySet<>(featureTags));
12100 } catch (ImsException e) {
12101 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12102 } finally {
12103 Binder.restoreCallingIdentity(identity);
12104 }
12105 }
12106
12107 /**
12108 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12109 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12110 */
12111 // Used for SHELL command only right now.
12112 @Override
12113 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12114 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12115 "clearUceRegistrationOverrideShell");
12116 final long identity = Binder.clearCallingIdentity();
12117 try {
12118 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12119 } catch (ImsException e) {
12120 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12121 } finally {
12122 Binder.restoreCallingIdentity(identity);
12123 }
12124 }
12125
12126 /**
12127 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12128 */
12129 // Used for SHELL command only right now.
12130 @Override
12131 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12132 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12133 "getLatestRcsContactUceCapabilityShell");
12134 final long identity = Binder.clearCallingIdentity();
12135 try {
12136 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12137 } catch (ImsException e) {
12138 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12139 } finally {
12140 Binder.restoreCallingIdentity(identity);
12141 }
12142 }
12143
12144 /**
12145 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12146 * device does not have an active PUBLISH.
12147 */
12148 // Used for SHELL command only right now.
12149 @Override
12150 public String getLastUcePidfXmlShell(int subId) {
12151 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12152 final long identity = Binder.clearCallingIdentity();
12153 try {
12154 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12155 } catch (ImsException e) {
12156 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12157 } finally {
12158 Binder.restoreCallingIdentity(identity);
12159 }
12160 }
12161
James.cf Line8713a42021-04-29 16:04:26 +080012162 /**
12163 * Remove UCE requests cannot be sent to the network status.
12164 */
12165 // Used for SHELL command only right now.
12166 @Override
12167 public boolean removeUceRequestDisallowedStatus(int subId) {
12168 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12169 final long identity = Binder.clearCallingIdentity();
12170 try {
12171 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12172 } catch (ImsException e) {
12173 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12174 } finally {
12175 Binder.restoreCallingIdentity(identity);
12176 }
12177 }
12178
James.cf Lin18bb9002021-05-25 01:37:38 +080012179 /**
12180 * Remove UCE requests cannot be sent to the network status.
12181 */
12182 // Used for SHELL command only.
12183 @Override
12184 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12185 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12186 final long identity = Binder.clearCallingIdentity();
12187 try {
12188 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12189 } catch (ImsException e) {
12190 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12191 } finally {
12192 Binder.restoreCallingIdentity(identity);
12193 }
12194 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012195
James.cf Lin4b784aa2021-01-31 03:25:15 +080012196 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012197 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12198 String callingPackage) {
12199 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12200 mApp, subId, "setSignalStrengthUpdateRequest");
12201
12202 final int callingUid = Binder.getCallingUid();
12203 // Verify that tha callingPackage belongs to the calling UID
12204 mApp.getSystemService(AppOpsManager.class)
12205 .checkPackage(callingUid, callingPackage);
12206
Rambo Wang3607f502021-02-01 21:51:40 -080012207 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012208
12209 final long identity = Binder.clearCallingIdentity();
12210 try {
12211 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12212 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12213
12214 if (result instanceof IllegalStateException) {
12215 throw (IllegalStateException) result;
12216 }
12217 } finally {
12218 Binder.restoreCallingIdentity(identity);
12219 }
12220 }
12221
12222 @Override
12223 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12224 String callingPackage) {
12225 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12226 mApp, subId, "clearSignalStrengthUpdateRequest");
12227
12228 final int callingUid = Binder.getCallingUid();
12229 // Verify that tha callingPackage belongs to the calling UID
12230 mApp.getSystemService(AppOpsManager.class)
12231 .checkPackage(callingUid, callingPackage);
12232
12233 final long identity = Binder.clearCallingIdentity();
12234 try {
12235 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12236 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12237
12238 if (result instanceof IllegalStateException) {
12239 throw (IllegalStateException) result;
12240 }
12241 } finally {
12242 Binder.restoreCallingIdentity(identity);
12243 }
12244 }
12245
Rambo Wang3607f502021-02-01 21:51:40 -080012246 private static void validateSignalStrengthUpdateRequest(Context context,
12247 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012248 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12249 // phone/system process do not have further restriction on request
12250 return;
12251 }
12252
12253 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012254 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012255 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012256 context.enforceCallingOrSelfPermission(
12257 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12258 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012259 }
12260
12261 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012262 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012263 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012264 || info.isEnabled()) {
12265 throw new IllegalArgumentException(
12266 "Only system can set hide fields in SignalThresholdInfo");
12267 }
12268
12269 // Thresholds length for each RAN need in range. This has been validated in
12270 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12271 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12272 final int[] thresholds = info.getThresholds();
12273 Objects.requireNonNull(thresholds);
12274 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12275 || thresholds.length
12276 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12277 throw new IllegalArgumentException(
12278 "thresholds length is out of range: " + thresholds.length);
12279 }
12280 }
12281 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012282
12283 /**
12284 * Gets the current phone capability.
12285 *
12286 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12287 * @return the PhoneCapability which describes the data connection capability of modem.
12288 * It's used to evaluate possible phone config change, for example from single
12289 * SIM device to multi-SIM device.
12290 */
12291 @Override
12292 public PhoneCapability getPhoneCapability() {
12293 enforceReadPrivilegedPermission("getPhoneCapability");
12294 final long identity = Binder.clearCallingIdentity();
12295 try {
12296 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12297 } finally {
12298 Binder.restoreCallingIdentity(identity);
12299 }
12300 }
Michele Berionne5e411512020-11-13 02:36:59 +000012301
12302 /**
12303 * Prepare TelephonyManager for an unattended reboot. The reboot is
12304 * required to be done shortly after the API is invoked.
12305 */
12306 @Override
12307 @TelephonyManager.PrepareUnattendedRebootResult
12308 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012309 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012310 enforceRebootPermission();
12311
12312 final long identity = Binder.clearCallingIdentity();
12313 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012314 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012315 } finally {
12316 Binder.restoreCallingIdentity(identity);
12317 }
12318 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012319
12320 /**
12321 * Request to get the current slicing configuration including URSP rules and
12322 * NSSAIs (configured, allowed and rejected).
12323 *
12324 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12325 */
12326 @Override
12327 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012328 TelephonyPermissions
12329 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12330 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012331
12332 final long identity = Binder.clearCallingIdentity();
12333 try {
12334 Phone phone = getDefaultPhone();
12335 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12336 } finally {
12337 Binder.restoreCallingIdentity(identity);
12338 }
12339 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012340
12341 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012342 * Check whether the given premium capability is available for purchase from the carrier.
12343 *
12344 * @param capability The premium capability to check.
12345 * @param subId The subId to check the premium capability for.
12346 *
12347 * @return Whether the given premium capability is available to purchase.
12348 */
12349 @Override
12350 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12351 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12352 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12353 log("Premium capability "
12354 + TelephonyManager.convertPremiumCapabilityToString(capability)
12355 + " is not available for purchase due to missing permissions.");
12356 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12357 + "permission READ_BASIC_PHONE_STATE.");
12358 }
12359
12360 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012361 if (phone == null) {
12362 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12363 return false;
12364 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012365 final long identity = Binder.clearCallingIdentity();
12366 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070012367 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012368 .isPremiumCapabilityAvailableForPurchase(capability);
12369 } finally {
12370 Binder.restoreCallingIdentity(identity);
12371 }
12372 }
12373
12374 /**
12375 * Purchase the given premium capability from the carrier.
12376 *
12377 * @param capability The premium capability to purchase.
12378 * @param callback The result of the purchase request.
12379 * @param subId The subId to purchase the premium capability for.
12380 */
12381 @Override
12382 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12383 log("purchasePremiumCapability: capability="
12384 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12385 + getCurrentPackageName());
12386
12387 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12388 mApp, "purchasePremiumCapability")) {
12389 log("purchasePremiumCapability "
12390 + TelephonyManager.convertPremiumCapabilityToString(capability)
12391 + " failed due to missing permissions.");
12392 throw new SecurityException("purchasePremiumCapability requires permission "
12393 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012394 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12395 mApp, "purchasePremiumCapability")) {
12396 log("purchasePremiumCapability "
12397 + TelephonyManager.convertPremiumCapabilityToString(capability)
12398 + " failed due to missing permissions.");
12399 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012400 }
12401
12402 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012403 if (phone == null) {
12404 try {
12405 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12406 callback.accept(result);
12407 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12408 } catch (RemoteException e) {
12409 String logStr = "Purchase premium capability "
12410 + TelephonyManager.convertPremiumCapabilityToString(capability)
12411 + " failed due to RemoteException handling null phone: " + e;
12412 if (DBG) log(logStr);
12413 AnomalyReporter.reportAnomaly(
12414 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12415 }
12416 return;
12417 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012418
12419 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012420 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012421 callingProcess = mApp.getPackageManager().getApplicationInfo(
12422 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012423 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012424 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012425 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012426
12427 boolean isVisible = false;
12428 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12429 if (am != null) {
12430 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12431 if (processes != null) {
12432 for (ActivityManager.RunningAppProcessInfo process : processes) {
12433 log("purchasePremiumCapability: process " + process.processName
12434 + "has importance " + process.importance);
12435 if (process.processName.equals(callingProcess) && process.importance
12436 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12437 isVisible = true;
12438 break;
12439 }
12440 }
12441 }
12442 }
12443
12444 if (!isVisible) {
12445 try {
12446 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12447 callback.accept(result);
12448 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12449 } catch (RemoteException e) {
12450 String logStr = "Purchase premium capability "
12451 + TelephonyManager.convertPremiumCapabilityToString(capability)
12452 + " failed due to RemoteException handling background application: " + e;
12453 if (DBG) log(logStr);
12454 AnomalyReporter.reportAnomaly(
12455 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12456 }
12457 return;
12458 }
12459
Sarah Chin71b3a852022-09-28 15:54:19 -070012460 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012461 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012462 }
12463
12464 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012465 * Register an IMS connection state callback
12466 */
12467 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012468 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12469 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012470 if (feature == ImsFeature.FEATURE_MMTEL) {
12471 // ImsMmTelManager
12472 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12473 TelephonyPermissions
12474 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12475 mApp, subId, "registerImsStateCallback");
12476 } else if (feature == ImsFeature.FEATURE_RCS) {
12477 // ImsRcsManager or SipDelegateManager
12478 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12479 Binder.getCallingUid(), "registerImsStateCallback",
12480 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12481 Manifest.permission.READ_PRECISE_PHONE_STATE,
12482 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12483 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12484 }
12485
12486 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12487 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12488 "IMS not available on device.");
12489 }
12490
12491 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12492 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12493 }
12494
12495 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12496 if (controller == null) {
12497 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12498 "IMS not available on device.");
12499 }
12500
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012501 if (callingPackage == null) {
12502 callingPackage = getCurrentPackageName();
12503 }
12504
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012505 final long token = Binder.clearCallingIdentity();
12506 try {
12507 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012508 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012509 } catch (ImsException e) {
12510 throw new ServiceSpecificException(e.getCode());
12511 } finally {
12512 Binder.restoreCallingIdentity(token);
12513 }
12514 }
12515
12516 /**
12517 * Unregister an IMS connection state callback
12518 */
12519 @Override
12520 public void unregisterImsStateCallback(IImsStateCallback cb) {
12521 final long token = Binder.clearCallingIdentity();
12522 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12523 if (controller == null) {
12524 return;
12525 }
12526 try {
12527 controller.unregisterImsStateCallback(cb);
12528 } finally {
12529 Binder.restoreCallingIdentity(token);
12530 }
12531 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012532
12533 /**
12534 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12535 *
12536 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
12537 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
12538 * SecurityException.
12539 * If there is current registered network this value will be same as the registered cell
12540 * identity. If the device goes out of service the previous cell identity is cached and
12541 * will be returned. If the cache age of the Cell identity is more than 24 hours
12542 * it will be cleared and null will be returned.
12543 *
12544 */
12545 @Override
12546 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12547 String callingFeatureId) {
12548 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12549 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12550 LocationAccessPolicy.checkLocationPermission(mApp,
12551 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12552 .setCallingPackage(callingPackage)
12553 .setCallingFeatureId(callingFeatureId)
12554 .setCallingPid(Binder.getCallingPid())
12555 .setCallingUid(Binder.getCallingUid())
12556 .setMethod("getLastKnownCellIdentity")
12557 .setLogAsInfo(true)
12558 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12559 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12560 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12561 .build());
12562
12563 boolean hasFinePermission =
12564 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12565 if (!hasFinePermission
12566 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12567 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012568 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012569 }
12570
12571 final long identity = Binder.clearCallingIdentity();
12572 try {
12573 Phone phone = getPhone(subId);
12574 if (phone == null) return null;
12575 ServiceStateTracker sst = phone.getServiceStateTracker();
12576 if (sst == null) return null;
12577 return sst.getLastKnownCellIdentity();
12578 } finally {
12579 Binder.restoreCallingIdentity(identity);
12580 }
12581 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012582
jimsun3b9ccac2021-10-26 15:01:23 +080012583 /**
12584 * Sets the modem service class Name that Telephony will bind to.
12585 *
12586 * @param serviceName The class name of the modem service.
12587 * @return true if the operation is succeed, otherwise false.
12588 */
12589 public boolean setModemService(String serviceName) {
12590 Log.d(LOG_TAG, "setModemService - " + serviceName);
12591 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012593 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12594 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012595 return mPhoneConfigurationManager.setModemService(serviceName);
12596 }
12597
12598 /**
12599 * Return the class name of the currently bounded modem service.
12600 *
12601 * @return the class name of the modem service.
12602 */
12603 public String getModemService() {
12604 String result;
12605 Log.d(LOG_TAG, "getModemService");
12606 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12607 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012608 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012609 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12610 "getModemService");
12611 result = mPhoneConfigurationManager.getModemService();
12612 Log.d(LOG_TAG, "result = " + result);
12613 return result;
12614 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012615
12616 @Override
12617 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12618 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12619 mApp.enforceCallingOrSelfPermission(
12620 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12621 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12622
12623 final long identity = Binder.clearCallingIdentity();
12624 try {
12625 Phone phone = getPhone(subId);
12626 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012627 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12628 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012629 phone.setVoiceServiceStateOverride(hasService);
12630 } finally {
12631 Binder.restoreCallingIdentity(identity);
12632 }
12633 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012634
12635 /**
12636 * set removable eSIM as default eUICC.
12637 *
12638 * @hide
12639 */
12640 @Override
12641 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12642 enforceModifyPermission();
12643 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12644
12645 final long identity = Binder.clearCallingIdentity();
12646 try {
12647 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12648 } finally {
12649 Binder.restoreCallingIdentity(identity);
12650 }
12651 }
12652
12653 /**
12654 * Returns whether the removable eSIM is default eUICC or not.
12655 *
12656 * @hide
12657 */
12658 @Override
12659 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12660 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12661 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12662
12663 final long identity = Binder.clearCallingIdentity();
12664 try {
12665 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12666 } finally {
12667 Binder.restoreCallingIdentity(identity);
12668 }
12669 }
12670
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012671 /**
12672 * Get the component name of the default app to direct respond-via-message intent for the
12673 * user associated with this subscription, update the cache if there is no respond-via-message
12674 * application currently configured for this user.
12675 * @return component name of the app and class to direct Respond Via Message intent to, or
12676 * {@code null} if the functionality is not supported.
12677 * @hide
12678 */
12679 @Override
12680 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12681 boolean updateIfNeeded) {
12682 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012683
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012684 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12685
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012686 UserHandle userHandle = null;
12687 final long identity = Binder.clearCallingIdentity();
12688 try {
12689 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12690 } finally {
12691 Binder.restoreCallingIdentity(identity);
12692 }
12693 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12694 updateIfNeeded, userHandle);
12695 }
Jack Yuf5badd92022-12-08 00:50:53 -080012696
12697 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012698 * Set whether the device is able to connect with null ciphering or integrity
12699 * algorithms. This is a global setting and will apply to all active subscriptions
12700 * and all new subscriptions after this.
12701 *
12702 * @param enabled when true, null cipher and integrity algorithms are allowed.
12703 * @hide
12704 */
12705 @Override
12706 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12707 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12708 enforceModifyPermission();
12709 checkForNullCipherAndIntegritySupport();
12710
12711 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12712 // for listening to these preference changes and applying them immediately.
12713 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12714 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12715 editor.apply();
12716
12717 for (Phone phone: PhoneFactory.getPhones()) {
12718 phone.handleNullCipherEnabledChange();
12719 }
12720 }
12721
12722
12723 /**
12724 * Get whether the device is able to connect with null ciphering or integrity
12725 * algorithms. Note that this retrieves the phone-global preference and not
12726 * the state of the radio.
12727 *
12728 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12729 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12730 * version for this feature.
12731 * @hide
12732 */
12733 @Override
12734 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12735 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12736 enforceReadPermission();
12737 checkForNullCipherAndIntegritySupport();
12738 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12739 }
12740
12741 private void checkForNullCipherAndIntegritySupport() {
12742 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12743 throw new UnsupportedOperationException(
12744 "Null cipher and integrity operations require HAL 2.1 or above");
12745 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012746 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12747 throw new UnsupportedOperationException(
12748 "Null cipher and integrity operations unsupported by modem");
12749 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012750 }
12751
12752 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012753 * Get the SIM state for the slot index.
12754 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12755 *
12756 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12757 */
12758 @Override
12759 @SimState
12760 public int getSimStateForSlotIndex(int slotIndex) {
12761 IccCardConstants.State simState;
12762 if (slotIndex < 0) {
12763 simState = IccCardConstants.State.UNKNOWN;
12764 } else {
12765 Phone phone = null;
12766 try {
12767 phone = PhoneFactory.getPhone(slotIndex);
12768 } catch (IllegalStateException e) {
12769 // ignore
12770 }
12771 if (phone == null) {
12772 simState = IccCardConstants.State.UNKNOWN;
12773 } else {
12774 IccCard icc = phone.getIccCard();
12775 if (icc == null) {
12776 simState = IccCardConstants.State.UNKNOWN;
12777 } else {
12778 simState = icc.getState();
12779 }
12780 }
12781 }
12782 return simState.ordinal();
12783 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012784
12785 /**
12786 * Get current cell broadcast ranges.
12787 */
12788 @Override
12789 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12790 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12791 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12792 "getCellBroadcastIdRanges");
12793 final long identity = Binder.clearCallingIdentity();
12794 try {
12795 return getPhone(subId).getCellBroadcastIdRanges();
12796 } finally {
12797 Binder.restoreCallingIdentity(identity);
12798 }
12799 }
12800
12801 /**
12802 * Set reception of cell broadcast messages with the list of the given ranges
12803 *
12804 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12805 */
12806 @Override
12807 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12808 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12809 @Nullable IIntegerConsumer callback) {
12810 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12811 "setCellBroadcastIdRanges");
12812 final long identity = Binder.clearCallingIdentity();
12813 try {
12814 Phone phone = getPhoneFromSubId(subId);
12815 if (DBG) {
12816 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12817 }
12818 phone.setCellBroadcastIdRanges(ranges, result -> {
12819 if (callback != null) {
12820 try {
12821 callback.accept(result);
12822 } catch (RemoteException e) {
12823 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12824 }
12825 }
12826 });
12827 } finally {
12828 Binder.restoreCallingIdentity(identity);
12829 }
12830 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012831
12832 /**
12833 * Returns whether the device supports the domain selection service.
12834 *
12835 * @return {@code true} if the device supports the domain selection service.
12836 */
12837 @Override
12838 public boolean isDomainSelectionSupported() {
12839 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12840 "isDomainSelectionSupported");
12841
12842 final long identity = Binder.clearCallingIdentity();
12843 try {
12844 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12845 } finally {
12846 Binder.restoreCallingIdentity(identity);
12847 }
12848 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012849
12850 /**
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012851 * Request to enable or disable the satellite modem. If the satellite modem is enabled, this
12852 * will also disable the cellular modem, and if the satellite modem is disabled, this will also
12853 * re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012854 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012855 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012856 * @param enable {@code true} to enable the satellite modem and {@code false} to disable.
12857 * @param callback The callback to get the error code of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012858 *
12859 * @throws SecurityException if the caller doesn't have the required permission.
12860 */
12861 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012862 public void requestSatelliteEnabled(
12863 int subId, boolean enable, @NonNull IIntegerConsumer callback) {
12864 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012865 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012866 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012867 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12868 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012869 }
Sarah Chin503828c2023-02-01 23:54:20 -080012870
12871 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012872 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012873 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
12874 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012875 }
12876
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012877 Phone phone = getPhoneOrDefault(validSubId, "requestSatelliteEnabled");
Sarah Chin503828c2023-02-01 23:54:20 -080012878 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012879 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
12880 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012881 }
12882
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012883 Pair<Boolean, Consumer<Integer>> arg = new Pair<>(enable, result);
12884 sendRequestAsync(CMD_SET_SATELLITE_ENABLED, arg, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080012885 }
12886
12887 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012888 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012889 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012890 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012891 * @param result The result receiver that returns whether the satellite modem is enabled
12892 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012893 *
12894 * @throws SecurityException if the caller doesn't have the required permission.
12895 */
12896 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012897 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12898 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012899 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012900 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
12901 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012902 }
Sarah Chin503828c2023-02-01 23:54:20 -080012903
12904 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012905 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012906 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
12907 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012908 }
12909
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012910 Phone phone = getPhoneOrDefault(validSubId, "requestIsSatelliteEnabled");
Sarah Chin503828c2023-02-01 23:54:20 -080012911 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012912 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12913 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012914 }
12915
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012916 sendRequest(CMD_IS_SATELLITE_ENABLED, result, subId);
Sarah Chin503828c2023-02-01 23:54:20 -080012917 }
12918
12919 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012920 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012921 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012922 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012923 * @param result The result receiver that returns whether the satellite service is supported on
12924 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012925 */
12926 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012927 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012928 synchronized (mIsSatelliteSupportedLock) {
12929 if (mIsSatelliteSupported != null) {
12930 /* We have already successfully queried the satellite modem. */
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012931 Bundle bundle = new Bundle();
12932 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, mIsSatelliteSupported);
12933 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, bundle);
12934 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012935 }
12936 }
Sarah Chin503828c2023-02-01 23:54:20 -080012937
12938 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012939 Phone phone = getPhoneOrDefault(validSubId, "requestIsSatelliteSupported");
Sarah Chin503828c2023-02-01 23:54:20 -080012940 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012941 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12942 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012943 }
12944
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012945 sendRequestAsync(CMD_IS_SATELLITE_SUPPORTED, result, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080012946 }
12947
12948 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012949 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012950 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012951 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012952 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12953 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012954 *
12955 * @throws SecurityException if the caller doesn't have required permission.
12956 */
12957 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012958 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12959 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012960 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012961 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
12962 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012963 }
Sarah Chin503828c2023-02-01 23:54:20 -080012964
12965 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012966 Phone phone = getPhoneOrDefault(validSubId, "requestSatelliteCapabilities");
Sarah Chin503828c2023-02-01 23:54:20 -080012967 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012968 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12969 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012970 }
12971
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012972 sendRequestAsync(CMD_GET_SATELLITE_CAPABILITIES, result, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080012973 }
12974
12975 /**
Sarah Chineccfbd12023-01-20 19:00:35 -080012976 * Start receiving satellite position updates.
12977 * This can be called by the pointing UI when the user starts pointing to the satellite.
12978 * Modem should continue to report the pointing input as the device or satellite moves.
12979 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012980 * @param subId The subId of the subscription to start satellite position updates for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012981 * @param errorCallback The callback to get the error code of the request.
Sarah Chineccfbd12023-01-20 19:00:35 -080012982 * @param callback The callback to notify of changes in satellite position.
Sarah Chin503828c2023-02-01 23:54:20 -080012983 *
12984 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012985 */
12986 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012987 public void startSatellitePositionUpdates(int subId, @NonNull IIntegerConsumer errorCallback,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012988 @NonNull ISatellitePositionUpdateCallback callback) {
Sarah Chinf75afa72023-02-01 01:32:19 -080012989 enforceSatelliteCommunicationPermission("startSatellitePositionUpdates");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012990 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012991 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012992 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12993 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012994 }
Sarah Chinf75afa72023-02-01 01:32:19 -080012995
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012996 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012997 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012998 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
12999 return;
Sarah Chinf75afa72023-02-01 01:32:19 -080013000 }
13001
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013002 Phone phone = getPhoneOrDefault(validSubId, "startSatellitePositionUpdates");
Sarah Chineccfbd12023-01-20 19:00:35 -080013003 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013004 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
13005 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080013006 }
13007
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013008 SatellitePositionUpdateHandler handler =
13009 mSatellitePositionUpdateHandlers.get(validSubId);
13010 if (handler != null) {
13011 handler.addListener(callback);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013012 return;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013013 } else {
13014 handler = new SatellitePositionUpdateHandler(Looper.getMainLooper());
13015 handler.addListener(callback);
13016 mSatellitePositionUpdateHandlers.put(validSubId, handler);
13017 phone.registerForSatellitePointingInfoChanged(handler,
13018 SatellitePositionUpdateHandler.EVENT_POSITION_UPDATE, null);
13019 phone.registerForSatelliteDatagramsDelivered(handler,
13020 SatellitePositionUpdateHandler.EVENT_MESSAGE_TRANSFER_STATE_UPDATE,
13021 null);
Sarah Chineccfbd12023-01-20 19:00:35 -080013022 }
13023
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013024 sendRequestAsync(CMD_START_SATELLITE_POSITION_UPDATES,
13025 new SatellitePositionUpdateArgument(result, callback, validSubId), phone, null);
Sarah Chineccfbd12023-01-20 19:00:35 -080013026 }
13027
13028 /**
13029 * Stop receiving satellite position updates.
13030 * This can be called by the pointing UI when the user stops pointing to the satellite.
13031 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013032 * @param subId The subId of the subscription to stop satellite position updates for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013033 * @param errorCallback The callback to get the error code of the request.
13034 * @param callback The callback that was passed to {@link
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013035 * #startSatellitePositionUpdates(int, IIntegerConsumer, ISatellitePositionUpdateCallback)}
Sarah Chin503828c2023-02-01 23:54:20 -080013036 *
13037 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013038 */
13039 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013040 public void stopSatellitePositionUpdates(int subId, @NonNull IIntegerConsumer errorCallback,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013041 @NonNull ISatellitePositionUpdateCallback callback) {
Sarah Chinf75afa72023-02-01 01:32:19 -080013042 enforceSatelliteCommunicationPermission("stopSatellitePositionUpdates");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013043 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013044 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013045 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
13046 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013047 }
Sarah Chinf75afa72023-02-01 01:32:19 -080013048
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013049 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013050 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013051 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
13052 return;
Sarah Chinf75afa72023-02-01 01:32:19 -080013053 }
13054
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013055 Phone phone = getPhoneOrDefault(validSubId, "stopSatellitePositionUpdates");
Sarah Chineccfbd12023-01-20 19:00:35 -080013056 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013057 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
13058 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080013059 }
13060
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013061 SatellitePositionUpdateHandler handler = mSatellitePositionUpdateHandlers.get(validSubId);
13062 if (handler != null) {
13063 handler.removeListener(callback);
13064
13065 if (handler.hasListeners()) {
13066 /**
13067 * TODO (b/269194948): If the calling apps crash, the handler will always have some
13068 * listener. That is, we will not request modem to stop position update and
13069 * cleaning our resources. We need to monitor the calling apps and clean up the
13070 * resources when the apps die. We need to this for other satellite callbacks
13071 * as well.
13072 */
13073 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
13074 return;
13075 }
13076
13077 mSatellitePositionUpdateHandlers.remove(validSubId);
Sarah Chineccfbd12023-01-20 19:00:35 -080013078 phone.unregisterForSatellitePointingInfoChanged(handler);
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013079 phone.unregisterForSatelliteDatagramsDelivered(handler);
Sarah Chineccfbd12023-01-20 19:00:35 -080013080 }
13081
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013082 /**
13083 * Even if handler is null - which means there are not any listeners, the command to stop
13084 * satellite position updates sent to the modem might have failed. The callers might want to
13085 * retry sending the command. Thus, we always need to send this command to the modem.
13086 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013087 sendRequestAsync(CMD_STOP_SATELLITE_POSITION_UPDATES, result, phone, null);
Sarah Chineccfbd12023-01-20 19:00:35 -080013088 }
13089
13090 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013091 * Request to get the maximum number of characters per text message on satellite.
13092 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013093 * @param subId The subId of the subscription to get the maximum number of characters for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013094 * @param result The result receiver that returns the maximum number of characters per text
13095 * message on satellite if the request is successful or an error code
13096 * if the request failed.
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013097 *
13098 * @throws SecurityException if the caller doesn't have the required permission.
13099 */
13100 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013101 public void requestMaxCharactersPerSatelliteTextMessage(int subId,
13102 @NonNull ResultReceiver result) {
13103 enforceSatelliteCommunicationPermission("requestMaxCharactersPerSatelliteTextMessage");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013104 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013105 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
13106 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013107 }
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013108
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013109 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013110 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013111 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
13112 return;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013113 }
13114
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013115 Phone phone = getPhoneOrDefault(validSubId, "requestMaxCharactersPerSatelliteTextMessage");
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013116 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013117 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
13118 return;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013119 }
13120
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013121 sendRequestAsync(CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG, result, phone, null);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013122 }
13123
13124 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013125 * Register the subscription with a satellite provider.
13126 * This is needed to register the subscription if the provider allows dynamic registration.
13127 *
13128 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013129 * @param token The token to be used as a unique identifier for provisioning with satellite
13130 * gateway.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013131 * @param callback The callback to get the error code of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013132 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013133 * @return The signal transport used by the caller to cancel the provision request,
13134 * or {@code null} if the request failed.
13135 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013136 * @throws SecurityException if the caller doesn't have the required permission.
13137 */
13138 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013139 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
13140 @NonNull String token, @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013141 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013142 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013143 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013144 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013145 return null;
13146 }
13147
13148 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013149 Phone phone = getPhoneOrDefault(validSubId, "provisionSatelliteService");
13150 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013151 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013152 return null;
13153 }
13154
13155 if (mSatelliteProvisionCallbacks.containsKey(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013156 result.accept(SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013157 return null;
13158 }
13159
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013160 if (isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013161 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013162 return null;
13163 }
13164
13165 sendRequestAsync(CMD_PROVISION_SATELLITE_SERVICE,
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013166 new ProvisionSatelliteServiceArgument(token, result, validSubId), phone, null);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013167
13168 ICancellationSignal cancelTransport = CancellationSignal.createTransport();
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013169 CancellationSignal.fromTransport(cancelTransport).setOnCancelListener(() -> {
13170 sendRequestAsync(CMD_DEPROVISION_SATELLITE_SERVICE,
13171 new ProvisionSatelliteServiceArgument(token, null, validSubId),
13172 phone, null);
13173 });
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013174 return cancelTransport;
13175 }
13176
13177 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013178 * Unregister the device/subscription with the satellite provider.
13179 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013180 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013181 * should report as deprovisioned.
13182 *
13183 * @param subId The subId of the subscription to be deprovisioned.
13184 * @param token The token of the device/subscription to be deprovisioned.
13185 * @param callback The callback to get the error code of the request.
13186 *
13187 * @throws SecurityException if the caller doesn't have the required permission.
13188 */
13189 @Override
13190 public void deprovisionSatelliteService(int subId,
13191 @NonNull String token, @NonNull IIntegerConsumer callback) {
13192 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
13193 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
13194 if (!isSatelliteSupported()) {
13195 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
13196 return;
13197 }
13198
13199 final int validSubId = getValidSatelliteSubId(subId);
13200 if (!isSatelliteProvisioned(validSubId)) {
13201 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
13202 return;
13203 }
13204
13205 Phone phone = getPhoneOrDefault(validSubId, "deprovisionSatelliteService");
13206 if (phone == null) {
13207 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
13208 return;
13209 }
13210
13211 sendRequestAsync(CMD_DEPROVISION_SATELLITE_SERVICE,
13212 new ProvisionSatelliteServiceArgument(token, result, validSubId), phone, null);
13213 }
13214
13215 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013216 * Register for the satellite provision state change.
13217 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013218 * @param subId The subId of the subscription to register for provision state changes.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013219 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013220 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013221 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
13222 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013223 * @throws SecurityException if the caller doesn't have the required permission.
13224 */
13225 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080013226 @SatelliteManager.SatelliteError public int registerForSatelliteProvisionStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013227 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013228 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Sarah Chindf715ec2023-02-13 13:46:24 -080013229 return registerForSatelliteProvisionStateChangedInternal(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013230 }
13231
13232 /**
13233 * Unregister for the satellite provision state change.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013234 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013235 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013236 * @param subId The subId of the subscription to unregister for provision state changes.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013237 * @param callback The callback that was passed to
13238 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013239 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013240 * @throws SecurityException if the caller doesn't have the required permission.
13241 */
13242 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013243 public void unregisterForSatelliteProvisionStateChanged(
13244 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013245 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
13246
13247 final int validSubId = getValidSatelliteSubId(subId);
13248 SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler =
13249 mSatelliteProvisionStateChangedHandlers.get(validSubId);
13250 if (satelliteProvisionStateChangedHandler != null) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013251 satelliteProvisionStateChangedHandler.removeListener(callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013252 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013253 }
13254
13255 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013256 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013257 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013258 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013259 * @param result The result receiver that returns whether the device is provisioned with a
13260 * satellite provider if the request is successful or an error code if the
13261 * request failed.
13262 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013263 * @throws SecurityException if the caller doesn't have the required permission.
13264 */
13265 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013266 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13267 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013268 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013269 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
13270 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013271 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013272
13273 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013274 Bundle bundle = new Bundle();
13275 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_PROVISIONED,
13276 isSatelliteProvisioned(validSubId));
13277 result.send(SatelliteManager.SATELLITE_ERROR_NONE, bundle);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013278 }
13279
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013280 /**
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013281 * Register for listening to satellite modem state changes.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013282 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013283 * @param subId The subId of the subscription to register for satellite modem state changes.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013284 * @param callback The callback to handle the satellite modem state change event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013285 *
13286 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
13287 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013288 * @throws SecurityException if the caller doesn't have the required permission.
13289 */
13290 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080013291 @SatelliteManager.SatelliteError public int registerForSatelliteModemStateChange(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013292 @NonNull ISatelliteStateCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013293 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChange");
13294
13295 final int validSubId = getValidSatelliteSubId(subId);
13296 Phone phone = getPhoneOrDefault(
13297 validSubId, "registerForSatelliteModemStateChange");
13298 if (phone == null) {
13299 return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
13300 }
13301
13302 SatelliteStateListenerHandler satelliteStateListenerHandler =
13303 mSatelliteStateListenerHandlers.get(validSubId);
13304 if (satelliteStateListenerHandler == null) {
13305 satelliteStateListenerHandler = new SatelliteStateListenerHandler(
13306 Looper.getMainLooper(), validSubId);
13307 phone.registerForSatelliteModemStateChange(satelliteStateListenerHandler,
13308 SatelliteStateListenerHandler.EVENT_SATELLITE_MODEM_STATE_CHANGE, null);
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013309 phone.registerForPendingDatagramCount(satelliteStateListenerHandler,
13310 SatelliteStateListenerHandler.EVENT_PENDING_DATAGRAM_COUNT, null);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013311 }
13312
13313 satelliteStateListenerHandler.addListener(callback);
13314 mSatelliteStateListenerHandlers.put(validSubId, satelliteStateListenerHandler);
13315 return SatelliteManager.SATELLITE_ERROR_NONE;
13316 }
13317
13318 /**
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013319 * Unregister from listening to satellite modem state changes.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013320 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013321 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013322 * @param subId The subId of the subscription to unregister for satellite modem state changes.
13323 * @param callback The callback that was passed to
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013324 * {@link #registerForSatelliteModemStateChange(int, ISatelliteStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013325 *
13326 * @throws SecurityException if the caller doesn't have the required permission.
13327 */
13328 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013329 public void unregisterForSatelliteModemStateChange(int subId,
13330 @NonNull ISatelliteStateCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013331 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChange");
13332
13333 final int validSubId = getValidSatelliteSubId(subId);
13334 SatelliteStateListenerHandler satelliteStateListenerHandler =
13335 mSatelliteStateListenerHandlers.get(validSubId);
13336 if (satelliteStateListenerHandler != null) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013337 satelliteStateListenerHandler.removeListener(callback);
13338 if (!satelliteStateListenerHandler.hasListeners()) {
13339 mSatelliteStateListenerHandlers.remove(validSubId);
13340
13341 Phone phone = getPhoneOrDefault(
13342 validSubId, "unregisterForSatelliteModemStateChange");
13343 if (phone == null) {
13344 loge("unregisterForSatelliteModemStateChange: phone is null");
13345 } else {
13346 phone.unregisterForSatelliteModemStateChange(satelliteStateListenerHandler);
13347 phone.unregisterForPendingDatagramCount(satelliteStateListenerHandler);
13348 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013349 }
13350 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013351 }
13352
13353 /**
13354 * Register to receive incoming datagrams over satellite.
13355 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013356 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013357 * @param datagramType datagram type indicating whether the datagram is of type
13358 * SOS_SMS or LOCATION_SHARING.
Sarah Chindf715ec2023-02-13 13:46:24 -080013359 * @param callback The callback to handle incoming datagrams over satellite.
13360 *
13361 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
13362 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013363 * @throws SecurityException if the caller doesn't have the required permission.
13364 */
13365 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080013366 @SatelliteManager.SatelliteError public int registerForSatelliteDatagram(int subId,
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013367 @SatelliteManager.DatagramType int datagramType,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013368 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013369 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013370 if (!isSatelliteSupported()) {
13371 return SatelliteManager.SATELLITE_NOT_SUPPORTED;
13372 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013373
13374 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chindf715ec2023-02-13 13:46:24 -080013375 Phone phone = getPhoneOrDefault(validSubId, "registerForSatelliteDatagram");
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013376 if (phone == null) {
13377 return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
13378 }
13379
13380 SatelliteDatagramListenerHandler satelliteDatagramListenerHandler =
13381 mSatelliteDatagramListenerHandlers.get(validSubId);
13382 if (satelliteDatagramListenerHandler == null) {
13383 satelliteDatagramListenerHandler = new SatelliteDatagramListenerHandler(
13384 Looper.getMainLooper(), validSubId);
13385 phone.registerForNewSatelliteDatagram(satelliteDatagramListenerHandler,
13386 SatelliteDatagramListenerHandler.EVENT_SATELLITE_DATAGRAMS_RECEIVED, null);
13387 }
13388
13389 satelliteDatagramListenerHandler.addListener(callback);
13390 mSatelliteDatagramListenerHandlers.put(validSubId, satelliteDatagramListenerHandler);
13391 return SatelliteManager.SATELLITE_ERROR_NONE;
13392 }
13393
13394 /**
13395 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013396 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013397 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013398 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13399 * @param callback The callback that was passed to
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013400 * {@link #registerForSatelliteDatagram(int, int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013401 *
13402 * @throws SecurityException if the caller doesn't have the required permission.
13403 */
13404 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013405 public void unregisterForSatelliteDatagram(int subId,
13406 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013407 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
13408
13409 final int validSubId = getValidSatelliteSubId(subId);
13410 SatelliteDatagramListenerHandler satelliteDatagramListenerHandler =
13411 mSatelliteDatagramListenerHandlers.get(validSubId);
13412 if (satelliteDatagramListenerHandler != null) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013413 satelliteDatagramListenerHandler.removeListener(callback);
13414
13415 if (!satelliteDatagramListenerHandler.hasListeners()) {
13416 mSatelliteDatagramListenerHandlers.remove(validSubId);
13417
13418 Phone phone = getPhoneOrDefault(validSubId, "unregisterForSatelliteDatagram");
13419 if (phone == null) {
13420 loge("unregisterForSatelliteDatagram: phone is null");
13421 } else {
13422 phone.unregisterForNewSatelliteDatagram(satelliteDatagramListenerHandler);
13423 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013424 }
13425 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013426 }
13427
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013428 /**
13429 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013430 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013431 * This method requests modem to check if there are any pending datagrams to be received over
13432 * satellite. If there are any incoming datagrams, they will be received via
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013433 * {@link SatelliteDatagramCallback#onSatelliteDatagrams(SatelliteDatagram[])}
Sarah Chindf715ec2023-02-13 13:46:24 -080013434 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013435 * @param subId The subId of the subscription used for receiving datagrams.
13436 * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013437 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013438 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013439 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013440 @Override
13441 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013442 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013443 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013444
13445 final int validSubId = getValidSatelliteSubId(subId);
13446 if (!isSatelliteProvisioned(validSubId)) {
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013447 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
13448 return;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013449 }
13450
13451 Phone phone = getPhoneOrDefault(validSubId, "pollPendingSatelliteDatagrams");
13452 if (phone == null) {
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013453 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
13454 return;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013455 }
13456
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013457 sendRequestAsync(CMD_POLL_PENDING_SATELLITE_DATAGRAMS, result, phone, null);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013458 }
13459
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013460 /**
13461 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013462 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013463 * Gateway encodes SOS SMS or location sharing message into a datagram and passes it as input to
13464 * this method. Datagram received here will be passed down to modem without any encoding or
13465 * encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013466 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013467 * @param subId The subId of the subscription to send satellite datagrams for.
13468 * @param datagramType datagram type indicating whether the datagram is of type
13469 * SOS_SMS or LOCATION_SHARING.
13470 * @param datagram encoded gateway datagram which is encrypted by the caller.
13471 * Datagram will be passed down to modem without any encoding or encryption.
13472 * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request.
13473 *
13474 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013475 */
13476 @Override
13477 public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
13478 SatelliteDatagram datagram, IIntegerConsumer callback) {
13479 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
13480 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
13481
13482 final int validSubId = getValidSatelliteSubId(subId);
13483 if (!isSatelliteProvisioned(validSubId)) {
13484 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
13485 return;
13486 }
13487
13488 Phone phone = getPhoneOrDefault(validSubId, "sendSatelliteDatagram");
13489 if (phone == null) {
13490 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
13491 return;
13492 }
13493
13494 // check if we need to start PointingUI.
13495
13496 sendRequestAsync(CMD_SEND_SATELLITE_DATAGRAM,
13497 new SendSatelliteDatagramArgument(datagramType, datagram, result),
13498 phone, null);
13499 }
13500
Sarah Chindf715ec2023-02-13 13:46:24 -080013501 /**
13502 * Request to get whether satellite communication is allowed for the current location.
13503 *
13504 * @param subId The subId of the subscription to check whether satellite communication is
13505 * allowed for the current location for.
13506 * @param result The result receiver that returns whether satellite communication is allowed
13507 * for the current location if the request is successful or an error code
13508 * if the request failed.
13509 *
13510 * @throws SecurityException if the caller doesn't have the required permission.
13511 */
13512 @Override
13513 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
13514 @NonNull ResultReceiver result) {
13515 enforceSatelliteCommunicationPermission(
13516 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
13517 if (!isSatelliteSupported()) {
13518 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
13519 return;
13520 }
13521
13522 final int validSubId = getValidSatelliteSubId(subId);
13523 if (!isSatelliteProvisioned(validSubId)) {
13524 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
13525 return;
13526 }
13527
13528 Phone phone = getPhoneOrDefault(validSubId,
13529 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
13530 if (phone == null) {
13531 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
13532 return;
13533 }
13534
13535 sendRequest(CMD_IS_SATELLITE_COMMUNICATION_ALLOWED, result, subId);
13536 }
13537
13538 /**
Sarah Chin5f57c582023-02-14 04:16:10 -080013539 * Request to get the time after which the satellite will be visible
Sarah Chindf715ec2023-02-13 13:46:24 -080013540 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013541 * @param subId The subId to get the time after which the satellite will be visible for.
13542 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013543 * be visible if the request is successful or an error code if the request failed.
13544 *
13545 * @throws SecurityException if the caller doesn't have the required permission.
13546 */
13547 @Override
13548 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13549 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
13550 if (!isSatelliteSupported()) {
13551 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
13552 return;
13553 }
13554
13555 final int validSubId = getValidSatelliteSubId(subId);
13556 if (!isSatelliteProvisioned(validSubId)) {
13557 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
13558 return;
13559 }
13560
13561 Phone phone = getPhoneOrDefault(validSubId, "requestTimeForNextSatelliteVisibility");
13562 if (phone == null) {
13563 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
13564 return;
13565 }
13566
13567 sendRequestAsync(CMD_GET_TIME_SATELLITE_NEXT_VISIBLE, result, phone, null);
13568 }
13569
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013570 private void handleEventProvisionSatelliteServiceDone(
13571 @NonNull ProvisionSatelliteServiceArgument arg,
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013572 @SatelliteManager.SatelliteError int result) {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013573 log("handleEventProvisionSatelliteServiceDone: result="
13574 + result + ", subId=" + arg.subId);
13575
13576 Consumer<Integer> callback = mSatelliteProvisionCallbacks.remove(arg.subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013577 if (callback == null) {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013578 loge("handleEventProvisionSatelliteServiceDone: callback is null for subId="
13579 + arg.subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013580 return;
13581 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013582 callback.accept(result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013583
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013584 if (result == SatelliteManager.SATELLITE_ERROR_NONE) {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013585 setSatelliteProvisioned(arg.subId, true);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013586 }
13587
13588 /**
13589 * We need to update satellite provision status in SubscriptionController
13590 * or SatelliteController.
13591 * TODO (b/267826133) we need to do this for all subscriptions on the device.
13592 */
Sarah Chindf715ec2023-02-13 13:46:24 -080013593 registerForSatelliteProvisionStateChangedInternal(arg.subId, null);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013594 }
13595
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013596 private void handleEventDeprovisionSatelliteServiceDone(
13597 @NonNull ProvisionSatelliteServiceArgument arg,
13598 @SatelliteManager.SatelliteError int result) {
13599 if (arg == null) {
13600 loge("handleEventDeprovisionSatelliteServiceDone: arg is null");
13601 return;
13602 }
13603 log("handleEventDeprovisionSatelliteServiceDone: result="
13604 + result + ", subId=" + arg.subId);
13605
13606 if (arg.callback != null) {
13607 arg.callback.accept(result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013608 }
13609
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013610 if (result == SatelliteManager.SATELLITE_ERROR_NONE) {
13611 setSatelliteProvisioned(arg.subId, false);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013612 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013613 }
13614
13615 private Phone getPhoneOrDefault(int subId, String caller) {
13616 Phone phone = getPhone(subId);
13617 if (phone == null) {
13618 loge(caller + " called with invalid subId: " + subId
13619 + ". Retrying with default phone.");
13620 phone = getDefaultPhone();
13621 if (phone == null) {
13622 loge(caller + " failed with no phone object.");
13623 }
13624 }
13625 return phone;
13626 }
13627
13628 /**
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013629 * Check if satellite is provisioned for a subscription or the device.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013630 *
13631 * Note: this is the version without permission check for telephony internal use only. The
13632 * caller need to take care of the permission check.
13633 */
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013634 private boolean isSatelliteProvisioned(int subId) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013635 if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
13636 if (mSubscriptionController == null) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013637 loge("isSatelliteProvisioned mSubscriptionController is null");
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013638 return false;
13639 }
13640
13641 String strResult = mSubscriptionController.getSubscriptionProperty(
13642 subId, SubscriptionManager.SATELLITE_ENABLED);
13643 if (strResult != null) {
13644 int intResult = Integer.parseInt(strResult);
13645 return (intResult == 1) ? true : false;
13646 }
13647 } else {
13648 //TODO (b/267826133): check via SatelliteController
13649 }
13650 return false;
13651 }
13652
13653 /**
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013654 * Set satellite provisioned for a subscription or the device.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013655 *
13656 * The permission {@link android.Manifest.permission#MODIFY_PHONE_STATE} will be enforced by
13657 * {@link SubscriptionController} when setting satellite enabled for an active subscription.
13658 * Otherwise, {@link android.Manifest.permission#SATELLITE_COMMUNICATION} will be enforced.
13659 */
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013660 private synchronized void setSatelliteProvisioned(int subId, boolean isEnabled) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013661 if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
13662 if (mSubscriptionController == null) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013663 loge("setSatelliteProvisioned mSubscriptionController is null");
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013664 return;
13665 }
13666 mSubscriptionController.setSubscriptionProperty(
13667 subId, SubscriptionManager.SATELLITE_ENABLED, isEnabled ? "1" : "0");
13668 } else {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013669 //TODO (b/267826133): set via SatelliteController
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013670 }
13671 }
13672
13673 private int getValidSatelliteSubId(int subId) {
13674 if (mSubscriptionController == null) {
13675 loge("getValidSatelliteSubId mSubscriptionController is null. "
13676 + "Use DEFAULT_SUBSCRIPTION_ID for subId=" + subId);
13677 return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
13678 }
13679 final long identity = Binder.clearCallingIdentity();
13680 try {
13681 Context context = getDefaultPhone().getContext();
13682 if (mSubscriptionController.isActiveSubId(
13683 subId, context.getOpPackageName(), context.getAttributionTag())) {
13684 return subId;
13685 }
13686 } finally {
13687 Binder.restoreCallingIdentity(identity);
13688 }
13689 if (DBG) log("getValidSatelliteSubId: use DEFAULT_SUBSCRIPTION_ID for subId=" + subId);
13690 return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
13691 }
13692
13693 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013694 * If we have not successfully queried the satellite modem for its satellite service support,
13695 * we will retry the query one more time. Otherwise, we will return the queried result.
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013696 */
13697 private boolean isSatelliteSupported() {
13698 synchronized (mIsSatelliteSupportedLock) {
13699 if (mIsSatelliteSupported != null) {
13700 /* We have already successfully queried the satellite modem. */
13701 return mIsSatelliteSupported;
13702 }
13703 }
13704 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013705 * We have not successfully checked whether the modem supports satellite service.
13706 * Thus, we need to retry it now.
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013707 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013708 requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
13709 mSatelliteSupportedReceiver);
13710 return false;
13711 }
13712
13713 /**
13714 * Get the {@link SatelliteManager.SatelliteError} from the provided result.
Sarah Chindf715ec2023-02-13 13:46:24 -080013715 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013716 * @param ar AsyncResult used to determine the error code.
13717 * @param caller The satellite request.
13718 * @param checkResult Whether to check if the result exists.
Sarah Chindf715ec2023-02-13 13:46:24 -080013719 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013720 * @return The {@link SatelliteManager.SatelliteError} error code from the request.
13721 */
13722 @SatelliteManager.SatelliteError private int getSatelliteError(@NonNull AsyncResult ar,
13723 @NonNull String caller, boolean checkResult) {
13724 int errorCode;
13725 if (ar.exception == null) {
13726 errorCode = SatelliteManager.SATELLITE_ERROR_NONE;
13727 if (checkResult && ar.result == null) {
13728 loge(caller + ": result is null");
13729 errorCode = SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
13730 }
13731 } else {
13732 errorCode = SatelliteManager.SATELLITE_ERROR;
13733 if (ar.exception instanceof CommandException) {
Sarah Chin4beb2b72023-02-14 14:47:54 -080013734 CommandException.Error error = ((CommandException) ar.exception).getCommandError();
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013735 errorCode = RILUtils.convertToSatelliteError(error);
13736 loge(caller + " CommandException: " + ar.exception);
Sarah Chin4beb2b72023-02-14 14:47:54 -080013737 } else if (ar.exception instanceof SatelliteManager.SatelliteException) {
13738 errorCode = ((SatelliteManager.SatelliteException) ar.exception).getErrorCode();
13739 loge(caller + " SatelliteException: " + ar.exception);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013740 } else {
13741 loge(caller + " unknown exception: " + ar.exception);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013742 }
13743 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013744 log(caller + " error: " + errorCode);
13745 return errorCode;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013746 }
13747
13748 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013749 * Register for the satellite provision state change.
13750 *
13751 * @param subId The subId of the subscription associated with the satellite service.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013752 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013753 *
13754 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013755 */
Sarah Chindf715ec2023-02-13 13:46:24 -080013756 @SatelliteManager.SatelliteError private int registerForSatelliteProvisionStateChangedInternal(
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013757 int subId, @Nullable ISatelliteProvisionStateCallback callback) {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013758 if (!isSatelliteSupported()) {
Sarah Chindf715ec2023-02-13 13:46:24 -080013759 return SatelliteManager.SATELLITE_NOT_SUPPORTED;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013760 }
13761
13762 final int validSubId = getValidSatelliteSubId(subId);
13763 Phone phone = getPhoneOrDefault(validSubId, "registerForSatelliteProvisionStateChanged");
13764 if (phone == null) {
Sarah Chindf715ec2023-02-13 13:46:24 -080013765 return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013766 }
13767
13768 SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler =
13769 mSatelliteProvisionStateChangedHandlers.get(validSubId);
13770 if (satelliteProvisionStateChangedHandler == null) {
13771 satelliteProvisionStateChangedHandler = new SatelliteProvisionStateChangedHandler(
13772 Looper.getMainLooper(), validSubId);
13773 phone.registerForSatelliteProvisionStateChanged(satelliteProvisionStateChangedHandler,
13774 SatelliteProvisionStateChangedHandler.EVENT_PROVISION_STATE_CHANGED, null);
13775 }
13776
13777 if (callback != null) {
13778 satelliteProvisionStateChangedHandler.addListener(callback);
13779 }
13780 mSatelliteProvisionStateChangedHandlers.put(
13781 validSubId, satelliteProvisionStateChangedHandler);
Sarah Chindf715ec2023-02-13 13:46:24 -080013782 return SatelliteManager.SATELLITE_ERROR_NONE;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013783 }
13784
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013785 private void handleStartSatellitePositionUpdatesDone(@NonNull AsyncResult ar) {
13786 MainThreadRequest request = (MainThreadRequest) ar.userObj;
13787 SatellitePositionUpdateArgument arg = (SatellitePositionUpdateArgument) request.argument;
13788 int errorCode = getSatelliteError(
13789 ar, "handleStartSatellitePositionUpdatesDone", false);
13790 arg.errorCallback.accept(errorCode);
13791
13792 if (errorCode != SatelliteManager.SATELLITE_ERROR_NONE) {
13793 /**
13794 * We need to remove the callback from our listener list since the caller might not call
13795 * {@link #stopSatellitePositionUpdates(int, IIntegerConsumer, ISatellitePositionUpdateCallback)}
13796 * to unregister the callback in case of failure.
13797 */
13798 SatellitePositionUpdateHandler handler =
13799 mSatellitePositionUpdateHandlers.get(arg.subId);
13800 if (handler != null) {
13801 handler.removeListener(arg.callback);
13802
13803 if (!handler.hasListeners()) {
13804 mSatellitePositionUpdateHandlers.remove(arg.subId);
13805
13806 Phone phone = getPhoneFromRequest(request);
13807 if (phone == null) {
13808 loge("handleStartSatellitePositionUpdatesDone: phone is null");
13809 } else {
13810 phone.unregisterForSatellitePointingInfoChanged(handler);
13811 phone.unregisterForSatelliteDatagramsDelivered(handler);
13812 }
13813 }
13814 }
13815 }
13816 }
13817
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013818 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000013819 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
13820 *
13821 * <p>This method behaves in one of the following ways:
13822 * <ul>
13823 * <li>return true : if the calling package has the appop permission {@link
13824 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
13825 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
13826 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
13827 * Owner device identifier access check, or the calling package has carrier privileges</>
13828 * <li>throw SecurityException: if the caller does not meet any of the requirements.
13829 * </ul>
13830 */
13831 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
13832 String callingPackage, @Nullable String callingFeatureId, String message) {
13833 for (Phone phone : PhoneFactory.getPhones()) {
13834 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
13835 phone.getSubId(), callingPackage, callingFeatureId, message)) {
13836 return true;
13837 }
13838 }
13839 return false;
13840 }
arunvoddud7401012022-12-15 16:08:12 +000013841
13842 /**
Jack Yufa8ed012023-02-11 15:42:28 -080013843 * @return The subscription manager service instance.
13844 */
13845 public SubscriptionManagerService getSubscriptionManagerService() {
13846 return SubscriptionManagerService.getInstance();
13847 }
13848
13849 /**
arunvoddud7401012022-12-15 16:08:12 +000013850 * Class binds the consumer[callback] and carrierId.
13851 */
13852 private static class CallerCallbackInfo {
13853 private final Consumer<Integer> mConsumer;
13854 private final int mCarrierId;
13855
13856 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
13857 mConsumer = consumer;
13858 mCarrierId = carrierId;
13859 }
13860
13861 public Consumer<Integer> getConsumer() {
13862 return mConsumer;
13863 }
13864
13865 public int getCarrierId() {
13866 return mCarrierId;
13867 }
13868 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013869
13870 private static SatelliteDatagram[] convertToSatelliteDatagramArray(byte[][] datagrams) {
13871 // Convert 2D byte array into SatelliteDatagramArray.
13872 SatelliteDatagram[] satelliteDatagramArray =
13873 new SatelliteDatagram[datagrams.length];
13874 for (int i = 0; i < datagrams.length; i++) {
13875 satelliteDatagramArray[i] = new SatelliteDatagram(datagrams[i]);
13876 }
13877 return satelliteDatagramArray;
13878 }
Jack Yufa8ed012023-02-11 15:42:28 -080013879}