blob: 93810fed51d55634041a5f98df500171e78aea56 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000020import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080021import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Hall Liud892bec2018-11-30 14:51:45 -080022
Shuo Qianccbaf742021-02-22 18:32:21 -080023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
24import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070025import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000027import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070028
Brad Ebinger34c09a52021-02-17 23:23:21 +000029import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080030import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080031import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070032import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000033import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080034import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080036import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070037import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000038import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080039import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000040import android.compat.annotation.ChangeId;
41import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070042import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070043import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.content.Context;
45import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070046import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070047import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070048import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.net.Uri;
50import android.os.AsyncResult;
51import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080052import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.Bundle;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080054import android.os.CancellationSignal;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070056import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080057import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080058import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import android.os.Looper;
60import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070061import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080062import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070063import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070064import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080065import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080066import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070067import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070068import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080069import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070071import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070072import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070073import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070074import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080075import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070076import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000077import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090078import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080079import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080080import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070081import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080082import android.telephony.AccessNetworkConstants;
83import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070084import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070085import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080086import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070087import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080088import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070089import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080090import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -060091import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -070092import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080093import android.telephony.CellIdentityCdma;
94import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070096import android.telephony.CellInfoGsm;
97import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070098import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080099import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700100import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700101import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700102import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800103import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700104import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800105import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700106import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800107import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800108import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700109import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800110import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800112import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800113import android.telephony.SignalStrengthUpdateRequest;
114import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800115import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800117import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700118import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700119import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800120import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800121import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800122import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800123import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000124import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000125import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000126import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700127import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700128import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800129import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800130import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700131import android.telephony.gba.GbaAuthRequest;
132import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700133import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800134import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000135import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000136import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700137import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000138import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700139import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800140import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700141import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800142import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700143import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000144import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700145import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800146import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800147import android.telephony.ims.stub.ImsRegistrationImplBase;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800148import android.telephony.satellite.ISatelliteDatagramCallback;
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +0000149import android.telephony.satellite.ISatelliteDatagramReceiverAck;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800150import android.telephony.satellite.ISatellitePositionUpdateCallback;
151import android.telephony.satellite.ISatelliteProvisionStateCallback;
152import android.telephony.satellite.ISatelliteStateCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800153import android.telephony.satellite.PointingInfo;
Sarah Chin503828c2023-02-01 23:54:20 -0800154import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000155import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800156import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800157import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800158import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800160import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700161import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800163import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800164
Andrew Lee312e8172014-10-23 17:01:36 -0700165import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800166import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800167import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800168import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800169import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700170import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700171import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700172import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800173import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800174import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700175import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700176import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800177import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700178import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800179import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800180import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800181import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700182import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000183import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700184import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800185import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800187import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800188import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800189import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700190import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700191import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700192import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700194import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800195import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700196import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700197import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700198import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700199import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800200import com.android.internal.telephony.RILConstants;
Sarah Chineccfbd12023-01-20 19:00:35 -0800201import com.android.internal.telephony.RILUtils;
Daniel Bright94f43662021-03-01 14:43:40 -0800202import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700203import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000204import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700205import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700206import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800207import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800208import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800209import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700210import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000211import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800212import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700213import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800214import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700215import com.android.internal.telephony.imsphone.ImsPhone;
216import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000217import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800218import com.android.internal.telephony.metrics.TelephonyMetrics;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800219import com.android.internal.telephony.satellite.SatelliteServiceController;
Jack Yu285100e2022-12-02 22:48:35 -0800220import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
221import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700222import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700223import com.android.internal.telephony.uicc.IccIoResult;
224import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800225import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700226import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800227import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700228import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000229import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800230import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000231import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800232import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000233import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700234import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700235import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800236import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800237import com.android.phone.callcomposer.CallComposerPictureManager;
238import com.android.phone.callcomposer.CallComposerPictureTransfer;
239import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700240import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700241import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000242import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700243import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800244import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700245import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700246import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800247import com.android.services.telephony.TelecomAccountRegistry;
248import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800249import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800250
Hall Liu82694d52020-12-11 18:22:04 -0800251import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700252import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800253import java.io.IOException;
254import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700255import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700256import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800257import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000258import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800259import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800260import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800261import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800262import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100263import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800264import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700265import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800266import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800267import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700268import java.util.UUID;
Sarah Chineccfbd12023-01-20 19:00:35 -0800269import java.util.concurrent.ConcurrentHashMap;
Hall Liu82694d52020-12-11 18:22:04 -0800270import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800271import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800272import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700273
274/**
275 * Implementation of the ITelephony interface.
276 */
Santos Cordon117fee72014-05-16 17:56:12 -0700277public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700278 private static final String LOG_TAG = "PhoneInterfaceManager";
279 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
280 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800281 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700282
283 // Message codes used with mMainThreadHandler
284 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700285 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
286 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700287 private static final int CMD_OPEN_CHANNEL = 9;
288 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
289 private static final int CMD_CLOSE_CHANNEL = 11;
290 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800291 private static final int CMD_NV_READ_ITEM = 13;
292 private static final int EVENT_NV_READ_ITEM_DONE = 14;
293 private static final int CMD_NV_WRITE_ITEM = 15;
294 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
295 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
296 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700297 private static final int CMD_RESET_MODEM_CONFIG = 19;
298 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800299 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
300 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800301 private static final int CMD_SEND_ENVELOPE = 25;
302 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000303 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
304 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700305 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
306 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
307 private static final int CMD_EXCHANGE_SIM_IO = 31;
308 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800309 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
310 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700311 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
312 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700313 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
314 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700315 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
316 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
317 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
318 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700319 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
320 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
321 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
322 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700323 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800324 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
325 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000326 private static final int CMD_SWITCH_SLOTS = 50;
327 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700328 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
329 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
330 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
331 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
332 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
333 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
334 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
335 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700336 private static final int CMD_GET_ALL_CELL_INFO = 60;
337 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
338 private static final int CMD_GET_CELL_LOCATION = 62;
339 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700340 private static final int CMD_MODEM_REBOOT = 64;
341 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700342 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
343 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800344 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
345 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700346 private static final int CMD_GET_MODEM_STATUS = 70;
347 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700348 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
349 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700350 private static final int CMD_ERASE_MODEM_CONFIG = 74;
351 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800352 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
353 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
354 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
355 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800356 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
357 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800358 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800359 private static final int CMD_GET_CALL_FORWARDING = 83;
360 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
361 private static final int CMD_SET_CALL_FORWARDING = 85;
362 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
363 private static final int CMD_GET_CALL_WAITING = 87;
364 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
365 private static final int CMD_SET_CALL_WAITING = 89;
366 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700367 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
368 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
369 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
370 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700371 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
372 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800373 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
374 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800375 private static final int CMD_SET_DATA_THROTTLING = 99;
376 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800377 private static final int CMD_SET_SIM_POWER = 101;
378 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800379 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
380 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
381 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
382 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800383 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
384 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000385 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800386 private static final int CMD_GET_SLICING_CONFIG = 110;
387 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800388 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700389 private static final int CMD_ENABLE_VONR = 113;
390 private static final int EVENT_ENABLE_VONR_DONE = 114;
391 private static final int CMD_IS_VONR_ENABLED = 115;
392 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700393 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
394 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Sarah Chineccfbd12023-01-20 19:00:35 -0800395 private static final int CMD_START_SATELLITE_POSITION_UPDATES = 119;
396 private static final int EVENT_START_SATELLITE_POSITION_UPDATES_DONE = 120;
397 private static final int CMD_STOP_SATELLITE_POSITION_UPDATES = 121;
398 private static final int EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE = 122;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +0000399 private static final int CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG = 123;
400 private static final int EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE = 124;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800401 private static final int CMD_PROVISION_SATELLITE_SERVICE = 125;
402 private static final int EVENT_PROVISION_SATELLITE_SERVICE_DONE = 126;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -0800403 private static final int CMD_DEPROVISION_SATELLITE_SERVICE = 127;
404 private static final int EVENT_DEPROVISION_SATELLITE_SERVICE_DONE = 128;
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800405 private static final int CMD_SET_SATELLITE_ENABLED = 129;
406 private static final int EVENT_SET_SATELLITE_ENABLED_DONE = 130;
407 private static final int CMD_IS_SATELLITE_ENABLED = 131;
408 private static final int EVENT_IS_SATELLITE_ENABLED_DONE = 132;
409 private static final int CMD_IS_SATELLITE_SUPPORTED = 133;
410 private static final int EVENT_IS_SATELLITE_SUPPORTED_DONE = 134;
411 private static final int CMD_GET_SATELLITE_CAPABILITIES = 135;
412 private static final int EVENT_GET_SATELLITE_CAPABILITIES_DONE = 136;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000413 private static final int CMD_POLL_PENDING_SATELLITE_DATAGRAMS = 137;
414 private static final int EVENT_POLL_PENDING_SATELLITE_DATAGRAMS_DONE = 138;
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +0000415 private static final int CMD_SEND_SATELLITE_DATAGRAM = 139;
416 private static final int EVENT_SEND_SATELLITE_DATAGRAM_DONE = 140;
Sarah Chindf715ec2023-02-13 13:46:24 -0800417 private static final int CMD_IS_SATELLITE_COMMUNICATION_ALLOWED = 141;
418 private static final int EVENT_IS_SATELLITE_COMMUNICATION_ALLOWED_DONE = 142;
419 private static final int CMD_GET_TIME_SATELLITE_NEXT_VISIBLE = 143;
420 private static final int EVENT_GET_TIME_SATELLITE_NEXT_VISIBLE_DONE = 144;
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800421 // Parameters of select command.
422 private static final int SELECT_COMMAND = 0xA4;
423 private static final int SELECT_P1 = 0x04;
424 private static final int SELECT_P2 = 0;
425 private static final int SELECT_P3 = 0x10;
426
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000427 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
428 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
429
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700430 /** The singleton instance. */
431 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800432 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700433
Sarah Chin4beb2b72023-02-14 14:47:54 -0800434 private final PhoneGlobals mApp;
435 private final CallManager mCM;
436 private final ImsResolver mImsResolver;
437 private final SatelliteServiceController mSatelliteServiceController;
438 private final UserManager mUserManager;
439 private final AppOpsManager mAppOps;
440 private final MainThreadHandler mMainThreadHandler;
Jack Yue37dd262022-12-16 11:53:37 -0800441 private final SubscriptionController mSubscriptionController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800442 private final SharedPreferences mTelephonySharedPreferences;
443 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800444 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445
Peter Wangdafb9ac2020-01-15 14:13:38 -0800446 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800447 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800448 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
449
Sarah Chin4beb2b72023-02-14 14:47:54 -0800450 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800451
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800452 /**
453 * Map key: subId, value: callback to get error code of the provision request.
454 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800455 private final ConcurrentHashMap<Integer, Consumer<Integer>> mSatelliteProvisionCallbacks =
Sarah Chineccfbd12023-01-20 19:00:35 -0800456 new ConcurrentHashMap<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800457 /**
458 * Map key: subId, value: SatellitePositionUpdateHandler to notify registrants.
459 */
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800460 private final ConcurrentHashMap<Integer, SatellitePositionUpdateHandler>
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800461 mSatellitePositionUpdateHandlers = new ConcurrentHashMap<>();
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800462 /**
463 * Map key: subId, value: SatelliteProvisionStateChangedHandler to notify registrants.
464 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800465 private final ConcurrentHashMap<Integer, SatelliteProvisionStateChangedHandler>
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800466 mSatelliteProvisionStateChangedHandlers = new ConcurrentHashMap<>();
467
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800468 private Boolean mIsSatelliteSupported = null;
469 private final Object mIsSatelliteSupportedLock = new Object();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800470 private final ResultReceiver mSatelliteSupportedReceiver;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800471 /**
472 * {@code true} to use the vendor satellite service and {@code false} to use the HAL.
473 */
474 private final boolean mIsSatelliteServiceSupported = false;
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800475
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000476 /**
477 * Map key: subId, value: SatelliteStateChangeHandler to notify registrants.
478 */
479 private ConcurrentHashMap<Integer, SatelliteStateListenerHandler>
480 mSatelliteStateListenerHandlers = new ConcurrentHashMap<>();
481
482 /**
483 * Map key: subId, value: SatelliteDatagramListenerHandler to notify registrants.
484 */
485 private ConcurrentHashMap<Integer, SatelliteDatagramListenerHandler>
486 mSatelliteDatagramListenerHandlers = new ConcurrentHashMap<>();
487
Derek Tan97ebb422014-09-05 16:55:38 -0700488 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
489 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800490 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800491 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700492
Michelecea4cf22018-12-21 15:00:11 -0800493 // String to store multi SIM allowed
494 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
495
Derek Tan740e1672017-06-27 14:56:27 -0700496 // The AID of ISD-R.
497 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
498
yinxub1bed742017-04-17 11:45:04 -0700499 private NetworkScanRequestTracker mNetworkScanRequestTracker;
500
David Kelly5e06a7f2018-03-12 14:10:59 +0000501 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
502 private static final int MANUFACTURER_CODE_LENGTH = 8;
503
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800504 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800505 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800506
Sarah Chin2ec39f62022-08-31 17:03:26 -0700507 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
508 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
509
Derek Tan89e89d42014-07-08 17:00:10 -0700510 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700511 * Experiment flag to enable erase modem config on reset network, default value is false
512 */
513 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
514 "reset_network_erase_modem_config_enabled";
515
Rambo Wang0f050d82021-02-12 11:43:36 -0800516 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800517
Gary Jian76280a42022-12-07 16:18:33 +0800518 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
519
sandeepjsb6c87872021-09-27 15:34:44 +0000520 /**
521 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
522 * one ICCID active at the same time.
523 * Apps should use below API signatures if targeting SDK is T and beyond.
524 *
525 * @hide
526 */
527 @ChangeId
528 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
529 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800530
Naina Nallurid63128d2019-09-17 14:10:30 -0700531 /**
Chen Xu540470b2021-12-14 17:15:47 -0800532 * Apps targeting on Android T and beyond will get exception whenever icc close channel
533 * operation fails.
534 */
535 @ChangeId
536 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
537 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
538
539 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700540 * A request object to use for transmitting data to an ICC.
541 */
542 private static final class IccAPDUArgument {
543 public int channel, cla, command, p1, p2, p3;
544 public String data;
545
546 public IccAPDUArgument(int channel, int cla, int command,
547 int p1, int p2, int p3, String data) {
548 this.channel = channel;
549 this.cla = cla;
550 this.command = command;
551 this.p1 = p1;
552 this.p2 = p2;
553 this.p3 = p3;
554 this.data = data;
555 }
556 }
557
558 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700559 * A request object to use for transmitting data to an ICC.
560 */
561 private static final class ManualNetworkSelectionArgument {
562 public OperatorInfo operatorInfo;
563 public boolean persistSelection;
564
565 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
566 this.operatorInfo = operatorInfo;
567 this.persistSelection = persistSelection;
568 }
569 }
570
Sarah Chin71b3a852022-09-28 15:54:19 -0700571 private static final class PurchasePremiumCapabilityArgument {
572 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700573 public @NonNull IIntegerConsumer callback;
574
575 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800576 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700577 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700578 this.callback = callback;
579 }
580 }
581
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800582 private static final class ProvisionSatelliteServiceArgument {
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800583 public @NonNull String token;
584 public @NonNull Consumer<Integer> callback;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800585 public int subId;
586
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800587 ProvisionSatelliteServiceArgument(String token, Consumer<Integer> callback, int subId) {
588 this.token = token;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800589 this.callback = callback;
590 this.subId = subId;
591 }
592 }
593
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +0000594 private static final class SendSatelliteDatagramArgument {
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +0000595 public long datagramId;
596
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +0000597 public @SatelliteManager.DatagramType int datagramType;
598 public @NonNull SatelliteDatagram datagram;
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +0000599 public @NonNull ResultReceiver result;
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +0000600
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +0000601 SendSatelliteDatagramArgument(long datagramId,
602 @SatelliteManager.DatagramType int datagramType,
603 SatelliteDatagram datagram, ResultReceiver result) {
604 this.datagramId = datagramId;
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +0000605 this.datagramType = datagramType;
606 this.datagram = datagram;
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +0000607 this.result = result;
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +0000608 }
609 }
610
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800611 private static final class SatellitePositionUpdateArgument {
612 public @NonNull Consumer<Integer> errorCallback;
613 public @NonNull ISatellitePositionUpdateCallback callback;
614 public int subId;
615
616 SatellitePositionUpdateArgument(Consumer<Integer> errorCallback,
617 ISatellitePositionUpdateCallback callback, int subId) {
618 this.errorCallback = errorCallback;
619 this.callback = callback;
620 this.subId = subId;
621 }
622 }
623
Sarah Chineccfbd12023-01-20 19:00:35 -0800624 private static final class SatellitePositionUpdateHandler extends Handler {
625 public static final int EVENT_POSITION_UPDATE = 1;
626 public static final int EVENT_MESSAGE_TRANSFER_STATE_UPDATE = 2;
627
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800628 private final ConcurrentHashMap<IBinder, ISatellitePositionUpdateCallback> mListeners;
629 SatellitePositionUpdateHandler(Looper looper) {
Sarah Chineccfbd12023-01-20 19:00:35 -0800630 super(looper);
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800631 mListeners = new ConcurrentHashMap<>();
632 }
633
634 public void addListener(ISatellitePositionUpdateCallback listener) {
635 mListeners.put(listener.asBinder(), listener);
636 }
637
638 public void removeListener(ISatellitePositionUpdateCallback listener) {
639 mListeners.remove(listener.asBinder());
640 }
641
642 public boolean hasListeners() {
643 return !mListeners.isEmpty();
Sarah Chineccfbd12023-01-20 19:00:35 -0800644 }
645
646 @Override
647 public void handleMessage(@NonNull Message msg) {
648 switch (msg.what) {
649 case EVENT_POSITION_UPDATE: {
650 AsyncResult ar = (AsyncResult) msg.obj;
651 PointingInfo pointingInfo = (PointingInfo) ar.result;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800652 mListeners.values().forEach(listener -> {
653 try {
654 listener.onSatellitePositionUpdate(pointingInfo);
655 } catch (RemoteException e) {
656 log("EVENT_POSITION_UPDATE RemoteException: " + e);
657 }
658 });
Sarah Chineccfbd12023-01-20 19:00:35 -0800659 break;
660 }
661 case EVENT_MESSAGE_TRANSFER_STATE_UPDATE: {
662 AsyncResult ar = (AsyncResult) msg.obj;
663 int state = (int) ar.result;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800664 mListeners.values().forEach(listener -> {
665 try {
666 // TODO: get correct responses back from indication
667 listener.onDatagramTransferStateUpdate(state, 0, 0, 0);
668 } catch (RemoteException e) {
669 log("EVENT_MESSAGE_TRANSFER_STATE_UPDATE RemoteException: " + e);
670 }
671 });
Sarah Chineccfbd12023-01-20 19:00:35 -0800672 break;
673 }
674 default:
675 loge("SatellitePositionUpdateHandler unknown event: " + msg.what);
676 }
677 }
678 }
679
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800680 private static final class SatelliteProvisionStateChangedHandler extends Handler {
681 public static final int EVENT_PROVISION_STATE_CHANGED = 1;
682
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800683 private final ConcurrentHashMap<IBinder, ISatelliteProvisionStateCallback> mListeners;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800684 private final int mSubId;
685
686 SatelliteProvisionStateChangedHandler(Looper looper, int subId) {
687 super(looper);
688 mListeners = new ConcurrentHashMap<>();
689 mSubId = subId;
690 }
691
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800692 public void addListener(ISatelliteProvisionStateCallback listener) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800693 mListeners.put(listener.asBinder(), listener);
694 }
695
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800696 public void removeListener(ISatelliteProvisionStateCallback listener) {
697 mListeners.remove(listener.asBinder());
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800698 }
699
700 @Override
701 public void handleMessage(@NonNull Message msg) {
702 switch (msg.what) {
703 case EVENT_PROVISION_STATE_CHANGED: {
704 AsyncResult ar = (AsyncResult) msg.obj;
705 boolean provisioned = (boolean) ar.userObj;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800706 log("Received EVENT_PROVISION_STATE_CHANGED for subId=" + mSubId
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800707 + ", provisioned=" + provisioned);
708 mListeners.values().forEach(listener -> {
709 try {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -0800710 listener.onSatelliteProvisionStateChanged(provisioned);
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800711 } catch (RemoteException e) {
712 log("EVENT_PROVISION_STATE_CHANGED RemoteException: " + e);
713 }
714 });
715
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800716 setSatelliteProvisioned(provisioned);
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800717 /**
718 * TODO: Take bugreport if provisioned is true and user did not initiate the
719 * provision procedure for the corresponding subscription.
720 */
721 break;
722 }
723 default:
724 loge("SatelliteProvisionStateChangedHandler unknown event: " + msg.what);
725 }
726 }
727
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800728 private void setSatelliteProvisioned(boolean isProvisioned) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800729 if (mSubId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
730 SubscriptionManager.setSubscriptionProperty(
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800731 mSubId, SubscriptionManager.SATELLITE_ENABLED, isProvisioned ? "1" : "0");
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800732 } else {
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800733 //TODO (b/267826133): set via SatelliteController.
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800734 }
735 }
736 }
737
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000738 private static final class SatelliteStateListenerHandler extends Handler {
739 public static final int EVENT_SATELLITE_MODEM_STATE_CHANGE = 1;
Aishwarya Mallampati224317a2023-02-13 22:09:30 +0000740 public static final int EVENT_PENDING_DATAGRAM_COUNT = 2;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000741
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800742 private final ConcurrentHashMap<IBinder, ISatelliteStateCallback> mListeners;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000743 private final int mSubId;
744
745 SatelliteStateListenerHandler(Looper looper, int subId) {
746 super(looper);
747 mSubId = subId;
748 mListeners = new ConcurrentHashMap<>();
749 }
750
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800751 public void addListener(ISatelliteStateCallback listener) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000752 mListeners.put(listener.asBinder(), listener);
753 }
754
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800755 public void removeListener(ISatelliteStateCallback listener) {
756 mListeners.remove(listener.asBinder());
757 }
758
759 public boolean hasListeners() {
760 return !mListeners.isEmpty();
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000761 }
762
763 @Override
764 public void handleMessage(@NonNull Message msg) {
765 switch (msg.what) {
766 case EVENT_SATELLITE_MODEM_STATE_CHANGE : {
767 AsyncResult ar = (AsyncResult) msg.obj;
768 int state = (int) ar.result;
769 log("Received EVENT_SATELLITE_MODEM_STATE_CHANGE for subId=" + mSubId
770 + ", state=" + state);
771 mListeners.values().forEach(listener -> {
772 try {
773 listener.onSatelliteModemStateChange(state);
774 } catch (RemoteException e) {
775 log("EVENT_SATELLITE_MODEM_STATE_CHANGE RemoteException: " + e);
776 }
777 });
778 break;
779 }
Aishwarya Mallampati224317a2023-02-13 22:09:30 +0000780 case EVENT_PENDING_DATAGRAM_COUNT: {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000781 AsyncResult ar = (AsyncResult) msg.obj;
782 int count = (int) ar.result;
Aishwarya Mallampati224317a2023-02-13 22:09:30 +0000783 log("Received EVENT_PENDING_DATAGRAM_COUNT for subId=" + mSubId
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000784 + ", count=" + count);
785 mListeners.values().forEach(listener -> {
786 try {
Aishwarya Mallampati224317a2023-02-13 22:09:30 +0000787 listener.onPendingDatagramCount(count);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000788 } catch (RemoteException e) {
Aishwarya Mallampati224317a2023-02-13 22:09:30 +0000789 log("EVENT_PENDING_DATAGRAM_COUNT RemoteException: " + e);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000790 }
791 });
792 break;
793 }
794 default:
795 loge("SatelliteStateListenerHandler unknown event: " + msg.what);
796 }
797 }
798 }
799
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +0000800 /** Callback used by datagram receiver app to send ack back to Telephony. */
801 private static final ISatelliteDatagramReceiverAck.Stub mDatagramReceiverAck =
802 new ISatelliteDatagramReceiverAck.Stub() {
803 /**
804 * This callback will be used by datagram receiver app to send ack back to
805 * Telephony. If the callback is not received within five minutes,
806 * then Telephony will resend the datagram again.
807 *
808 * @param datagramId An id that uniquely identifies datagram
809 * received by satellite datagram receiver app.
810 * This should match with datagramId passed in
811 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(
812 * long, SatelliteDatagram, int, ISatelliteDatagramReceiverAck)}.
813 * Upon receiving the ack, Telephony will remove the datagram from
814 * the persistent memory.
815 */
816 public void acknowledgeSatelliteDatagramReceived(long datagramId) {
817
818 }
819 };
820
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000821 private static final class SatelliteDatagramListenerHandler extends Handler {
822 public static final int EVENT_SATELLITE_DATAGRAMS_RECEIVED = 1;
823
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800824 private final ConcurrentHashMap<IBinder, ISatelliteDatagramCallback> mListeners;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000825 private final int mSubId;
826
827 SatelliteDatagramListenerHandler(Looper looper, int subId) {
828 super(looper);
829 mSubId = subId;
830 mListeners = new ConcurrentHashMap<>();
831 }
832
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800833 public void addListener(ISatelliteDatagramCallback listener) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000834 mListeners.put(listener.asBinder(), listener);
835 }
836
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800837 public void removeListener(ISatelliteDatagramCallback listener) {
838 mListeners.remove(listener.asBinder());
839 }
840
841 public boolean hasListeners() {
842 return !mListeners.isEmpty();
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000843 }
844
845 @Override
846 public void handleMessage(@NonNull Message msg) {
847 switch (msg.what) {
848 case EVENT_SATELLITE_DATAGRAMS_RECEIVED : {
849 AsyncResult ar = (AsyncResult) msg.obj;
850 byte[][] datagrams = (byte[][]) ar.result;
851 SatelliteDatagram[] satelliteDatagramArray =
852 convertToSatelliteDatagramArray(datagrams);
853
854 log("Received EVENT_SATELLITE_DATAGRAMS_RECEIVED for subId=" + mSubId);
855 mListeners.values().forEach(listener -> {
856 try {
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +0000857 for(SatelliteDatagram datagram : satelliteDatagramArray) {
858 // TODO (b/269637555): wait for ack and retry after 5mins
859 listener.onSatelliteDatagramReceived(0, datagram, 0,
860 mDatagramReceiverAck);
861 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000862 } catch (RemoteException e) {
863 log("EVENT_SATELLITE_DATAGRAMS_RECEIVED RemoteException: " + e);
864 }
865 });
866 break;
867 }
868 default:
869 loge("SatelliteDatagramListenerHandler unknown event: " + msg.what);
870 }
871 }
872 }
873
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700874 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700875 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
876 * request after sending. The main thread will notify the request when it is complete.
877 */
878 private static final class MainThreadRequest {
879 /** The argument to use for the request */
880 public Object argument;
881 /** The result of the request that is run on the main thread */
882 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800883 // The subscriber id that this request applies to. Defaults to
884 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
885 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700886
Nathan Harold92bed182018-10-12 18:16:49 -0700887 // In cases where subId is unavailable, the caller needs to specify the phone.
888 public Phone phone;
889
vagdeviaf9a5b92018-08-15 16:01:53 -0700890 public WorkSource workSource;
891
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700892 public MainThreadRequest(Object argument) {
893 this.argument = argument;
894 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800895
Nathan Harold92bed182018-10-12 18:16:49 -0700896 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
897 this.argument = argument;
898 if (phone != null) {
899 this.phone = phone;
900 }
901 this.workSource = workSource;
902 }
903
vagdeviaf9a5b92018-08-15 16:01:53 -0700904 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800905 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800906 if (subId != null) {
907 this.subId = subId;
908 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700909 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800910 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700911 }
912
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800913 private static final class IncomingThirdPartyCallArgs {
914 public final ComponentName component;
915 public final String callId;
916 public final String callerDisplayName;
917
918 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
919 String callerDisplayName) {
920 this.component = component;
921 this.callId = callId;
922 this.callerDisplayName = callerDisplayName;
923 }
924 }
925
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700926 /**
927 * A handler that processes messages on the main thread in the phone process. Since many
928 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
929 * inbound binder threads to the main thread in the phone process. The Binder thread
930 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
931 * on, which will be notified when the operation completes and will contain the result of the
932 * request.
933 *
934 * <p>If a MainThreadRequest object is provided in the msg.obj field,
935 * note that request.result must be set to something non-null for the calling thread to
936 * unblock.
937 */
938 private final class MainThreadHandler extends Handler {
939 @Override
940 public void handleMessage(Message msg) {
941 MainThreadRequest request;
942 Message onCompleted;
943 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000944 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700945 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800946 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700947
948 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700949 case CMD_HANDLE_USSD_REQUEST: {
950 request = (MainThreadRequest) msg.obj;
951 final Phone phone = getPhoneFromRequest(request);
952 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800953 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700954 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700955
Pengquan Menga1bb6272018-09-06 09:59:22 -0700956 if (!isUssdApiAllowed(request.subId)) {
957 // Carrier does not support use of this API, return failure.
958 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
959 UssdResponse response = new UssdResponse(ussdRequest, null);
960 Bundle returnData = new Bundle();
961 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
962 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700963
Pengquan Menga1bb6272018-09-06 09:59:22 -0700964 request.result = true;
965 notifyRequester(request);
966 return;
967 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700968
Pengquan Menga1bb6272018-09-06 09:59:22 -0700969 try {
970 request.result = phone != null
971 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
972 } catch (CallStateException cse) {
973 request.result = false;
974 }
975 // Wake up the requesting thread
976 notifyRequester(request);
977 break;
pkanwar32d516d2016-10-14 19:37:38 -0700978 }
979
Yorke Lee716f67e2015-06-17 15:39:16 -0700980 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700981 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700982 final Phone phone = getPhoneFromRequest(request);
983 request.result = phone != null ?
984 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
985 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700986 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700987 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700988 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700989 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700990
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700991 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700992 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700993 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000994 uiccPort = getUiccPortFromRequest(request);
995 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700996 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800997 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700998 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700999 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001000 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -08001001 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001002 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -08001003 iccArgument.channel, iccArgument.cla, iccArgument.command,
1004 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
1005 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001006 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001007 break;
1008
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001009 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -07001010 ar = (AsyncResult) msg.obj;
1011 request = (MainThreadRequest) ar.userObj;
1012 if (ar.exception == null && ar.result != null) {
1013 request.result = ar.result;
1014 } else {
Chen Xue9d737e2022-01-01 23:41:31 -08001015 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001016 if (ar.result == null) {
1017 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -08001018 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -07001019 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -08001020 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001021 } else {
1022 loge("iccTransmitApduLogicalChannel: Unknown exception");
1023 }
1024 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001025 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001026 break;
1027
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001028 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
1029 request = (MainThreadRequest) msg.obj;
1030 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001031 uiccPort = getUiccPortFromRequest(request);
1032 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001033 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -08001034 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001035 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001036 } else {
1037 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -08001038 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001039 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -08001040 iccArgument.cla, iccArgument.command, iccArgument.p1,
1041 iccArgument.p2,
1042 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001043 }
1044 break;
1045
1046 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
1047 ar = (AsyncResult) msg.obj;
1048 request = (MainThreadRequest) ar.userObj;
1049 if (ar.exception == null && ar.result != null) {
1050 request.result = ar.result;
1051 } else {
Chen Xue9d737e2022-01-01 23:41:31 -08001052 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001053 if (ar.result == null) {
1054 loge("iccTransmitApduBasicChannel: Empty response");
1055 } else if (ar.exception instanceof CommandException) {
1056 loge("iccTransmitApduBasicChannel: CommandException: " +
1057 ar.exception);
1058 } else {
1059 loge("iccTransmitApduBasicChannel: Unknown exception");
1060 }
1061 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001062 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001063 break;
1064
1065 case CMD_EXCHANGE_SIM_IO:
1066 request = (MainThreadRequest) msg.obj;
1067 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001068 uiccPort = getUiccPortFromRequest(request);
1069 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001070 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -08001071 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001072 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001073 } else {
1074 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
1075 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001076 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001077 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
1078 iccArgument.data, onCompleted);
1079 }
1080 break;
1081
1082 case EVENT_EXCHANGE_SIM_IO_DONE:
1083 ar = (AsyncResult) msg.obj;
1084 request = (MainThreadRequest) ar.userObj;
1085 if (ar.exception == null && ar.result != null) {
1086 request.result = ar.result;
1087 } else {
Chen Xue9d737e2022-01-01 23:41:31 -08001088 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001089 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001090 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001091 break;
1092
Derek Tan4d5e5c12014-02-04 11:54:58 -08001093 case CMD_SEND_ENVELOPE:
1094 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001095 uiccPort = getUiccPortFromRequest(request);
1096 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001097 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -08001098 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001099 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001100 } else {
1101 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -08001102 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001103 }
Derek Tan4d5e5c12014-02-04 11:54:58 -08001104 break;
1105
1106 case EVENT_SEND_ENVELOPE_DONE:
1107 ar = (AsyncResult) msg.obj;
1108 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -07001109 if (ar.exception == null && ar.result != null) {
1110 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -08001111 } else {
Chen Xue9d737e2022-01-01 23:41:31 -08001112 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -07001113 if (ar.result == null) {
1114 loge("sendEnvelopeWithStatus: Empty response");
1115 } else if (ar.exception instanceof CommandException) {
1116 loge("sendEnvelopeWithStatus: CommandException: " +
1117 ar.exception);
1118 } else {
1119 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
1120 }
Derek Tan4d5e5c12014-02-04 11:54:58 -08001121 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001122 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -08001123 break;
1124
Shishir Agrawal566b7612013-10-28 14:41:00 -07001125 case CMD_OPEN_CHANNEL:
1126 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001127 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -08001128 IccLogicalChannelRequest openChannelRequest =
1129 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001130 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001131 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -08001132 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -08001133 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001134 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001135 } else {
1136 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -08001137 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
1138 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001139 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001140 break;
1141
1142 case EVENT_OPEN_CHANNEL_DONE:
1143 ar = (AsyncResult) msg.obj;
1144 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001145 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -07001146 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001147 int[] result = (int[]) ar.result;
1148 int channelId = result[0];
1149 byte[] selectResponse = null;
1150 if (result.length > 1) {
1151 selectResponse = new byte[result.length - 1];
1152 for (int i = 1; i < result.length; ++i) {
1153 selectResponse[i - 1] = (byte) result[i];
1154 }
1155 }
1156 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -08001157 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -08001158
1159 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -07001160 if (uiccPort == null) {
1161 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
1162 } else {
1163 IccLogicalChannelRequest channelRequest =
1164 (IccLogicalChannelRequest) request.argument;
1165 channelRequest.channel = channelId;
1166 uiccPort.onLogicalChannelOpened(channelRequest);
1167 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001168 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -07001169 if (ar.result == null) {
1170 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -07001171 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001172 if (ar.exception != null) {
1173 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
1174 }
1175
Shishir Agrawal527e8bf2014-08-25 08:54:56 -07001176 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -07001177 if (ar.exception instanceof CommandException) {
1178 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -08001179 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -07001180 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -07001181 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -07001182 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -07001183 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001184 }
1185 }
1186 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -08001187 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001188 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -07001189 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001190 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001191 break;
1192
1193 case CMD_CLOSE_CHANNEL:
1194 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001195 uiccPort = getUiccPortFromRequest(request);
1196 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001197 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -08001198 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001199 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -08001200 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001201 } else {
1202 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001203 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001204 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001205 break;
1206
1207 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -08001208 ar = (AsyncResult) msg.obj;
1209 request = (MainThreadRequest) ar.userObj;
1210 if (ar.exception == null) {
1211 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -08001212 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -07001213 if (uiccPort == null) {
1214 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
1215 } else {
1216 final int channelId = (Integer) request.argument;
1217 uiccPort.onLogicalChannelClosed(channelId);
1218 }
Chen Xu540470b2021-12-14 17:15:47 -08001219 } else {
1220 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -08001221 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -08001222 if (ar.exception instanceof CommandException) {
1223 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
1224 CommandException.Error error =
1225 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -08001226 if (error == CommandException.Error.INVALID_ARGUMENTS) {
1227 // should only throw exceptions from the binder threads.
1228 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -08001229 "iccCloseLogicalChannel: invalid argument ");
1230 }
1231 } else {
1232 loge("iccCloseLogicalChannel: Unknown exception");
1233 }
Chen Xua8f0dff2022-02-12 00:34:15 -08001234 request.result = (exception != null) ? exception :
1235 new IllegalStateException(
1236 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -08001237 }
1238 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001239 break;
1240
1241 case CMD_NV_READ_ITEM:
1242 request = (MainThreadRequest) msg.obj;
1243 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001244 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
1245 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -08001246 break;
1247
1248 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -07001249 ar = (AsyncResult) msg.obj;
1250 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -08001251 if (ar.exception == null && ar.result != null) {
1252 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -07001253 } else {
Jake Hambye994d462014-02-03 13:10:13 -08001254 request.result = "";
1255 if (ar.result == null) {
1256 loge("nvReadItem: Empty response");
1257 } else if (ar.exception instanceof CommandException) {
1258 loge("nvReadItem: CommandException: " +
1259 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001260 } else {
Jake Hambye994d462014-02-03 13:10:13 -08001261 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -07001262 }
1263 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001264 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001265 break;
1266
Jake Hambye994d462014-02-03 13:10:13 -08001267 case CMD_NV_WRITE_ITEM:
1268 request = (MainThreadRequest) msg.obj;
1269 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
1270 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001271 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -07001272 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -08001273 break;
1274
1275 case EVENT_NV_WRITE_ITEM_DONE:
1276 handleNullReturnEvent(msg, "nvWriteItem");
1277 break;
1278
1279 case CMD_NV_WRITE_CDMA_PRL:
1280 request = (MainThreadRequest) msg.obj;
1281 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001282 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -08001283 break;
1284
1285 case EVENT_NV_WRITE_CDMA_PRL_DONE:
1286 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
1287 break;
1288
chen xu6dac5ab2018-10-26 17:39:23 -07001289 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -08001290 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -07001291 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001292 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -08001293 break;
1294
chen xu6dac5ab2018-10-26 17:39:23 -07001295 case EVENT_RESET_MODEM_CONFIG_DONE:
1296 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -08001297 break;
1298
Sooraj Sasindran37444802020-08-11 10:40:43 -07001299 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
1300 request = (MainThreadRequest) msg.obj;
1301 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
1302 request);
1303 Phone phone = getPhoneFromRequest(request);
1304 if (phone != null) {
1305 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
1306 } else {
1307 loge("isNRDualConnectivityEnabled: No phone object");
1308 request.result = false;
1309 notifyRequester(request);
1310 }
1311 break;
1312 }
1313
1314 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
1315 ar = (AsyncResult) msg.obj;
1316 request = (MainThreadRequest) ar.userObj;
1317 if (ar.exception == null && ar.result != null) {
1318 request.result = ar.result;
1319 } else {
1320 // request.result must be set to something non-null
1321 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001322 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -07001323 request.result = ar.result;
1324 } else {
1325 request.result = false;
1326 }
1327 if (ar.result == null) {
1328 loge("isNRDualConnectivityEnabled: Empty response");
1329 } else if (ar.exception instanceof CommandException) {
1330 loge("isNRDualConnectivityEnabled: CommandException: "
1331 + ar.exception);
1332 } else {
1333 loge("isNRDualConnectivityEnabled: Unknown exception");
1334 }
1335 }
1336 notifyRequester(request);
1337 break;
1338
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001339 case CMD_IS_VONR_ENABLED: {
1340 request = (MainThreadRequest) msg.obj;
1341 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1342 request);
1343 Phone phone = getPhoneFromRequest(request);
1344 if (phone != null) {
1345 phone.isVoNrEnabled(onCompleted, request.workSource);
1346 } else {
1347 loge("isVoNrEnabled: No phone object");
1348 request.result = false;
1349 notifyRequester(request);
1350 }
1351 break;
1352 }
1353
1354 case EVENT_IS_VONR_ENABLED_DONE:
1355 ar = (AsyncResult) msg.obj;
1356 request = (MainThreadRequest) ar.userObj;
1357 if (ar.exception == null && ar.result != null) {
1358 request.result = ar.result;
1359 } else {
1360 // request.result must be set to something non-null
1361 // for the calling thread to unblock
1362 if (ar.result != null) {
1363 request.result = ar.result;
1364 } else {
1365 request.result = false;
1366 }
1367 if (ar.result == null) {
1368 loge("isVoNrEnabled: Empty response");
1369 } else if (ar.exception instanceof CommandException) {
1370 loge("isVoNrEnabled: CommandException: "
1371 + ar.exception);
1372 } else {
1373 loge("isVoNrEnabled: Unknown exception");
1374 }
1375 }
1376 notifyRequester(request);
1377 break;
1378
Sooraj Sasindran37444802020-08-11 10:40:43 -07001379 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1380 request = (MainThreadRequest) msg.obj;
1381 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1382 Phone phone = getPhoneFromRequest(request);
1383 if (phone != null) {
1384 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1385 request.workSource);
1386 } else {
1387 loge("enableNrDualConnectivity: No phone object");
1388 request.result =
1389 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1390 notifyRequester(request);
1391 }
1392 break;
1393 }
1394
1395 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1396 ar = (AsyncResult) msg.obj;
1397 request = (MainThreadRequest) ar.userObj;
1398 if (ar.exception == null) {
1399 request.result =
1400 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1401 } else {
1402 request.result =
1403 TelephonyManager
1404 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1405 if (ar.exception instanceof CommandException) {
1406 CommandException.Error error =
1407 ((CommandException) (ar.exception)).getCommandError();
1408 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1409 request.result =
1410 TelephonyManager
1411 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001412 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1413 request.result =
1414 TelephonyManager
1415 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001416 }
1417 loge("enableNrDualConnectivity" + ": CommandException: "
1418 + ar.exception);
1419 } else {
1420 loge("enableNrDualConnectivity" + ": Unknown exception");
1421 }
1422 }
1423 notifyRequester(request);
1424 break;
1425 }
1426
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001427 case CMD_ENABLE_VONR: {
1428 request = (MainThreadRequest) msg.obj;
1429 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1430 Phone phone = getPhoneFromRequest(request);
1431 if (phone != null) {
1432 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1433 request.workSource);
1434 } else {
1435 loge("setVoNrEnabled: No phone object");
1436 request.result =
1437 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1438 notifyRequester(request);
1439 }
1440 break;
1441 }
1442
1443 case EVENT_ENABLE_VONR_DONE: {
1444 ar = (AsyncResult) msg.obj;
1445 request = (MainThreadRequest) ar.userObj;
1446 if (ar.exception == null) {
1447 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1448 } else {
1449 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1450 if (ar.exception instanceof CommandException) {
1451 CommandException.Error error =
1452 ((CommandException) (ar.exception)).getCommandError();
1453 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1454 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1455 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1456 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1457 } else {
1458 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1459 }
1460 loge("setVoNrEnabled" + ": CommandException: "
1461 + ar.exception);
1462 } else {
1463 loge("setVoNrEnabled" + ": Unknown exception");
1464 }
1465 }
1466 notifyRequester(request);
1467 break;
1468 }
1469
SongFerngWang3ef3e072020-12-21 16:41:52 +08001470 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001471 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001472 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1473 request);
1474 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001475 break;
1476
SongFerngWang3ef3e072020-12-21 16:41:52 +08001477 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001478 ar = (AsyncResult) msg.obj;
1479 request = (MainThreadRequest) ar.userObj;
1480 if (ar.exception == null && ar.result != null) {
1481 request.result = ar.result; // Integer
1482 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301483 // request.result must be set to something non-null
1484 // for the calling thread to unblock
1485 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001486 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001487 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001488 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001489 loge("getAllowedNetworkTypesBitmask: CommandException: "
1490 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001491 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001492 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001493 }
1494 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001495 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001496 break;
1497
SongFerngWang3ef3e072020-12-21 16:41:52 +08001498 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001499 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001500 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1501 request);
1502 Pair<Integer, Long> reasonWithNetworkTypes =
1503 (Pair<Integer, Long>) request.argument;
1504 getPhoneFromRequest(request).setAllowedNetworkTypes(
1505 reasonWithNetworkTypes.first,
1506 reasonWithNetworkTypes.second,
1507 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001508 break;
1509
SongFerngWang3ef3e072020-12-21 16:41:52 +08001510 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1511 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001512 break;
1513
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001514 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1515 request = (MainThreadRequest)msg.obj;
1516 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001517 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001518 break;
1519
1520 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1521 ar = (AsyncResult)msg.obj;
1522 request = (MainThreadRequest)ar.userObj;
1523 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001524 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001525 break;
1526
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001527 case CMD_SET_VOICEMAIL_NUMBER:
1528 request = (MainThreadRequest) msg.obj;
1529 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1530 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001531 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1532 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001533 break;
1534
1535 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1536 handleNullReturnEvent(msg, "setVoicemailNumber");
1537 break;
1538
Stuart Scott54788802015-03-30 13:18:01 -07001539 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1540 request = (MainThreadRequest) msg.obj;
1541 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1542 request);
1543 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1544 break;
1545
1546 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1547 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1548 break;
1549
Shishir Agrawal302c8692015-06-19 13:49:39 -07001550 case CMD_PERFORM_NETWORK_SCAN:
1551 request = (MainThreadRequest) msg.obj;
1552 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1553 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1554 break;
1555
Hall Liu27d24262020-09-18 19:04:59 -07001556 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001557 request = (MainThreadRequest) msg.obj;
1558 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001559 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1560 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1561 request.argument;
1562 int callForwardingReason = args.first;
1563 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001564 break;
Hall Liu27d24262020-09-18 19:04:59 -07001565 }
1566 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001567 ar = (AsyncResult) msg.obj;
1568 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001569 TelephonyManager.CallForwardingInfoCallback callback =
1570 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1571 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001572 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001573 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001574 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1575 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1576 // Service Class is a bit mask per 3gpp 27.007. Search for
1577 // any service for voice call.
1578 if ((callForwardInfo.serviceClass
1579 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001580 callForwardingInfo = new CallForwardingInfo(
1581 callForwardInfo.status
1582 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001583 callForwardInfo.reason,
1584 callForwardInfo.number,
1585 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001586 break;
1587 }
1588 }
1589 // Didn't find a call forward info for voice call.
1590 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001591 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1592 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001593 }
Hall Liu27d24262020-09-18 19:04:59 -07001594 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001595 } else {
1596 if (ar.result == null) {
1597 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1598 }
1599 if (ar.exception != null) {
1600 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1601 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001602 int errorCode = TelephonyManager
1603 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001604 if (ar.exception instanceof CommandException) {
1605 CommandException.Error error =
1606 ((CommandException) (ar.exception)).getCommandError();
1607 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001608 errorCode = TelephonyManager
1609 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001610 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001611 errorCode = TelephonyManager
1612 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001613 }
1614 }
Hall Liu27d24262020-09-18 19:04:59 -07001615 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001616 }
Shuo Qian4a594052020-01-23 11:59:30 -08001617 break;
Hall Liu27d24262020-09-18 19:04:59 -07001618 }
Shuo Qian4a594052020-01-23 11:59:30 -08001619
Hall Liu27d24262020-09-18 19:04:59 -07001620 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001621 request = (MainThreadRequest) msg.obj;
1622 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001623 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001624 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001625 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1626 request.argument).first;
1627 request.phone.setCallForwardingOption(
1628 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001629 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001630 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001631 callForwardingInfoToSet.getReason(),
1632 callForwardingInfoToSet.getNumber(),
1633 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1634 break;
Hall Liu27d24262020-09-18 19:04:59 -07001635 }
Shuo Qian4a594052020-01-23 11:59:30 -08001636
Hall Liu27d24262020-09-18 19:04:59 -07001637 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001638 ar = (AsyncResult) msg.obj;
1639 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001640 Consumer<Integer> callback =
1641 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1642 request.argument).second;
1643 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001644 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001645 int errorCode = TelephonyManager.CallForwardingInfoCallback
1646 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001647 if (ar.exception instanceof CommandException) {
1648 CommandException.Error error =
1649 ((CommandException) (ar.exception)).getCommandError();
1650 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001651 errorCode = TelephonyManager.CallForwardingInfoCallback
1652 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001653 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001654 errorCode = TelephonyManager.CallForwardingInfoCallback
1655 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001656 }
1657 }
1658 callback.accept(errorCode);
1659 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001660 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001661 }
Shuo Qian4a594052020-01-23 11:59:30 -08001662 break;
Hall Liu27d24262020-09-18 19:04:59 -07001663 }
Shuo Qian4a594052020-01-23 11:59:30 -08001664
Hall Liu27d24262020-09-18 19:04:59 -07001665 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001666 request = (MainThreadRequest) msg.obj;
1667 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1668 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1669 break;
Hall Liu27d24262020-09-18 19:04:59 -07001670 }
Shuo Qian4a594052020-01-23 11:59:30 -08001671
Hall Liu27d24262020-09-18 19:04:59 -07001672 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001673 ar = (AsyncResult) msg.obj;
1674 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001675 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001676 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001677 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001678 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001679 // Service Class is a bit mask per 3gpp 27.007.
1680 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001681 if (callForwardResults.length > 1
1682 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001683 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001684 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001685 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1686 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001687 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001688 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001689 }
1690 } else {
1691 if (ar.result == null) {
1692 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1693 }
1694 if (ar.exception != null) {
1695 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1696 }
1697 if (ar.exception instanceof CommandException) {
1698 CommandException.Error error =
1699 ((CommandException) (ar.exception)).getCommandError();
1700 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001701 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001702 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001703 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1704 callWaitingStatus =
1705 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001706 }
1707 }
1708 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001709 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001710 break;
Hall Liu27d24262020-09-18 19:04:59 -07001711 }
Shuo Qian4a594052020-01-23 11:59:30 -08001712
Hall Liu27d24262020-09-18 19:04:59 -07001713 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001714 request = (MainThreadRequest) msg.obj;
1715 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001716 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1717 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001718 break;
Hall Liu27d24262020-09-18 19:04:59 -07001719 }
Shuo Qian4a594052020-01-23 11:59:30 -08001720
Hall Liu27d24262020-09-18 19:04:59 -07001721 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001722 ar = (AsyncResult) msg.obj;
1723 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001724 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1725 Consumer<Integer> callback =
1726 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1727 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001728 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001729 if (ar.exception instanceof CommandException) {
1730 CommandException.Error error =
1731 ((CommandException) (ar.exception)).getCommandError();
1732 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1733 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001734 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1735 callback.accept(
1736 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001737 } else {
1738 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1739 }
1740 } else {
1741 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1742 }
1743 } else {
1744 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1745 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001746 }
Shuo Qian4a594052020-01-23 11:59:30 -08001747 break;
Hall Liu27d24262020-09-18 19:04:59 -07001748 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001749 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1750 ar = (AsyncResult) msg.obj;
1751 request = (MainThreadRequest) ar.userObj;
1752 CellNetworkScanResult cellScanResult;
1753 if (ar.exception == null && ar.result != null) {
1754 cellScanResult = new CellNetworkScanResult(
1755 CellNetworkScanResult.STATUS_SUCCESS,
1756 (List<OperatorInfo>) ar.result);
1757 } else {
1758 if (ar.result == null) {
1759 loge("getCellNetworkScanResults: Empty response");
1760 }
1761 if (ar.exception != null) {
1762 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1763 }
1764 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1765 if (ar.exception instanceof CommandException) {
1766 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001767 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001768 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1769 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1770 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1771 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1772 }
1773 }
1774 cellScanResult = new CellNetworkScanResult(errorCode, null);
1775 }
1776 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001777 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001778 break;
1779
1780 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1781 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001782 ManualNetworkSelectionArgument selArg =
1783 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001784 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1785 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001786 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1787 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001788 break;
1789
1790 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001791 ar = (AsyncResult) msg.obj;
1792 request = (MainThreadRequest) ar.userObj;
1793 if (ar.exception == null) {
1794 request.result = true;
1795 } else {
1796 request.result = false;
1797 loge("setNetworkSelectionModeManual " + ar.exception);
1798 }
1799 notifyRequester(request);
1800 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001801 break;
1802
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001803 case CMD_GET_MODEM_ACTIVITY_INFO:
1804 request = (MainThreadRequest) msg.obj;
1805 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001806 if (defaultPhone != null) {
1807 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001808 } else {
1809 ResultReceiver result = (ResultReceiver) request.argument;
1810 Bundle bundle = new Bundle();
1811 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001812 new ModemActivityInfo(0, 0, 0,
1813 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001814 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001815 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001816 break;
1817
Hall Liud0f208c2020-10-14 16:54:44 -07001818 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001819 ar = (AsyncResult) msg.obj;
1820 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001821 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001822 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001823 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001824 if (mLastModemActivityInfo == null) {
1825 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1826 mLastModemActivitySpecificInfo[0] =
1827 new ActivityStatsTechSpecificInfo(
1828 0,
1829 0,
1830 new int[ModemActivityInfo.getNumTxPowerLevels()],
1831 0);
1832 mLastModemActivityInfo =
1833 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1834 }
1835
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001836 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001837 // Update the last modem activity info and the result of the request.
1838 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1839 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001840 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001841 } else {
1842 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001843 }
Kai Shi917fdc62022-11-28 14:01:02 -08001844 // This is needed to decouple ret from mLastModemActivityInfo
1845 // We don't want to return mLastModemActivityInfo which is updated
1846 // inside mergeModemActivityInfo()
1847 ret = new ModemActivityInfo(
1848 mLastModemActivityInfo.getTimestampMillis(),
1849 mLastModemActivityInfo.getSleepTimeMillis(),
1850 mLastModemActivityInfo.getIdleTimeMillis(),
1851 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001852
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001853 } else {
1854 if (ar.result == null) {
1855 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001856 error = TelephonyManager.ModemActivityInfoException
1857 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001858 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001859 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001860 error = TelephonyManager.ModemActivityInfoException
1861 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001862 } else {
1863 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001864 error = TelephonyManager.ModemActivityInfoException
1865 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001866 }
1867 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001868 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001869 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001870 bundle.putParcelable(
1871 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001872 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001873 } else {
1874 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1875 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001876 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001877 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001878 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001879 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001880
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001881 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001882 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001883 CarrierRestrictionRules argument =
1884 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001885 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001886 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001887 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001888 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001889
1890 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1891 ar = (AsyncResult) msg.obj;
1892 request = (MainThreadRequest) ar.userObj;
1893 if (ar.exception == null && ar.result != null) {
1894 request.result = ar.result;
1895 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001896 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1897 if (ar.exception instanceof CommandException) {
1898 loge("setAllowedCarriers: CommandException: " + ar.exception);
1899 CommandException.Error error =
1900 ((CommandException) (ar.exception)).getCommandError();
1901 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1902 request.result =
1903 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1904 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001905 } else {
1906 loge("setAllowedCarriers: Unknown exception");
1907 }
1908 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001909 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001910 break;
1911
1912 case CMD_GET_ALLOWED_CARRIERS:
1913 request = (MainThreadRequest) msg.obj;
1914 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001915 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001916 break;
1917
1918 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1919 ar = (AsyncResult) msg.obj;
1920 request = (MainThreadRequest) ar.userObj;
1921 if (ar.exception == null && ar.result != null) {
1922 request.result = ar.result;
1923 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001924 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001925 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001926 if (ar.result == null) {
1927 loge("getAllowedCarriers: Empty response");
1928 } else if (ar.exception instanceof CommandException) {
1929 loge("getAllowedCarriers: CommandException: " +
1930 ar.exception);
1931 } else {
1932 loge("getAllowedCarriers: Unknown exception");
1933 }
1934 }
arunvoddud7401012022-12-15 16:08:12 +00001935 if (request.argument != null) {
1936 // This is for the implementation of carrierRestrictionStatus.
1937 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1938 Consumer<Integer> callback = callbackInfo.getConsumer();
1939 int callerCarrierId = callbackInfo.getCarrierId();
1940 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1941 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1942 CarrierRestrictionRules carrierRestrictionRules =
1943 (CarrierRestrictionRules) ar.result;
1944 int carrierId = -1;
1945 try {
1946 CarrierIdentifier carrierIdentifier =
1947 carrierRestrictionRules.getAllowedCarriers().get(0);
1948 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1949 carrierIdentifier);
1950 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1951 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1952 }
1953 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1954 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1955 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001956 lockStatus = TelephonyManager
1957 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001958 }
1959 } else {
1960 Rlog.e(LOG_TAG,
1961 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1962 }
1963 callback.accept(lockStatus);
1964 } else {
1965 // This is for the implementation of getAllowedCarriers.
1966 notifyRequester(request);
1967 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001968 break;
1969
Nathan Haroldb3014052017-01-25 15:57:32 -08001970 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1971 ar = (AsyncResult) msg.obj;
1972 request = (MainThreadRequest) ar.userObj;
1973 if (ar.exception == null && ar.result != null) {
1974 request.result = ar.result;
1975 } else {
1976 request.result = new IllegalArgumentException(
1977 "Failed to retrieve Forbidden Plmns");
1978 if (ar.result == null) {
1979 loge("getForbiddenPlmns: Empty response");
1980 } else {
1981 loge("getForbiddenPlmns: Unknown exception");
1982 }
1983 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001984 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001985 break;
1986
1987 case CMD_GET_FORBIDDEN_PLMNS:
1988 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001989 uiccPort = getUiccPortFromRequest(request);
1990 if (uiccPort == null) {
1991 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001992 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001993 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001994 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001995 break;
1996 }
1997 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001998 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001999 if (uiccApp == null) {
2000 loge("getForbiddenPlmns() no app with specified type -- "
2001 + appType);
2002 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07002003 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08002004 break;
2005 } else {
2006 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
2007 + " specified type -- " + appType);
2008 }
2009 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
2010 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002011 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08002012 break;
2013
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00002014 case CMD_SWITCH_SLOTS:
2015 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00002016 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00002017 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00002018 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00002019 break;
2020
2021 case EVENT_SWITCH_SLOTS_DONE:
2022 ar = (AsyncResult) msg.obj;
2023 request = (MainThreadRequest) ar.userObj;
2024 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07002025 notifyRequester(request);
2026 break;
2027 case CMD_GET_NETWORK_SELECTION_MODE:
2028 request = (MainThreadRequest) msg.obj;
2029 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
2030 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
2031 break;
2032
2033 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
2034 ar = (AsyncResult) msg.obj;
2035 request = (MainThreadRequest) ar.userObj;
2036 if (ar.exception != null) {
2037 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2038 } else {
2039 int mode = ((int[]) ar.result)[0];
2040 if (mode == 0) {
2041 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
2042 } else {
2043 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
2044 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00002045 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002046 notifyRequester(request);
2047 break;
2048 case CMD_GET_CDMA_ROAMING_MODE:
2049 request = (MainThreadRequest) msg.obj;
2050 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
2051 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
2052 break;
2053 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
2054 ar = (AsyncResult) msg.obj;
2055 request = (MainThreadRequest) ar.userObj;
2056 if (ar.exception != null) {
2057 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
2058 } else {
2059 request.result = ((int[]) ar.result)[0];
2060 }
2061 notifyRequester(request);
2062 break;
2063 case CMD_SET_CDMA_ROAMING_MODE:
2064 request = (MainThreadRequest) msg.obj;
2065 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
2066 int mode = (int) request.argument;
2067 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
2068 break;
2069 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
2070 ar = (AsyncResult) msg.obj;
2071 request = (MainThreadRequest) ar.userObj;
2072 request.result = ar.exception == null;
2073 notifyRequester(request);
2074 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07002075 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
2076 request = (MainThreadRequest) msg.obj;
2077 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
2078 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
2079 break;
2080 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
2081 ar = (AsyncResult) msg.obj;
2082 request = (MainThreadRequest) ar.userObj;
2083 if (ar.exception != null) {
2084 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
2085 } else {
2086 request.result = ((int[]) ar.result)[0];
2087 }
2088 notifyRequester(request);
2089 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07002090 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
2091 request = (MainThreadRequest) msg.obj;
2092 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
2093 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07002094 getPhoneFromRequest(request).setCdmaSubscriptionMode(
2095 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07002096 break;
2097 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
2098 ar = (AsyncResult) msg.obj;
2099 request = (MainThreadRequest) ar.userObj;
2100 request.result = ar.exception == null;
2101 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00002102 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07002103 case CMD_GET_ALL_CELL_INFO:
2104 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07002105 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07002106 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07002107 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07002108 case EVENT_GET_ALL_CELL_INFO_DONE:
2109 ar = (AsyncResult) msg.obj;
2110 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07002111 // If a timeout occurs, the response will be null
2112 request.result = (ar.exception == null && ar.result != null)
2113 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07002114 synchronized (request) {
2115 request.notifyAll();
2116 }
2117 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002118 case CMD_REQUEST_CELL_INFO_UPDATE:
2119 request = (MainThreadRequest) msg.obj;
2120 request.phone.requestCellInfoUpdate(request.workSource,
2121 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
2122 break;
2123 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
2124 ar = (AsyncResult) msg.obj;
2125 request = (MainThreadRequest) ar.userObj;
2126 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
2127 try {
2128 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002129 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07002130 cb.onError(
2131 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
2132 ar.exception.getClass().getName(),
2133 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002134 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002135 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07002136 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002137 } else {
2138 // use the result as returned
2139 cb.onCellInfo((List<CellInfo>) ar.result);
2140 }
2141 } catch (RemoteException re) {
2142 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
2143 }
2144 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08002145 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07002146 request = (MainThreadRequest) msg.obj;
2147 WorkSource ws = (WorkSource) request.argument;
2148 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08002149 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07002150 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08002151 }
2152 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07002153 ar = (AsyncResult) msg.obj;
2154 request = (MainThreadRequest) ar.userObj;
2155 if (ar.exception == null) {
2156 request.result = ar.result;
2157 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08002158 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07002159 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08002160 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07002161 }
2162
2163 synchronized (request) {
2164 request.notifyAll();
2165 }
2166 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08002167 }
chen xu6dac5ab2018-10-26 17:39:23 -07002168 case CMD_MODEM_REBOOT:
2169 request = (MainThreadRequest) msg.obj;
2170 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002171 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07002172 break;
chen xu6dac5ab2018-10-26 17:39:23 -07002173 case EVENT_CMD_MODEM_REBOOT_DONE:
2174 handleNullReturnEvent(msg, "rebootModem");
2175 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002176 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002177 request = (MainThreadRequest) msg.obj;
2178 boolean enable = (boolean) request.argument;
2179 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08002180 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002181 PhoneConfigurationManager.getInstance()
2182 .enablePhone(request.phone, enable, onCompleted);
2183 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002184 }
Michele Berionne5e411512020-11-13 02:36:59 +00002185 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002186 ar = (AsyncResult) msg.obj;
2187 request = (MainThreadRequest) ar.userObj;
2188 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07002189 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08002190 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07002191 if ((boolean) request.result) {
2192 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
2193 updateModemStateMetrics();
2194 } else {
2195 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
2196 + ar.exception);
2197 }
2198 notifyRequester(request);
2199 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002200 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07002201 case CMD_GET_MODEM_STATUS:
2202 request = (MainThreadRequest) msg.obj;
2203 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
2204 PhoneConfigurationManager.getInstance()
2205 .getPhoneStatusFromModem(request.phone, onCompleted);
2206 break;
2207 case EVENT_GET_MODEM_STATUS_DONE:
2208 ar = (AsyncResult) msg.obj;
2209 request = (MainThreadRequest) ar.userObj;
2210 int id = request.phone.getPhoneId();
2211 if (ar.exception == null && ar.result != null) {
2212 request.result = ar.result;
2213 //update the cache as modem status has changed
2214 mPhoneConfigurationManager.addToPhoneStatusCache(id,
2215 (boolean) request.result);
2216 } else {
2217 // Return true if modem status cannot be retrieved. For most cases,
2218 // modem status is on. And for older version modems, GET_MODEM_STATUS
2219 // and disable modem are not supported. Modem is always on.
2220 // TODO: this should be fixed in R to support a third
2221 // status UNKNOWN b/131631629
2222 request.result = true;
2223 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
2224 + ar.exception);
2225 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002226 notifyRequester(request);
2227 break;
Hall Liu73f5d362020-01-20 13:42:00 -08002228 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
2229 request = (MainThreadRequest) msg.obj;
2230 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
2231 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
2232 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
2233 request.phone.setSystemSelectionChannels(args.first, onCompleted);
2234 break;
2235 }
2236 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
2237 ar = (AsyncResult) msg.obj;
2238 request = (MainThreadRequest) ar.userObj;
2239 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
2240 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
2241 args.second.accept(ar.exception == null);
2242 notifyRequester(request);
2243 break;
2244 }
Sarah Chin679c08a2020-11-18 13:39:35 -08002245 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
2246 request = (MainThreadRequest) msg.obj;
2247 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
2248 Phone phone = getPhoneFromRequest(request);
2249 if (phone != null) {
2250 phone.getSystemSelectionChannels(onCompleted);
2251 } else {
2252 loge("getSystemSelectionChannels: No phone object");
2253 request.result = new ArrayList<RadioAccessSpecifier>();
2254 notifyRequester(request);
2255 }
2256 break;
2257 }
2258 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
2259 ar = (AsyncResult) msg.obj;
2260 request = (MainThreadRequest) ar.userObj;
2261 if (ar.exception == null && ar.result != null) {
2262 request.result = ar.result;
2263 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08002264 request.result = new IllegalStateException(
2265 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08002266 if (ar.result == null) {
2267 loge("getSystemSelectionChannels: Empty response");
2268 } else {
2269 loge("getSystemSelectionChannels: Unknown exception");
2270 }
2271 }
2272 notifyRequester(request);
2273 break;
yincheng zhao2737e882019-09-06 17:06:54 -07002274 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
2275 ar = (AsyncResult) msg.obj;
2276 request = (MainThreadRequest) ar.userObj;
2277 if (ar.exception == null && ar.result != null) {
2278 request.result = ar.result;
2279 } else {
2280 request.result = -1;
2281 loge("Failed to set Forbidden Plmns");
2282 if (ar.result == null) {
2283 loge("setForbidenPlmns: Empty response");
2284 } else if (ar.exception != null) {
2285 loge("setForbiddenPlmns: Exception: " + ar.exception);
2286 request.result = -1;
2287 } else {
2288 loge("setForbiddenPlmns: Unknown exception");
2289 }
2290 }
2291 notifyRequester(request);
2292 break;
2293 case CMD_SET_FORBIDDEN_PLMNS:
2294 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002295 uiccPort = getUiccPortFromRequest(request);
2296 if (uiccPort == null) {
2297 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07002298 request.result = -1;
2299 notifyRequester(request);
2300 break;
2301 }
2302 Pair<Integer, List<String>> setFplmnsArgs =
2303 (Pair<Integer, List<String>>) request.argument;
2304 appType = setFplmnsArgs.first;
2305 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002306 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07002307 if (uiccApp == null) {
2308 loge("setForbiddenPlmns: no app with specified type -- " + appType);
2309 request.result = -1;
2310 loge("Failed to get UICC App");
2311 notifyRequester(request);
2312 } else {
2313 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
2314 ((SIMRecords) uiccApp.getIccRecords())
2315 .setForbiddenPlmns(onCompleted, fplmns);
2316 }
yinchengzhao4d163c02019-12-12 15:21:47 -08002317 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07002318 case CMD_ERASE_MODEM_CONFIG:
2319 request = (MainThreadRequest) msg.obj;
2320 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
2321 defaultPhone.eraseModemConfig(onCompleted);
2322 break;
2323 case EVENT_ERASE_MODEM_CONFIG_DONE:
2324 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07002325 break;
zoey chene02881a2019-12-30 16:11:23 +08002326
Kai Shif70f46f2021-03-03 13:59:46 -08002327 case CMD_ERASE_DATA_SHARED_PREFERENCES:
2328 request = (MainThreadRequest) msg.obj;
2329 request.result = defaultPhone.eraseDataInSharedPreferences();
2330 notifyRequester(request);
2331 break;
2332
zoey chene02881a2019-12-30 16:11:23 +08002333 case CMD_CHANGE_ICC_LOCK_PASSWORD:
2334 request = (MainThreadRequest) msg.obj;
2335 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
2336 Pair<String, String> changed = (Pair<String, String>) request.argument;
2337 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
2338 changed.first, changed.second, onCompleted);
2339 break;
2340 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2341 ar = (AsyncResult) msg.obj;
2342 request = (MainThreadRequest) ar.userObj;
2343 if (ar.exception == null) {
2344 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002345 // If the operation is successful, update the PIN storage
2346 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2347 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002348 UiccController.getInstance().getPinStorage()
2349 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002350 } else {
2351 request.result = msg.arg1;
2352 }
2353 notifyRequester(request);
2354 break;
2355
Michele Berionne5e411512020-11-13 02:36:59 +00002356 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002357 request = (MainThreadRequest) msg.obj;
2358 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2359 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2360 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2361 enabled.first, enabled.second, onCompleted);
2362 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002363 }
zoey chene02881a2019-12-30 16:11:23 +08002364 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2365 ar = (AsyncResult) msg.obj;
2366 request = (MainThreadRequest) ar.userObj;
2367 if (ar.exception == null) {
2368 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002369 // If the operation is successful, update the PIN storage
2370 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2371 int phoneId = getPhoneFromRequest(request).getPhoneId();
2372 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002373 UiccController.getInstance().getPinStorage()
2374 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002375 } else {
2376 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2377 }
zoey chene02881a2019-12-30 16:11:23 +08002378 } else {
2379 request.result = msg.arg1;
2380 }
Michele Berionne5e411512020-11-13 02:36:59 +00002381
2382
zoey chene02881a2019-12-30 16:11:23 +08002383 notifyRequester(request);
2384 break;
2385
Peter Wangdafb9ac2020-01-15 14:13:38 -08002386 case MSG_NOTIFY_USER_ACTIVITY:
2387 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002388 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002389 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2390 getDefaultPhone().getContext().sendBroadcastAsUser(
2391 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2392 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002393
2394 case CMD_SET_DATA_THROTTLING: {
2395 request = (MainThreadRequest) msg.obj;
2396 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2397 DataThrottlingRequest dataThrottlingRequest =
2398 (DataThrottlingRequest) request.argument;
2399 Phone phone = getPhoneFromRequest(request);
2400 if (phone != null) {
2401 phone.setDataThrottling(onCompleted,
2402 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2403 dataThrottlingRequest.getCompletionDurationMillis());
2404 } else {
2405 loge("setDataThrottling: No phone object");
2406 request.result =
2407 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2408 notifyRequester(request);
2409 }
2410
2411 break;
2412 }
2413 case EVENT_SET_DATA_THROTTLING_DONE:
2414 ar = (AsyncResult) msg.obj;
2415 request = (MainThreadRequest) ar.userObj;
2416
2417 if (ar.exception == null) {
2418 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2419 } else if (ar.exception instanceof CommandException) {
2420 loge("setDataThrottling: CommandException: " + ar.exception);
2421 CommandException.Error error =
2422 ((CommandException) (ar.exception)).getCommandError();
2423
2424 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2425 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002426 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002427 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2428 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002429 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2430 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002431 } else {
2432 request.result =
2433 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2434 }
2435 } else {
2436 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2437 }
2438 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2439 notifyRequester(request);
2440 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002441
2442 case CMD_SET_SIM_POWER: {
2443 request = (MainThreadRequest) msg.obj;
2444 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2445 request = (MainThreadRequest) msg.obj;
2446 int stateToSet =
2447 ((Pair<Integer, IIntegerConsumer>)
2448 request.argument).first;
2449 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2450 break;
2451 }
2452 case EVENT_SET_SIM_POWER_DONE: {
2453 ar = (AsyncResult) msg.obj;
2454 request = (MainThreadRequest) ar.userObj;
2455 IIntegerConsumer callback =
2456 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2457 if (ar.exception != null) {
2458 loge("setSimPower exception: " + ar.exception);
2459 int errorCode = TelephonyManager.CallForwardingInfoCallback
2460 .RESULT_ERROR_UNKNOWN;
2461 if (ar.exception instanceof CommandException) {
2462 CommandException.Error error =
2463 ((CommandException) (ar.exception)).getCommandError();
2464 if (error == CommandException.Error.SIM_ERR) {
2465 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2466 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2467 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2468 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2469 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2470 } else {
2471 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2472 }
2473 }
2474 try {
2475 callback.accept(errorCode);
2476 } catch (RemoteException e) {
2477 // Ignore if the remote process is no longer available to call back.
2478 Log.w(LOG_TAG, "setSimPower: callback not available.");
2479 }
2480 } else {
2481 try {
2482 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2483 } catch (RemoteException e) {
2484 // Ignore if the remote process is no longer available to call back.
2485 Log.w(LOG_TAG, "setSimPower: callback not available.");
2486 }
2487 }
2488 break;
2489 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002490 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2491 request = (MainThreadRequest) msg.obj;
2492
2493 final Phone phone = getPhoneFromRequest(request);
2494 if (phone == null || phone.getServiceStateTracker() == null) {
2495 request.result = new IllegalStateException("Phone or SST is null");
2496 notifyRequester(request);
2497 break;
2498 }
2499
2500 Pair<Integer, SignalStrengthUpdateRequest> pair =
2501 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2502 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2503 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002504 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002505 request.subId, pair.first /*callingUid*/,
2506 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002507 break;
2508 }
2509 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2510 ar = (AsyncResult) msg.obj;
2511 request = (MainThreadRequest) ar.userObj;
2512 // request.result will be the exception of ar if present, true otherwise.
2513 // Be cautious not to leave result null which will wait() forever
2514 request.result = ar.exception != null ? ar.exception : true;
2515 notifyRequester(request);
2516 break;
2517 }
2518 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2519 request = (MainThreadRequest) msg.obj;
2520
2521 Phone phone = getPhoneFromRequest(request);
2522 if (phone == null || phone.getServiceStateTracker() == null) {
2523 request.result = new IllegalStateException("Phone or SST is null");
2524 notifyRequester(request);
2525 break;
2526 }
2527
2528 Pair<Integer, SignalStrengthUpdateRequest> pair =
2529 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2530 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2531 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002532 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002533 request.subId, pair.first /*callingUid*/,
2534 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002535 break;
2536 }
2537 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2538 ar = (AsyncResult) msg.obj;
2539 request = (MainThreadRequest) ar.userObj;
2540 request.result = ar.exception != null ? ar.exception : true;
2541 notifyRequester(request);
2542 break;
2543 }
Jordan Liu109698e2020-11-24 14:50:34 -08002544
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002545 case CMD_GET_SLICING_CONFIG: {
2546 request = (MainThreadRequest) msg.obj;
2547 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2548 request.phone.getSlicingConfig(onCompleted);
2549 break;
2550 }
2551 case EVENT_GET_SLICING_CONFIG_DONE: {
2552 ar = (AsyncResult) msg.obj;
2553 request = (MainThreadRequest) ar.userObj;
2554 ResultReceiver result = (ResultReceiver) request.argument;
2555
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002556 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002557 Bundle bundle = new Bundle();
2558 int resultCode = 0;
2559 if (ar.exception != null) {
2560 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2561 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002562 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002563 } else if (ar.result == null) {
2564 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002565 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002566 } else {
2567 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002568 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2569 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002570 }
2571
2572 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002573 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002574 }
2575 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2576 result.send(resultCode, bundle);
2577 notifyRequester(request);
2578 break;
2579 }
2580
Sarah Chin71b3a852022-09-28 15:54:19 -07002581 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002582 request = (MainThreadRequest) msg.obj;
2583 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002584 PurchasePremiumCapabilityArgument arg =
2585 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002586 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chinb8218c22023-01-04 13:35:29 -08002587 arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002588 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002589 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002590
Sarah Chin71b3a852022-09-28 15:54:19 -07002591 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002592 ar = (AsyncResult) msg.obj;
2593 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002594 PurchasePremiumCapabilityArgument arg =
2595 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002596 try {
2597 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002598 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002599 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002600 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002601 + ", result= "
2602 + TelephonyManager.convertPurchaseResultToString(result));
2603 } catch (RemoteException e) {
2604 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002605 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002606 + " failed: " + e;
2607 if (DBG) log(logStr);
2608 AnomalyReporter.reportAnomaly(
2609 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2610 }
2611 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002612 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002613
Michele Berionne5e411512020-11-13 02:36:59 +00002614 case CMD_PREPARE_UNATTENDED_REBOOT:
2615 request = (MainThreadRequest) msg.obj;
2616 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002617 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002618 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002619 notifyRequester(request);
2620 break;
2621
Sarah Chineccfbd12023-01-20 19:00:35 -08002622 case CMD_START_SATELLITE_POSITION_UPDATES: {
2623 request = (MainThreadRequest) msg.obj;
2624 onCompleted =
2625 obtainMessage(EVENT_START_SATELLITE_POSITION_UPDATES_DONE, request);
Sarah Chin4beb2b72023-02-14 14:47:54 -08002626 if (mIsSatelliteServiceSupported) {
2627 mSatelliteServiceController.startSendingSatellitePointingInfo(onCompleted);
2628 break;
2629 }
Sarah Chineccfbd12023-01-20 19:00:35 -08002630 Phone phone = getPhoneFromRequest(request);
2631 if (phone != null) {
2632 phone.startSatellitePositionUpdates(onCompleted);
2633 } else {
2634 loge("startSatellitePositionUpdates: No phone object");
Thomas Nguyen299d6cd2023-02-14 09:57:15 -08002635 SatellitePositionUpdateArgument arg =
2636 (SatellitePositionUpdateArgument) request.argument;
2637 arg.errorCallback.accept(
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002638 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Sarah Chineccfbd12023-01-20 19:00:35 -08002639 }
2640 break;
2641 }
2642
2643 case EVENT_START_SATELLITE_POSITION_UPDATES_DONE: {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -08002644 handleStartSatellitePositionUpdatesDone((AsyncResult) msg.obj);
Sarah Chineccfbd12023-01-20 19:00:35 -08002645 break;
2646 }
2647
2648 case CMD_STOP_SATELLITE_POSITION_UPDATES: {
2649 request = (MainThreadRequest) msg.obj;
2650 onCompleted =
2651 obtainMessage(EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE, request);
Sarah Chin4beb2b72023-02-14 14:47:54 -08002652 if (mIsSatelliteServiceSupported) {
2653 mSatelliteServiceController.stopSendingSatellitePointingInfo(onCompleted);
2654 break;
2655 }
Sarah Chineccfbd12023-01-20 19:00:35 -08002656 Phone phone = getPhoneFromRequest(request);
2657 if (phone != null) {
2658 phone.stopSatellitePositionUpdates(onCompleted);
2659 } else {
2660 loge("stopSatellitePositionUpdates: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002661 ((Consumer<Integer>) request.argument).accept(
2662 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Sarah Chineccfbd12023-01-20 19:00:35 -08002663 }
2664 break;
2665 }
2666
2667 case EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE: {
2668 ar = (AsyncResult) msg.obj;
2669 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002670 int error = getSatelliteError(ar, "stopSatellitePositionUpdates", false);
2671 ((Consumer<Integer>) request.argument).accept(error);
Sarah Chineccfbd12023-01-20 19:00:35 -08002672 break;
2673 }
2674
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002675 case CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG: {
2676 request = (MainThreadRequest) msg.obj;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002677 onCompleted =
2678 obtainMessage(EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE, request);
2679 if (mIsSatelliteServiceSupported) {
2680 mSatelliteServiceController
2681 .requestMaxCharactersPerMOTextMessage(onCompleted);
2682 break;
2683 }
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002684 Phone phone = getPhoneFromRequest(request);
2685 if (phone != null) {
2686 phone.getMaxCharactersPerSatelliteTextMessage(onCompleted);
2687 } else {
2688 loge("getMaxCharactersPerSatelliteTextMessage: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002689 ((ResultReceiver) request.argument).send(
2690 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002691 }
2692 break;
2693 }
2694
2695 case EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE: {
2696 ar = (AsyncResult) msg.obj;
2697 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002698 int error =
2699 getSatelliteError(ar, "getMaxCharactersPerSatelliteTextMessage", true);
2700 Bundle bundle = new Bundle();
2701 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002702 int maxCharLimit = ((int[]) ar.result)[0];
Sarah Chin503828c2023-02-01 23:54:20 -08002703 if (DBG) log("getMaxCharactersPerSatelliteTextMessage: " + maxCharLimit);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002704 bundle.putInt(SatelliteManager.KEY_MAX_CHARACTERS_PER_SATELLITE_TEXT,
2705 maxCharLimit);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002706 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002707 ((ResultReceiver) request.argument).send(error, bundle);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002708 break;
2709 }
2710
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002711 case CMD_PROVISION_SATELLITE_SERVICE: {
2712 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002713 ProvisionSatelliteServiceArgument argument =
2714 (ProvisionSatelliteServiceArgument) request.argument;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002715 if (mSatelliteProvisionCallbacks.containsKey(argument.subId)) {
2716 argument.callback.accept(
2717 SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS);
2718 notifyRequester(request);
2719 break;
2720 }
2721 mSatelliteProvisionCallbacks.put(argument.subId, argument.callback);
2722 onCompleted = obtainMessage(EVENT_PROVISION_SATELLITE_SERVICE_DONE, request);
2723 if (mIsSatelliteServiceSupported) {
2724 mSatelliteServiceController
2725 .provisionSatelliteService(argument.token, onCompleted);
2726 break;
2727 }
2728 Phone phone = getPhoneFromRequest(request);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002729 if (phone != null) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08002730 phone.provisionSatelliteService(onCompleted, argument.token);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002731 } else {
2732 loge("provisionSatelliteService: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002733 argument.callback.accept(
2734 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002735 notifyRequester(request);
2736 }
2737 break;
2738 }
2739
2740 case EVENT_PROVISION_SATELLITE_SERVICE_DONE: {
2741 ar = (AsyncResult) msg.obj;
2742 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002743 int errorCode = getSatelliteError(ar, "provisionSatelliteService", false);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002744 handleEventProvisionSatelliteServiceDone(
2745 (ProvisionSatelliteServiceArgument) request.argument, errorCode);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002746 notifyRequester(request);
2747 break;
2748 }
2749
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002750 case CMD_DEPROVISION_SATELLITE_SERVICE: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002751 request = (MainThreadRequest) msg.obj;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002752 ProvisionSatelliteServiceArgument argument =
2753 (ProvisionSatelliteServiceArgument) request.argument;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002754 onCompleted = obtainMessage(EVENT_DEPROVISION_SATELLITE_SERVICE_DONE, request);
2755 if (mIsSatelliteServiceSupported) {
2756 mSatelliteServiceController
2757 .deprovisionSatelliteService(argument.token, onCompleted);
2758 break;
2759 }
2760 Phone phone = getPhoneFromRequest(request);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002761 if (phone != null) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08002762 phone.deprovisionSatelliteService(onCompleted, argument.token);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002763 } else {
2764 loge("deprovisionSatelliteService: No phone object");
2765 if (argument.callback != null) {
2766 argument.callback.accept(
2767 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
2768 }
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002769 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002770 break;
2771 }
2772
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002773 case EVENT_DEPROVISION_SATELLITE_SERVICE_DONE: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002774 ar = (AsyncResult) msg.obj;
2775 request = (MainThreadRequest) ar.userObj;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002776 int errorCode = getSatelliteError(ar, "deprovisionSatelliteService", false);
2777 handleEventDeprovisionSatelliteServiceDone(
2778 (ProvisionSatelliteServiceArgument) request.argument, errorCode);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002779 break;
2780 }
2781
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002782 case CMD_SET_SATELLITE_ENABLED: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002783 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002784 Pair<Boolean, Consumer<Integer>> argument =
2785 (Pair<Boolean, Consumer<Integer>>) request.argument;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002786 onCompleted = obtainMessage(EVENT_SET_SATELLITE_ENABLED_DONE, request);
2787 if (mIsSatelliteServiceSupported) {
2788 mSatelliteServiceController
2789 .requestSatelliteEnabled(argument.first, onCompleted);
2790 break;
2791 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002792 Phone phone = getPhoneFromRequest(request);
2793 if (phone != null) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08002794 phone.setSatellitePower(onCompleted, argument.first);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002795 } else {
Sarah Chin4beb2b72023-02-14 14:47:54 -08002796 loge("requestSatelliteEnabled: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002797 argument.second.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002798 }
2799 break;
2800 }
2801
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002802 case EVENT_SET_SATELLITE_ENABLED_DONE: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002803 ar = (AsyncResult) msg.obj;
2804 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002805 Pair<Boolean, Consumer<Integer>> argument =
2806 (Pair<Boolean, Consumer<Integer>>) request.argument;
2807 int error = getSatelliteError(ar, "setSatelliteEnabled", false);
2808 argument.second.accept(error);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002809 break;
2810 }
2811
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002812 case CMD_IS_SATELLITE_ENABLED: {
Sarah Chin503828c2023-02-01 23:54:20 -08002813 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002814 onCompleted = obtainMessage(EVENT_IS_SATELLITE_ENABLED_DONE, request);
Sarah Chin4beb2b72023-02-14 14:47:54 -08002815 if (mIsSatelliteServiceSupported) {
2816 mSatelliteServiceController.requestIsSatelliteEnabled(onCompleted);
2817 break;
2818 }
Sarah Chin503828c2023-02-01 23:54:20 -08002819 Phone phone = getPhoneFromRequest(request);
2820 if (phone != null) {
2821 phone.isSatellitePowerOn(onCompleted);
2822 } else {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002823 loge("isSatelliteEnabled: No phone object");
2824 ((ResultReceiver) request.argument).send(
2825 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002826 }
2827 break;
2828 }
2829
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002830 case EVENT_IS_SATELLITE_ENABLED_DONE: {
Sarah Chin503828c2023-02-01 23:54:20 -08002831 ar = (AsyncResult) msg.obj;
2832 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002833 int error = getSatelliteError(ar, "isSatelliteEnabled", true);
2834 Bundle bundle = new Bundle();
2835 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
2836 boolean enabled = ((int[]) ar.result)[0] == 1;
2837 if (DBG) log("isSatelliteEnabled: " + enabled);
2838 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_ENABLED, enabled);
Sarah Chin503828c2023-02-01 23:54:20 -08002839 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002840 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002841 break;
2842 }
2843
2844 case CMD_IS_SATELLITE_SUPPORTED: {
2845 request = (MainThreadRequest) msg.obj;
2846 onCompleted = obtainMessage(EVENT_IS_SATELLITE_SUPPORTED_DONE, request);
Sarah Chin4beb2b72023-02-14 14:47:54 -08002847 if (mIsSatelliteServiceSupported) {
2848 mSatelliteServiceController.requestIsSatelliteSupported(onCompleted);
2849 break;
2850 }
Sarah Chin503828c2023-02-01 23:54:20 -08002851 Phone phone = getPhoneFromRequest(request);
2852 if (phone != null) {
2853 phone.isSatelliteSupported(onCompleted);
2854 } else {
2855 loge("isSatelliteSupported: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002856 ((ResultReceiver) request.argument).send(
2857 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002858 }
2859 break;
2860 }
2861
2862 case EVENT_IS_SATELLITE_SUPPORTED_DONE: {
2863 ar = (AsyncResult) msg.obj;
2864 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002865 int error = getSatelliteError(ar, "isSatelliteSupported", true);
2866 Bundle bundle = new Bundle();
2867 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
2868 boolean supported = ((int[]) ar.result)[0] == 1;
2869 if (DBG) log("isSatelliteSupported: " + supported);
2870 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, supported);
Thomas Nguyene77de6d2023-02-10 17:42:43 -08002871 synchronized (mIsSatelliteSupportedLock) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002872 mIsSatelliteSupported = supported;
2873 }
2874 } else {
2875 synchronized (mIsSatelliteSupportedLock) {
2876 mIsSatelliteSupported = null;
Thomas Nguyene77de6d2023-02-10 17:42:43 -08002877 }
Sarah Chin503828c2023-02-01 23:54:20 -08002878 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002879 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002880 break;
2881 }
2882
2883 case CMD_GET_SATELLITE_CAPABILITIES: {
2884 request = (MainThreadRequest) msg.obj;
2885 onCompleted = obtainMessage(EVENT_GET_SATELLITE_CAPABILITIES_DONE, request);
Sarah Chin4beb2b72023-02-14 14:47:54 -08002886 if (mIsSatelliteServiceSupported) {
2887 mSatelliteServiceController.requestSatelliteCapabilities(onCompleted);
2888 break;
2889 }
Sarah Chin503828c2023-02-01 23:54:20 -08002890 Phone phone = getPhoneFromRequest(request);
2891 if (phone != null) {
2892 phone.getSatelliteCapabilities(onCompleted);
2893 } else {
2894 loge("getSatelliteCapabilities: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002895 ((ResultReceiver) request.argument).send(
2896 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002897 }
2898 break;
2899 }
2900
2901 case EVENT_GET_SATELLITE_CAPABILITIES_DONE: {
2902 ar = (AsyncResult) msg.obj;
2903 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002904 int error = getSatelliteError(ar, "getSatelliteCapabilities", true);
2905 Bundle bundle = new Bundle();
2906 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
Sarah Chin503828c2023-02-01 23:54:20 -08002907 SatelliteCapabilities capabilities = (SatelliteCapabilities) ar.result;
2908 if (DBG) log("getSatelliteCapabilities: " + capabilities);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002909 bundle.putParcelable(SatelliteManager.KEY_SATELLITE_CAPABILITIES,
2910 capabilities);
Sarah Chin503828c2023-02-01 23:54:20 -08002911 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002912 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002913 break;
2914 }
2915
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +00002916 case CMD_POLL_PENDING_SATELLITE_DATAGRAMS: {
2917 request = (MainThreadRequest) msg.obj;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002918 onCompleted =
2919 obtainMessage(EVENT_POLL_PENDING_SATELLITE_DATAGRAMS_DONE, request);
2920 if (mIsSatelliteServiceSupported) {
2921 mSatelliteServiceController.pollPendingSatelliteDatagrams(onCompleted);
2922 break;
2923 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +00002924 Phone phone = getPhoneFromRequest(request);
2925 if (phone != null) {
2926 phone.pollPendingSatelliteDatagrams(onCompleted);
2927 } else {
2928 loge("pollPendingSatelliteDatagrams: No phone object");
Sarah Chin4beb2b72023-02-14 14:47:54 -08002929 ((Consumer<Integer>) request.argument).accept(
2930 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +00002931 }
2932 break;
2933 }
2934
2935 case EVENT_POLL_PENDING_SATELLITE_DATAGRAMS_DONE: {
2936 ar = (AsyncResult) msg.obj;
2937 request = (MainThreadRequest) ar.userObj;
Aishwarya Mallampati224317a2023-02-13 22:09:30 +00002938 int error = getSatelliteError(ar, "pollPendingSatelliteDatagrams", false);
2939 ((Consumer<Integer>) request.argument).accept(error);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +00002940 break;
2941 }
2942
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +00002943 case CMD_SEND_SATELLITE_DATAGRAM: {
2944 request = (MainThreadRequest) msg.obj;
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +00002945 SendSatelliteDatagramArgument argument =
2946 (SendSatelliteDatagramArgument) request.argument;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002947 onCompleted = obtainMessage(EVENT_SEND_SATELLITE_DATAGRAM_DONE, request);
2948 if (mIsSatelliteServiceSupported) {
2949 // TODO: set isEmergency properly
2950 mSatelliteServiceController
2951 .sendSatelliteDatagram(argument.datagram, false, onCompleted);
2952 break;
2953 }
2954 Phone phone = getPhoneFromRequest(request);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +00002955 if (phone != null) {
2956 phone.sendSatelliteDatagram(onCompleted, argument.datagram);
2957 } else {
2958 loge("sendSatelliteDatagram: No phone object");
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +00002959 argument.result.send(
2960 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +00002961 }
2962 break;
2963 }
2964
2965 case EVENT_SEND_SATELLITE_DATAGRAM_DONE: {
2966 ar = (AsyncResult) msg.obj;
2967 request = (MainThreadRequest) ar.userObj;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002968 int error = getSatelliteError(ar, "sendSatelliteDatagram", false);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +00002969 SendSatelliteDatagramArgument argument =
2970 (SendSatelliteDatagramArgument) request.argument;
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +00002971 Bundle bundle = new Bundle();
2972 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
2973 bundle.putLong(SatelliteManager.KEY_SEND_SATELLITE_DATAGRAM,
2974 argument.datagramId);
2975 }
2976 argument.result.send(error, bundle);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +00002977 break;
2978 }
2979
Sarah Chindf715ec2023-02-13 13:46:24 -08002980 case CMD_IS_SATELLITE_COMMUNICATION_ALLOWED: {
2981 request = (MainThreadRequest) msg.obj;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002982 onCompleted =
2983 obtainMessage(EVENT_IS_SATELLITE_COMMUNICATION_ALLOWED_DONE, request);
2984 if (mIsSatelliteServiceSupported) {
2985 mSatelliteServiceController
2986 .requestIsSatelliteCommunicationAllowedForCurrentLocation(
2987 onCompleted);
2988 break;
2989 }
Sarah Chindf715ec2023-02-13 13:46:24 -08002990 Phone phone = getPhoneFromRequest(request);
2991 if (phone != null) {
2992 phone.isSatelliteCommunicationAllowedForCurrentLocation(onCompleted);
2993 } else {
2994 loge("isSatelliteCommunicationAllowedForCurrentLocation: No phone object");
2995 ((ResultReceiver) request.argument).send(
2996 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
2997 }
2998 break;
2999 }
3000
3001 case EVENT_IS_SATELLITE_COMMUNICATION_ALLOWED_DONE: {
3002 ar = (AsyncResult) msg.obj;
3003 request = (MainThreadRequest) ar.userObj;
3004 int error = getSatelliteError(
3005 ar, "isSatelliteCommunicationAllowedForCurrentLocation", true);
3006 Bundle bundle = new Bundle();
3007 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
3008 boolean communicationAllowed = ((int[]) ar.result)[0] == 1;
3009 if (DBG) {
3010 log("isSatelliteCommunicationAllowedForCurrentLocation: "
3011 + communicationAllowed);
3012 }
3013 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_COMMUNICATION_ALLOWED,
3014 communicationAllowed);
3015 }
3016 ((ResultReceiver) request.argument).send(error, bundle);
3017 break;
3018 }
3019
3020 case CMD_GET_TIME_SATELLITE_NEXT_VISIBLE: {
3021 request = (MainThreadRequest) msg.obj;
3022 onCompleted = obtainMessage(EVENT_GET_TIME_SATELLITE_NEXT_VISIBLE_DONE,
3023 request);
Sarah Chin4beb2b72023-02-14 14:47:54 -08003024 if (mIsSatelliteServiceSupported) {
3025 mSatelliteServiceController
3026 .requestTimeForNextSatelliteVisibility(onCompleted);
3027 break;
3028 }
Sarah Chindf715ec2023-02-13 13:46:24 -08003029 Phone phone = getPhoneFromRequest(request);
3030 if (phone != null) {
3031 phone.requestTimeForNextSatelliteVisibility(onCompleted);
3032 } else {
3033 loge("requestTimeForNextSatelliteVisibility: No phone object");
3034 ((ResultReceiver) request.argument).send(
3035 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
3036 }
3037 break;
3038 }
3039
3040 case EVENT_GET_TIME_SATELLITE_NEXT_VISIBLE_DONE: {
3041 ar = (AsyncResult) msg.obj;
3042 request = (MainThreadRequest) ar.userObj;
3043 int error =
3044 getSatelliteError(ar, "requestTimeForNextSatelliteVisibility", true);
3045 Bundle bundle = new Bundle();
3046 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
3047 int nextVisibilityDuration = ((int[]) ar.result)[0];
3048 if (DBG) {
3049 log("requestTimeForNextSatelliteVisibility: " + nextVisibilityDuration);
3050 }
3051 bundle.putInt(SatelliteManager.KEY_SATELLITE_NEXT_VISIBILITY,
3052 nextVisibilityDuration);
3053 }
3054 ((ResultReceiver) request.argument).send(error, bundle);
3055 break;
3056 }
3057
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003058 default:
3059 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
3060 break;
3061 }
3062 }
Jake Hambye994d462014-02-03 13:10:13 -08003063
Pengquan Menga1bb6272018-09-06 09:59:22 -07003064 private void notifyRequester(MainThreadRequest request) {
3065 synchronized (request) {
3066 request.notifyAll();
3067 }
3068 }
3069
Jake Hambye994d462014-02-03 13:10:13 -08003070 private void handleNullReturnEvent(Message msg, String command) {
3071 AsyncResult ar = (AsyncResult) msg.obj;
3072 MainThreadRequest request = (MainThreadRequest) ar.userObj;
3073 if (ar.exception == null) {
3074 request.result = true;
3075 } else {
3076 request.result = false;
3077 if (ar.exception instanceof CommandException) {
3078 loge(command + ": CommandException: " + ar.exception);
3079 } else {
3080 loge(command + ": Unknown exception");
3081 }
3082 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003083 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08003084 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003085 }
3086
3087 /**
3088 * Posts the specified command to be executed on the main thread,
3089 * waits for the request to complete, and returns the result.
3090 * @see #sendRequestAsync
3091 */
3092 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08003093 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
3094 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07003095 }
3096
3097 /**
3098 * Posts the specified command to be executed on the main thread,
3099 * waits for the request to complete, and returns the result.
3100 * @see #sendRequestAsync
3101 */
3102 private Object sendRequest(int command, Object argument, WorkSource workSource) {
3103 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08003104 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07003105 }
3106
3107 /**
3108 * Posts the specified command to be executed on the main thread,
3109 * waits for the request to complete, and returns the result.
3110 * @see #sendRequestAsync
3111 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003112 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08003113 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
3114 }
3115
3116 /**
3117 * Posts the specified command to be executed on the main thread,
3118 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
3119 * if not timeout or null otherwise.
3120 * @see #sendRequestAsync
3121 */
3122 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
3123 long timeoutInMs) {
3124 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07003125 }
3126
3127 /**
3128 * Posts the specified command to be executed on the main thread,
3129 * waits for the request to complete, and returns the result.
3130 * @see #sendRequestAsync
3131 */
Nathan Harold92bed182018-10-12 18:16:49 -07003132 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08003133 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07003134 }
3135
3136 /**
3137 * Posts the specified command to be executed on the main thread,
3138 * waits for the request to complete, and returns the result.
3139 * @see #sendRequestAsync
3140 */
3141 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08003142 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
3143 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07003144 }
3145
3146 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08003147 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
3148 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
3149 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07003150 * @see #sendRequestAsync
3151 */
Rambo Wang0f050d82021-02-12 11:43:36 -08003152 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
3153 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003154 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
3155 throw new RuntimeException("This method will deadlock if called from the main thread.");
3156 }
3157
Nathan Harold92bed182018-10-12 18:16:49 -07003158 MainThreadRequest request = null;
3159 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
3160 throw new IllegalArgumentException("subId and phone cannot both be specified!");
3161 } else if (phone != null) {
3162 request = new MainThreadRequest(argument, phone, workSource);
3163 } else {
3164 request = new MainThreadRequest(argument, subId, workSource);
3165 }
3166
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003167 Message msg = mMainThreadHandler.obtainMessage(command, request);
3168 msg.sendToTarget();
3169
Rambo Wang0f050d82021-02-12 11:43:36 -08003170
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003171 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08003172 if (timeoutInMs >= 0) {
3173 // Wait for at least timeoutInMs before returning null request result
3174 long now = SystemClock.elapsedRealtime();
3175 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07003176 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08003177 try {
3178 request.wait(deadline - now);
3179 } catch (InterruptedException e) {
3180 // Do nothing, go back and check if request is completed or timeout
3181 } finally {
3182 now = SystemClock.elapsedRealtime();
3183 }
3184 }
3185 } else {
3186 // Wait for the request to complete
3187 while (request.result == null) {
3188 try {
3189 request.wait();
3190 } catch (InterruptedException e) {
3191 // Do nothing, go back and wait until the request is complete
3192 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003193 }
3194 }
3195 }
Rambo Wang0f050d82021-02-12 11:43:36 -08003196 if (request.result == null) {
3197 Log.wtf(LOG_TAG,
3198 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
3199 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003200 return request.result;
3201 }
3202
3203 /**
3204 * Asynchronous ("fire and forget") version of sendRequest():
3205 * Posts the specified command to be executed on the main thread, and
3206 * returns immediately.
3207 * @see #sendRequest
3208 */
3209 private void sendRequestAsync(int command) {
3210 mMainThreadHandler.sendEmptyMessage(command);
3211 }
3212
3213 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003214 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003215 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003216 */
3217 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003218 sendRequestAsync(command, argument, null, null);
3219 }
3220
3221 /**
3222 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
3223 * @see {@link #sendRequest(int,Object)}
3224 */
3225 private void sendRequestAsync(
3226 int command, Object argument, Phone phone, WorkSource workSource) {
3227 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003228 Message msg = mMainThreadHandler.obtainMessage(command, request);
3229 msg.sendToTarget();
3230 }
3231
3232 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003233 * Initialize the singleton PhoneInterfaceManager instance.
3234 * This is only done once, at startup, from PhoneApp.onCreate().
3235 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003236 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003237 synchronized (PhoneInterfaceManager.class) {
3238 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003239 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003240 } else {
3241 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
3242 }
3243 return sInstance;
3244 }
3245 }
3246
3247 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00003248 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003249 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003250 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00003251 mImsResolver = ImsResolver.getInstance();
Sarah Chin4beb2b72023-02-14 14:47:54 -08003252 mSatelliteServiceController = SatelliteServiceController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07003253 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003254 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
3255 mMainThreadHandler = new MainThreadHandler();
Jack Yue37dd262022-12-16 11:53:37 -08003256 if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) {
3257 mSubscriptionController = SubscriptionController.getInstance();
3258 } else {
3259 mSubscriptionController = null;
3260 }
Sarah Chin4beb2b72023-02-14 14:47:54 -08003261 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07003262 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07003263 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08003264 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08003265 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07003266 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003267 publish();
arunvoddud7401012022-12-15 16:08:12 +00003268 CarrierAllowListInfo.loadInstance(mApp);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08003269 mSatelliteSupportedReceiver = new ResultReceiver(mMainThreadHandler) {
3270 @Override
3271 protected void onReceiveResult(int resultCode, Bundle resultData) {
3272 if (resultCode == SatelliteManager.SATELLITE_ERROR_NONE
3273 && resultData.containsKey(SatelliteManager.KEY_SATELLITE_SUPPORTED)) {
3274 synchronized (mIsSatelliteSupportedLock) {
3275 mIsSatelliteSupported = resultData.getBoolean(
3276 SatelliteManager.KEY_SATELLITE_SUPPORTED);
3277 }
3278 } else {
3279 synchronized (mIsSatelliteSupportedLock) {
3280 mIsSatelliteSupported = null;
3281 }
3282 }
3283 }
3284 };
3285 requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
3286 mSatelliteSupportedReceiver);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003287 }
3288
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003289 @VisibleForTesting
3290 public SharedPreferences getSharedPreferences() {
3291 return mTelephonySharedPreferences;
3292 }
3293
Gil Cukierman92cc7db2023-01-06 19:25:53 +00003294 /**
3295 * Get the default phone for this device.
3296 */
3297 @VisibleForTesting
3298 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003299 Phone thePhone = getPhone(getDefaultSubscription());
3300 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
3301 }
3302
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003303 private void publish() {
3304 if (DBG) log("publish: " + this);
3305
Peter Wangc035ce42020-01-08 21:00:22 -08003306 TelephonyFrameworkInitializer
3307 .getTelephonyServiceManager()
3308 .getTelephonyServiceRegisterer()
3309 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003310 }
3311
Stuart Scott584921c2015-01-15 17:10:34 -08003312 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08003313 if (request.phone != null) {
3314 return request.phone;
3315 } else {
3316 return getPhoneFromSubId(request.subId);
3317 }
3318 }
3319
3320 private Phone getPhoneFromSubId(int subId) {
3321 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
3322 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08003323 }
3324
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00003325 /**
3326 * Get phone object associated with a subscription.
3327 * Return default phone if phone object associated with subscription is null
3328 * @param subId - subscriptionId
3329 * @return phone object associated with a subscription or default phone if null.
3330 */
3331 private Phone getPhoneFromSubIdOrDefault(int subId) {
3332 Phone phone = getPhoneFromSubId(subId);
3333 if (phone == null) {
3334 phone = getDefaultPhone();
3335 }
3336 return phone;
3337 }
3338
Rambo Wange53e07d2022-05-10 13:01:13 -07003339 @Nullable
3340 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003341 Phone phone = getPhoneFromRequest(request);
3342 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00003343 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003344 }
3345
Wink Saville36469e72014-06-11 15:17:00 -07003346 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07003347 private Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08003348 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07003349 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003350
Kai Shif70f46f2021-03-03 13:59:46 -08003351 private void sendEraseModemConfig(@NonNull Phone phone) {
3352 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
3353 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
3354 }
3355
3356 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
3357 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
3358 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07003359 }
3360
Peter Wang44b186e2020-01-13 23:33:09 -08003361 private boolean isImsAvailableOnDevice() {
3362 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
3363 if (pm == null) {
3364 // For some reason package manger is not available.. This will fail internally anyway,
3365 // so do not throw error and allow.
3366 return true;
3367 }
3368 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
3369 }
3370
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003371 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003372 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07003373 }
3374
Wink Savilleb564aae2014-10-23 10:18:09 -07003375 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003376 if (DBG) log("dial: " + number);
3377 // No permission check needed here: This is just a wrapper around the
3378 // ACTION_DIAL intent, which is available to any app since it puts up
3379 // the UI before it does anything.
3380
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003381 final long identity = Binder.clearCallingIdentity();
3382 try {
3383 String url = createTelUrl(number);
3384 if (url == null) {
3385 return;
3386 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003387
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003388 // PENDING: should we just silently fail if phone is offhook or ringing?
3389 PhoneConstants.State state = mCM.getState(subId);
3390 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
3391 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
3392 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3393 mApp.startActivity(intent);
3394 }
3395 } finally {
3396 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003397 }
3398 }
3399
3400 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003401 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07003402 }
3403
Wink Savilleb564aae2014-10-23 10:18:09 -07003404 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003405 if (DBG) log("call: " + number);
3406
3407 // This is just a wrapper around the ACTION_CALL intent, but we still
3408 // need to do a permission check since we're calling startActivity()
3409 // from the context of the phone app.
3410 enforceCallPermission();
3411
Jordan Liu1617b712019-07-10 15:06:26 -07003412 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003413 != AppOpsManager.MODE_ALLOWED) {
3414 return;
3415 }
3416
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003417 final long identity = Binder.clearCallingIdentity();
3418 try {
3419 String url = createTelUrl(number);
3420 if (url == null) {
3421 return;
3422 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003423
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003424 boolean isValid = false;
3425 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
3426 if (slist != null) {
3427 for (SubscriptionInfo subInfoRecord : slist) {
3428 if (subInfoRecord.getSubscriptionId() == subId) {
3429 isValid = true;
3430 break;
3431 }
Wink Saville3ab207e2014-11-20 13:07:20 -08003432 }
Wink Saville08874612014-08-31 19:19:58 -07003433 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003434 if (!isValid) {
3435 return;
3436 }
Wink Saville08874612014-08-31 19:19:58 -07003437
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003438 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
3439 intent.putExtra(SUBSCRIPTION_KEY, subId);
3440 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3441 mApp.startActivity(intent);
3442 } finally {
3443 Binder.restoreCallingIdentity(identity);
3444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003445 }
3446
Wink Savilleb564aae2014-10-23 10:18:09 -07003447 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003448 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07003449 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
3450 }
3451
Wink Savilleb564aae2014-10-23 10:18:09 -07003452 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003453 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07003454 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
3455 }
3456
Wink Savilleb564aae2014-10-23 10:18:09 -07003457 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003458 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003459
3460 final long identity = Binder.clearCallingIdentity();
3461 try {
Michele Berionne5e411512020-11-13 02:36:59 +00003462 Phone phone = getPhone(subId);
3463 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003464 checkSimPin.start();
3465 return checkSimPin.unlockSim(null, pin);
3466 } finally {
3467 Binder.restoreCallingIdentity(identity);
3468 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003469 }
3470
Wink Savilleb564aae2014-10-23 10:18:09 -07003471 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003472 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003473
3474 final long identity = Binder.clearCallingIdentity();
3475 try {
Michele Berionne5e411512020-11-13 02:36:59 +00003476 Phone phone = getPhone(subId);
3477 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003478 checkSimPuk.start();
3479 return checkSimPuk.unlockSim(puk, pin);
3480 } finally {
3481 Binder.restoreCallingIdentity(identity);
3482 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003483 }
3484
3485 /**
Wink Saville9de0f752013-10-22 19:04:03 -07003486 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003487 * a synchronous one.
3488 */
3489 private static class UnlockSim extends Thread {
3490
3491 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00003492 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003493
3494 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07003495 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
3496 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003497
3498 // For replies from SimCard interface
3499 private Handler mHandler;
3500
3501 // For async handler to identify request type
3502 private static final int SUPPLY_PIN_COMPLETE = 100;
3503
Michele Berionne5e411512020-11-13 02:36:59 +00003504 UnlockSim(int phoneId, IccCard simCard) {
3505 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003506 mSimCard = simCard;
3507 }
3508
3509 @Override
3510 public void run() {
3511 Looper.prepare();
3512 synchronized (UnlockSim.this) {
3513 mHandler = new Handler() {
3514 @Override
3515 public void handleMessage(Message msg) {
3516 AsyncResult ar = (AsyncResult) msg.obj;
3517 switch (msg.what) {
3518 case SUPPLY_PIN_COMPLETE:
3519 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
3520 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07003521 mRetryCount = msg.arg1;
3522 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08003523 CommandException.Error error = null;
3524 if (ar.exception instanceof CommandException) {
3525 error = ((CommandException) (ar.exception))
3526 .getCommandError();
3527 }
3528 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07003529 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08003530 } else if (error == CommandException.Error.ABORTED) {
3531 /* When UiccCardApp dispose, handle message and return
3532 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08003533 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07003534 } else {
3535 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
3536 }
3537 } else {
3538 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
3539 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003540 mDone = true;
3541 UnlockSim.this.notifyAll();
3542 }
3543 break;
3544 }
3545 }
3546 };
3547 UnlockSim.this.notifyAll();
3548 }
3549 Looper.loop();
3550 }
3551
3552 /*
3553 * Use PIN or PUK to unlock SIM card
3554 *
3555 * If PUK is null, unlock SIM card with PIN
3556 *
3557 * If PUK is not null, unlock SIM card with PUK and set PIN code
3558 */
Wink Saville9de0f752013-10-22 19:04:03 -07003559 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003560
3561 while (mHandler == null) {
3562 try {
3563 wait();
3564 } catch (InterruptedException e) {
3565 Thread.currentThread().interrupt();
3566 }
3567 }
3568 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
3569
3570 if (puk == null) {
3571 mSimCard.supplyPin(pin, callback);
3572 } else {
3573 mSimCard.supplyPuk(puk, pin, callback);
3574 }
3575
3576 while (!mDone) {
3577 try {
3578 Log.d(LOG_TAG, "wait for done");
3579 wait();
3580 } catch (InterruptedException e) {
3581 // Restore the interrupted status
3582 Thread.currentThread().interrupt();
3583 }
3584 }
3585 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07003586 int[] resultArray = new int[2];
3587 resultArray[0] = mResult;
3588 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00003589
3590 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00003591 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00003592 }
3593
Wink Saville9de0f752013-10-22 19:04:03 -07003594 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003595 }
3596 }
3597
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003598 /**
3599 * This method has been removed due to privacy and stability concerns.
3600 */
3601 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003602 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003603 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
3604 return;
Wink Saville36469e72014-06-11 15:17:00 -07003605 }
3606
Nathan Harold1f889d82020-06-04 17:05:26 -07003607 @Override
3608 public void updateServiceLocationWithPackageName(String callingPackage) {
3609 mApp.getSystemService(AppOpsManager.class)
3610 .checkPackage(Binder.getCallingUid(), callingPackage);
3611
Nathan Haroldf096d982020-11-18 17:18:06 -08003612 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07003613 if (targetSdk > android.os.Build.VERSION_CODES.R) {
3614 // Callers targeting S have no business invoking this method.
3615 return;
3616 }
3617
3618 LocationAccessPolicy.LocationPermissionResult locationResult =
3619 LocationAccessPolicy.checkLocationPermission(mApp,
3620 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3621 .setCallingPackage(callingPackage)
3622 .setCallingFeatureId(null)
3623 .setCallingPid(Binder.getCallingPid())
3624 .setCallingUid(Binder.getCallingUid())
3625 .setMethod("updateServiceLocation")
3626 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3627 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3628 .build());
3629 // Apps that lack location permission have no business calling this method;
3630 // however, because no permission was declared in the public API, denials must
3631 // all be "soft".
3632 switch (locationResult) {
3633 case DENIED_HARD: /* fall through */
3634 case DENIED_SOFT:
3635 return;
3636 }
3637
3638 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003639 final long identity = Binder.clearCallingIdentity();
3640 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07003641 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003642 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07003643 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003644 }
3645 } finally {
3646 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003647 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003648 }
3649
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003650 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003651 @Override
3652 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003653 return isRadioOnWithFeature(callingPackage, null);
3654 }
3655
3656
3657 @Override
3658 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
3659 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
3660 callingFeatureId);
3661 }
3662
3663 @Deprecated
3664 @Override
3665 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
3666 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07003667 }
3668
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003669 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003670 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
3671 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003672 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003673 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003674 return false;
3675 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003676
3677 final long identity = Binder.clearCallingIdentity();
3678 try {
3679 return isRadioOnForSubscriber(subId);
3680 } finally {
3681 Binder.restoreCallingIdentity(identity);
3682 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003683 }
3684
3685 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003686 final long identity = Binder.clearCallingIdentity();
3687 try {
3688 final Phone phone = getPhone(subId);
3689 if (phone != null) {
3690 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
3691 } else {
3692 return false;
3693 }
3694 } finally {
3695 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003696 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003697 }
3698
3699 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003700 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003701 }
Wink Saville36469e72014-06-11 15:17:00 -07003702
Wink Savilleb564aae2014-10-23 10:18:09 -07003703 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003704 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003705
3706 final long identity = Binder.clearCallingIdentity();
3707 try {
3708 final Phone phone = getPhone(subId);
3709 if (phone != null) {
3710 phone.setRadioPower(!isRadioOnForSubscriber(subId));
3711 }
3712 } finally {
3713 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003714 }
Wink Saville36469e72014-06-11 15:17:00 -07003715 }
3716
3717 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003718 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07003719 }
3720
Wink Savilleb564aae2014-10-23 10:18:09 -07003721 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07003722 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003723
3724 final long identity = Binder.clearCallingIdentity();
3725 try {
3726 final Phone phone = getPhone(subId);
3727 if (phone == null) {
3728 return false;
3729 }
3730 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
3731 toggleRadioOnOffForSubscriber(subId);
3732 }
3733 return true;
3734 } finally {
3735 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003736 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003737 }
Wink Saville36469e72014-06-11 15:17:00 -07003738
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003739 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08003740 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003741 /*
3742 * If any of the Radios are available, it will need to be
3743 * shutdown. So return true if any Radio is available.
3744 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003745 final long identity = Binder.clearCallingIdentity();
3746 try {
3747 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3748 Phone phone = PhoneFactory.getPhone(i);
3749 if (phone != null && phone.isRadioAvailable()) return true;
3750 }
3751 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3752 return false;
3753 } finally {
3754 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003755 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003756 }
3757
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003758 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003759 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003760 enforceModifyPermission();
3761
3762 final long identity = Binder.clearCallingIdentity();
3763 try {
3764 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3765 logv("Shutting down Phone " + i);
3766 shutdownRadioUsingPhoneId(i);
3767 }
3768 } finally {
3769 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003770 }
3771 }
3772
3773 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003774 Phone phone = PhoneFactory.getPhone(phoneId);
3775 if (phone != null && phone.isRadioAvailable()) {
3776 phone.shutdownRadio();
3777 }
3778 }
3779
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003780 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003781 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003782
Ling Ma83dc5ea2023-01-12 15:06:04 -08003783 if (!turnOn) {
3784 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3785 }
3786
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003787 final long identity = Binder.clearCallingIdentity();
3788 try {
3789 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3790 if (defaultPhone != null) {
3791 defaultPhone.setRadioPower(turnOn);
3792 return true;
3793 } else {
3794 loge("There's no default phone.");
3795 return false;
3796 }
3797 } finally {
3798 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003799 }
Wink Saville36469e72014-06-11 15:17:00 -07003800 }
3801
Wink Savilleb564aae2014-10-23 10:18:09 -07003802 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003803 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003804
Ling Ma83dc5ea2023-01-12 15:06:04 -08003805 if (!turnOn) {
3806 log("setRadioPowerForSubscriber off: subId=" + subId
3807 + ",callingPackage=" + getCurrentPackageName());
3808 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003809 final long identity = Binder.clearCallingIdentity();
3810 try {
3811 final Phone phone = getPhone(subId);
3812 if (phone != null) {
3813 phone.setRadioPower(turnOn);
3814 return true;
3815 } else {
3816 return false;
3817 }
3818 } finally {
3819 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003820 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003821 }
3822
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003823 /**
3824 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3825 * no reason to power it off. When any of the voters want to power it off, it will be turned
3826 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3827 * powering it off, and these radio off votes will be cleared.
3828 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3829 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3830 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3831 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3832 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3833 * check its vote.
3834 *
3835 * @param subId The subscription ID.
3836 * @param reason The reason for powering off radio.
3837 * @return true on success and false on failure.
3838 */
3839 public boolean requestRadioPowerOffForReason(int subId,
3840 @TelephonyManager.RadioPowerReason int reason) {
3841 enforceModifyPermission();
3842
Ling Ma83dc5ea2023-01-12 15:06:04 -08003843 log("requestRadioPowerOffForReason: subId=" + subId
3844 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003845 final long identity = Binder.clearCallingIdentity();
3846 try {
3847 final Phone phone = getPhone(subId);
3848 if (phone != null) {
3849 phone.setRadioPowerForReason(false, reason);
3850 return true;
3851 } else {
3852 return false;
3853 }
3854 } finally {
3855 Binder.restoreCallingIdentity(identity);
3856 }
3857 }
3858
3859 /**
3860 * Remove the vote on powering off the radio for a reason, as requested by
3861 * {@link requestRadioPowerOffForReason}.
3862 *
3863 * @param subId The subscription ID.
3864 * @param reason The reason for powering off radio.
3865 * @return true on success and false on failure.
3866 */
3867 public boolean clearRadioPowerOffForReason(int subId,
3868 @TelephonyManager.RadioPowerReason int reason) {
3869 enforceModifyPermission();
3870
3871 final long identity = Binder.clearCallingIdentity();
3872 try {
3873 final Phone phone = getPhone(subId);
3874 if (phone != null) {
3875 phone.setRadioPowerForReason(true, reason);
3876 return true;
3877 } else {
3878 return false;
3879 }
3880 } finally {
3881 Binder.restoreCallingIdentity(identity);
3882 }
3883 }
3884
3885 /**
3886 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3887 *
3888 * @param subId The subscription ID.
3889 * @param callingPackage The package making the call.
3890 * @param callingFeatureId The feature in the package.
3891 * @return List of reasons for powering off radio.
3892 */
3893 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3894 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3895
3896 final long identity = Binder.clearCallingIdentity();
3897 List result = new ArrayList();
3898 try {
3899 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3900 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3901 return result;
3902 }
3903
3904 final Phone phone = getPhone(subId);
3905 if (phone != null) {
3906 result.addAll(phone.getRadioPowerOffReasons());
3907 }
3908 } finally {
3909 Binder.restoreCallingIdentity(identity);
3910 }
3911 return result;
3912 }
3913
Wink Saville36469e72014-06-11 15:17:00 -07003914 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003915 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003916 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003917 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003918
3919 final long identity = Binder.clearCallingIdentity();
3920 try {
Jack Yu285100e2022-12-02 22:48:35 -08003921 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003922 final Phone phone = getPhone(subId);
3923 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003924 phone.getDataSettingsManager().setDataEnabled(
3925 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003926 return true;
3927 } else {
3928 return false;
3929 }
3930 } finally {
3931 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003932 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003933 }
3934
Wink Saville36469e72014-06-11 15:17:00 -07003935 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003936 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003937 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003938 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003939
3940 final long identity = Binder.clearCallingIdentity();
3941 try {
Jack Yu285100e2022-12-02 22:48:35 -08003942 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003943 final Phone phone = getPhone(subId);
3944 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003945 phone.getDataSettingsManager().setDataEnabled(
3946 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003947 return true;
3948 } else {
3949 return false;
3950 }
3951 } finally {
3952 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003953 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003954 }
3955
Sanket Padawe356d7632015-06-22 14:03:32 -07003956 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003957 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003958 final long identity = Binder.clearCallingIdentity();
3959 try {
3960 final Phone phone = getPhone(subId);
3961 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003962 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003963 } else {
3964 return false;
3965 }
3966 } finally {
3967 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003968 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003969 }
3970
3971 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003972 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003973 }
3974
pkanwarae03a6b2016-11-06 20:37:09 -08003975 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003976 enforceCallPermission();
3977
3978 final long identity = Binder.clearCallingIdentity();
3979 try {
3980 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3981 return;
3982 }
3983 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3984 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3985 } finally {
3986 Binder.restoreCallingIdentity(identity);
3987 }
pkanwar32d516d2016-10-14 19:37:38 -07003988 };
3989
Wink Savilleb564aae2014-10-23 10:18:09 -07003990 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003991 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003992
3993 final long identity = Binder.clearCallingIdentity();
3994 try {
3995 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3996 return false;
3997 }
3998 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3999 } finally {
4000 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004001 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004002 }
4003
Brad Ebinger4f6208e2021-03-23 21:04:45 +00004004 /**
4005 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
4006 * tag on getCallState Binder call.
4007 */
4008 @Deprecated
4009 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004010 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00004011 if (CompatChanges.isChangeEnabled(
4012 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
4013 Binder.getCallingUid())) {
4014 // Do not allow this API to be called on API version 31+, it should only be
4015 // called on old apps using this Binder call directly.
4016 throw new SecurityException("This method can only be used for applications "
4017 + "targeting API version 30 or less.");
4018 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004019 final long identity = Binder.clearCallingIdentity();
4020 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00004021 Phone phone = getPhone(getDefaultSubscription());
4022 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
4023 PhoneConstantConversions.convertCallState(phone.getState());
4024 } finally {
4025 Binder.restoreCallingIdentity(identity);
4026 }
4027 }
4028
4029 @Override
4030 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
4031 if (CompatChanges.isChangeEnabled(
4032 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
4033 Binder.getCallingUid())) {
4034 // Check READ_PHONE_STATE for API version 31+
4035 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4036 featureId, "getCallStateForSubscription")) {
4037 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
4038 + "targeting API level 31+.");
4039 }
4040 }
4041 final long identity = Binder.clearCallingIdentity();
4042 try {
4043 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004044 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
4045 PhoneConstantConversions.convertCallState(phone.getState());
4046 } finally {
4047 Binder.restoreCallingIdentity(identity);
4048 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004049 }
4050
Sanket Padawe356d7632015-06-22 14:03:32 -07004051 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00004052 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08004053 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07004054 }
4055
4056 @Override
4057 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004058 final long identity = Binder.clearCallingIdentity();
4059 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07004060 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004061 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07004062 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004063 } else {
4064 return PhoneConstantConversions.convertDataState(
4065 PhoneConstants.DataState.DISCONNECTED);
4066 }
4067 } finally {
4068 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004069 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004070 }
4071
Sanket Padawe356d7632015-06-22 14:03:32 -07004072 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07004073 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08004074 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07004075 }
4076
4077 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07004078 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004079 final long identity = Binder.clearCallingIdentity();
4080 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07004081 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004082 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07004083 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004084 } else {
4085 return TelephonyManager.DATA_ACTIVITY_NONE;
4086 }
4087 } finally {
4088 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004089 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004090 }
4091
4092 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08004093 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004094 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08004095 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08004096
4097 LocationAccessPolicy.LocationPermissionResult locationResult =
4098 LocationAccessPolicy.checkLocationPermission(mApp,
4099 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4100 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004101 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004102 .setCallingPid(Binder.getCallingPid())
4103 .setCallingUid(Binder.getCallingUid())
4104 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08004105 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08004106 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4107 .build());
4108 switch (locationResult) {
4109 case DENIED_HARD:
4110 throw new SecurityException("Not allowed to access cell location");
4111 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08004112 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
4113 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004114 }
4115
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004116 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004117 final long identity = Binder.clearCallingIdentity();
4118 try {
4119 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08004120 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08004121 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004122 } finally {
4123 Binder.restoreCallingIdentity(identity);
4124 }
Svetoslav64fad262015-04-14 14:35:21 -07004125 }
4126
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004127 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08004128 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07004129 // Reporting the correct network country is ambiguous when IWLAN could conflict with
4130 // registered cell info, so return a NULL country instead.
4131 final long identity = Binder.clearCallingIdentity();
4132 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07004133 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
4134 // Get default phone in this case.
4135 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
4136 }
Jack Yu285100e2022-12-02 22:48:35 -08004137 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004138 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07004139 if (phone == null) return "";
4140 ServiceStateTracker sst = phone.getServiceStateTracker();
4141 if (sst == null) return "";
4142 LocaleTracker lt = sst.getLocaleTracker();
4143 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08004144 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07004145 } finally {
4146 Binder.restoreCallingIdentity(identity);
4147 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07004148 }
4149
Nathan Harold7c8d0f12020-05-28 20:40:31 -07004150 /**
4151 * This method was removed due to potential issues caused by performing partial
4152 * updates of service state, and lack of a credible use case.
4153 *
4154 * This has the ability to break the telephony implementation by disabling notification of
4155 * changes in device connectivity. DO NOT USE THIS!
4156 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07004157 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004158 public void enableLocationUpdates() {
4159 mApp.enforceCallingOrSelfPermission(
4160 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004161 }
4162
Nathan Harold7c8d0f12020-05-28 20:40:31 -07004163 /**
4164 * This method was removed due to potential issues caused by performing partial
4165 * updates of service state, and lack of a credible use case.
4166 *
4167 * This has the ability to break the telephony implementation by disabling notification of
4168 * changes in device connectivity. DO NOT USE THIS!
4169 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004170 @Override
4171 public void disableLocationUpdates() {
4172 mApp.enforceCallingOrSelfPermission(
4173 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004174 }
4175
4176 @Override
4177 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004178 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
4179 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07004180 try {
4181 mApp.getSystemService(AppOpsManager.class)
4182 .checkPackage(Binder.getCallingUid(), callingPackage);
4183 } catch (SecurityException e) {
4184 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
4185 throw e;
4186 }
4187
Nathan Haroldf096d982020-11-18 17:18:06 -08004188 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07004189 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
4190 throw new SecurityException(
4191 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
4192 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07004193
Jordan Liu1617b712019-07-10 15:06:26 -07004194 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004195 callingPackage) != AppOpsManager.MODE_ALLOWED) {
4196 return null;
4197 }
Svetoslav64fad262015-04-14 14:35:21 -07004198
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07004199 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004200
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004201 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07004202 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004203
Nathan Haroldf180aac2018-06-01 18:43:55 -07004204 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
4205 for (CellInfo ci : info) {
4206 if (ci instanceof CellInfoGsm) {
4207 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
4208 } else if (ci instanceof CellInfoWcdma) {
4209 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
4210 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004211 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07004212 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004213 }
4214
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004215 private List<CellInfo> getCachedCellInfo() {
4216 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
4217 for (Phone phone : PhoneFactory.getPhones()) {
4218 List<CellInfo> info = phone.getAllCellInfo();
4219 if (info != null) cellInfos.addAll(info);
4220 }
4221 return cellInfos;
4222 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004223
4224 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004225 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004226 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08004227 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08004228
4229 LocationAccessPolicy.LocationPermissionResult locationResult =
4230 LocationAccessPolicy.checkLocationPermission(mApp,
4231 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4232 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004233 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004234 .setCallingPid(Binder.getCallingPid())
4235 .setCallingUid(Binder.getCallingUid())
4236 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08004237 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08004238 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4239 .build());
4240 switch (locationResult) {
4241 case DENIED_HARD:
4242 throw new SecurityException("Not allowed to access cell info");
4243 case DENIED_SOFT:
4244 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004245 }
4246
Nathan Haroldf096d982020-11-18 17:18:06 -08004247 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004248 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
4249 return getCachedCellInfo();
4250 }
4251
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07004252 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004253 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004254 final long identity = Binder.clearCallingIdentity();
4255 try {
4256 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
4257 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07004258 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07004259 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004260 if (info != null) cellInfos.addAll(info);
4261 }
4262 return cellInfos;
4263 } finally {
4264 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004265 }
4266 }
4267
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07004268 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004269 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
4270 String callingFeatureId) {
4271 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
4272 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004273 }
4274
4275 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004276 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
4277 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004278 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004279 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004280 }
4281
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004282 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
4283 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004284 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004285 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08004286
4287 LocationAccessPolicy.LocationPermissionResult locationResult =
4288 LocationAccessPolicy.checkLocationPermission(mApp,
4289 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4290 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004291 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004292 .setCallingPid(Binder.getCallingPid())
4293 .setCallingUid(Binder.getCallingUid())
4294 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07004295 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
4296 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08004297 .build());
4298 switch (locationResult) {
4299 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08004300 if (TelephonyPermissions
4301 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07004302 // Safetynet logging for b/154934934
4303 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
4304 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004305 throw new SecurityException("Not allowed to access cell info");
4306 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08004307 if (TelephonyPermissions
4308 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07004309 // Safetynet logging for b/154934934
4310 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
4311 }
Nathan Harold5320c422019-05-09 10:26:08 -07004312 try {
4313 cb.onCellInfo(new ArrayList<CellInfo>());
4314 } catch (RemoteException re) {
4315 // Drop without consequences
4316 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004317 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004318 }
4319
Nathan Harolda939a962019-05-09 10:13:47 -07004320
4321 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004322 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
4323
4324 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
4325 }
4326
4327 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00004328 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08004329 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004330 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004331
4332 final long identity = Binder.clearCallingIdentity();
4333 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00004334 Phone phone = getPhone(subId);
4335 if (phone == null) {
4336 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
4337 } else {
4338 phone.setCellInfoListRate(rateInMillis, workSource);
4339 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004340 } finally {
4341 Binder.restoreCallingIdentity(identity);
4342 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004343 }
4344
Shishir Agrawala9f32182016-04-12 12:00:16 -07004345 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004346 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004347 Phone phone = PhoneFactory.getPhone(slotIndex);
4348 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004349 return null;
4350 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004351 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07004352 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07004353 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004354 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004355 return null;
4356 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004357
4358 final long identity = Binder.clearCallingIdentity();
4359 try {
4360 return phone.getImei();
4361 } finally {
4362 Binder.restoreCallingIdentity(identity);
4363 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07004364 }
4365
4366 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00004367 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
4368 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
4369 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
4370 callingFeatureId, "getPrimaryImei")) {
4371 throw new SecurityException("Caller does not have permission");
4372 }
4373 final long identity = Binder.clearCallingIdentity();
4374 try {
4375 for (Phone phone : PhoneFactory.getPhones()) {
4376 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
4377 return phone.getImei();
4378 }
4379 }
4380 throw new UnsupportedOperationException("Operation not supported");
4381 } finally {
4382 Binder.restoreCallingIdentity(identity);
4383 }
4384 }
4385
4386 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00004387 public String getTypeAllocationCodeForSlot(int slotIndex) {
4388 Phone phone = PhoneFactory.getPhone(slotIndex);
4389 String tac = null;
4390 if (phone != null) {
4391 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07004392 try {
4393 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
4394 } catch (IndexOutOfBoundsException e) {
4395 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
4396 return null;
4397 }
David Kelly5e06a7f2018-03-12 14:10:59 +00004398 }
4399 return tac;
4400 }
4401
4402 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004403 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004404 try {
4405 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4406 } catch (SecurityException se) {
4407 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
4408 throw new SecurityException("Package " + callingPackage + " does not belong to "
4409 + Binder.getCallingUid());
4410 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004411 Phone phone = PhoneFactory.getPhone(slotIndex);
4412 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07004413 return null;
4414 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004415
Jeff Davidson913390f2018-02-23 17:11:49 -08004416 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07004417 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004418 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004419 return null;
4420 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004421
4422 final long identity = Binder.clearCallingIdentity();
4423 try {
4424 return phone.getMeid();
4425 } finally {
4426 Binder.restoreCallingIdentity(identity);
4427 }
Jack Yu2af8d712017-03-15 17:14:14 -07004428 }
4429
4430 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00004431 public String getManufacturerCodeForSlot(int slotIndex) {
4432 Phone phone = PhoneFactory.getPhone(slotIndex);
4433 String manufacturerCode = null;
4434 if (phone != null) {
4435 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07004436 try {
4437 manufacturerCode =
4438 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
4439 } catch (IndexOutOfBoundsException e) {
4440 Log.e(LOG_TAG, "MEID length shorter than upper index.");
4441 return null;
4442 }
David Kelly5e06a7f2018-03-12 14:10:59 +00004443 }
4444 return manufacturerCode;
4445 }
4446
4447 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004448 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
4449 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004450 Phone phone = PhoneFactory.getPhone(slotIndex);
4451 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004452 return null;
4453 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004454 int subId = phone.getSubId();
4455 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004456 mApp, subId, callingPackage, callingFeatureId,
4457 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004458 return null;
4459 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004460
4461 final long identity = Binder.clearCallingIdentity();
4462 try {
4463 return phone.getDeviceSvn();
4464 } finally {
4465 Binder.restoreCallingIdentity(identity);
4466 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07004467 }
4468
fionaxu43304da2017-11-27 22:51:16 -08004469 @Override
4470 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004471 final long identity = Binder.clearCallingIdentity();
4472 try {
4473 final Phone phone = getPhone(subId);
4474 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
4475 } finally {
4476 Binder.restoreCallingIdentity(identity);
4477 }
fionaxu43304da2017-11-27 22:51:16 -08004478 }
4479
4480 @Override
4481 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004482 final long identity = Binder.clearCallingIdentity();
4483 try {
4484 final Phone phone = getPhone(subId);
4485 return phone == null ? null : phone.getCarrierName();
4486 } finally {
4487 Binder.restoreCallingIdentity(identity);
4488 }
fionaxu43304da2017-11-27 22:51:16 -08004489 }
4490
calvinpanffe225e2018-11-01 19:43:06 +08004491 @Override
chen xu0026ca62019-03-06 15:28:50 -08004492 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08004493 final long identity = Binder.clearCallingIdentity();
4494 try {
4495 final Phone phone = getPhone(subId);
4496 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08004497 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08004498 } finally {
4499 Binder.restoreCallingIdentity(identity);
4500 }
4501 }
4502
4503 @Override
chen xu0026ca62019-03-06 15:28:50 -08004504 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08004505 final long identity = Binder.clearCallingIdentity();
4506 try {
4507 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08004508 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08004509 } finally {
4510 Binder.restoreCallingIdentity(identity);
4511 }
4512 }
4513
chen xu651eec72018-11-11 19:03:44 -08004514 @Override
chen xu864e11c2018-12-06 22:10:03 -08004515 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
4516 if (!isSubscriptionMccMnc) {
4517 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
4518 }
chen xu651eec72018-11-11 19:03:44 -08004519 final Phone phone = PhoneFactory.getPhone(slotIndex);
4520 if (phone == null) {
4521 return TelephonyManager.UNKNOWN_CARRIER_ID;
4522 }
4523 final long identity = Binder.clearCallingIdentity();
4524 try {
4525 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
4526 } finally {
4527 Binder.restoreCallingIdentity(identity);
4528 }
4529 }
4530
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004531 //
4532 // Internal helper methods.
4533 //
4534
Sanket Padaweee13a9b2016-03-08 17:30:28 -08004535 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07004536 * Make sure the caller is the calling package itself
4537 *
4538 * @throws SecurityException if the caller is not the calling package
4539 */
4540 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
4541 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07004542 PackageManager pm = mApp.getBaseContext().createContextAsUser(
4543 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07004544 try {
Grace Jiadbefca02021-04-26 15:13:31 -07004545 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07004546 } catch (PackageManager.NameNotFoundException e) {
4547 // packageUid is -1
4548 }
4549 if (packageUid != callingUid) {
4550 throw new SecurityException(message + ": Package " + callingPackage
4551 + " does not belong to " + callingUid);
4552 }
4553 }
4554
4555 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004556 * Make sure the caller has the MODIFY_PHONE_STATE permission.
4557 *
4558 * @throws SecurityException if the caller does not have the required permission
4559 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004560 @VisibleForTesting
4561 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004562 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
4563 }
4564
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004565 /**
arunvoddud7401012022-12-15 16:08:12 +00004566 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004567 *
4568 * @throws SecurityException if the caller does not have the required permission
4569 */
4570 @VisibleForTesting
4571 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00004572 enforceReadPermission(null);
4573 }
4574
4575 /**
4576 * Make sure the caller has the READ_PHONE_STATE permissions.
4577 *
4578 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
4579 */
4580 @VisibleForTesting
4581 public void enforceReadPermission(String msg) {
4582 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004583 }
4584
Shuo Qian3b6ee772019-11-13 17:43:31 -08004585 private void enforceActiveEmergencySessionPermission() {
4586 mApp.enforceCallingOrSelfPermission(
4587 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
4588 }
4589
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004590 /**
4591 * Make sure the caller has the CALL_PHONE permission.
4592 *
4593 * @throws SecurityException if the caller does not have the required permission
4594 */
4595 private void enforceCallPermission() {
4596 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
4597 }
4598
paulhu5a773602019-08-23 19:17:33 +08004599 private void enforceSettingsPermission() {
4600 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004601 }
4602
Michele Berionne5e411512020-11-13 02:36:59 +00004603 private void enforceRebootPermission() {
4604 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
4605 }
4606
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00004607 /**
4608 * Make sure the caller has SATELLITE_COMMUNICATION permission.
4609 * @param message - log message to print.
4610 * @throws SecurityException if the caller does not have the required permission
4611 */
4612 private void enforceSatelliteCommunicationPermission(String message) {
4613 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
4614 }
4615
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004616 private String createTelUrl(String number) {
4617 if (TextUtils.isEmpty(number)) {
4618 return null;
4619 }
4620
Jake Hambye994d462014-02-03 13:10:13 -08004621 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004622 }
4623
Ihab Awadf9e92732013-12-05 18:02:52 -08004624 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08004625 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004626 }
4627
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07004628 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08004629 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07004630 }
4631
Ihab Awadf9e92732013-12-05 18:02:52 -08004632 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08004633 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004634 }
4635
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004636 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004637 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07004638 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07004639 }
4640
Sanket Padawe356d7632015-06-22 14:03:32 -07004641 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004642 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004643 final long identity = Binder.clearCallingIdentity();
4644 try {
4645 final Phone phone = PhoneFactory.getPhone(slotIndex);
4646 if (phone == null) {
4647 return PhoneConstants.PHONE_TYPE_NONE;
4648 } else {
4649 return phone.getPhoneType();
4650 }
4651 } finally {
4652 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004653 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004654 }
4655
4656 /**
4657 * Returns the CDMA ERI icon index to display
4658 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004659 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004660 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
4661 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4662 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004663 }
4664
Sanket Padawe356d7632015-06-22 14:03:32 -07004665 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004666 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4667 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004668 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004669 mApp, subId, callingPackage, callingFeatureId,
4670 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004671 return -1;
4672 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004673
4674 final long identity = Binder.clearCallingIdentity();
4675 try {
4676 final Phone phone = getPhone(subId);
4677 if (phone != null) {
4678 return phone.getCdmaEriIconIndex();
4679 } else {
4680 return -1;
4681 }
4682 } finally {
4683 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004684 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004685 }
4686
4687 /**
4688 * Returns the CDMA ERI icon mode,
4689 * 0 - ON
4690 * 1 - FLASHING
4691 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004692 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004693 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4694 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4695 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004696 }
4697
Sanket Padawe356d7632015-06-22 14:03:32 -07004698 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004699 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4700 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004701 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004702 mApp, subId, callingPackage, callingFeatureId,
4703 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004704 return -1;
4705 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004706
4707 final long identity = Binder.clearCallingIdentity();
4708 try {
4709 final Phone phone = getPhone(subId);
4710 if (phone != null) {
4711 return phone.getCdmaEriIconMode();
4712 } else {
4713 return -1;
4714 }
4715 } finally {
4716 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004717 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004718 }
4719
4720 /**
4721 * Returns the CDMA ERI text,
4722 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004723 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004724 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4725 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4726 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004727 }
4728
Sanket Padawe356d7632015-06-22 14:03:32 -07004729 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004730 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4731 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004732 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004733 mApp, subId, callingPackage, callingFeatureId,
4734 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004735 return null;
4736 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004737
4738 final long identity = Binder.clearCallingIdentity();
4739 try {
4740 final Phone phone = getPhone(subId);
4741 if (phone != null) {
4742 return phone.getCdmaEriText();
4743 } else {
4744 return null;
4745 }
4746 } finally {
4747 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004748 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004749 }
4750
4751 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004752 * Returns the CDMA MDN.
4753 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004754 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004755 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004756 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4757 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004758
4759 final long identity = Binder.clearCallingIdentity();
4760 try {
4761 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004762 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004763 return phone.getLine1Number();
4764 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004765 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004766 return null;
4767 }
4768 } finally {
4769 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004770 }
4771 }
4772
4773 /**
4774 * Returns the CDMA MIN.
4775 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004776 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004777 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4779 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004780
4781 final long identity = Binder.clearCallingIdentity();
4782 try {
4783 final Phone phone = getPhone(subId);
4784 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4785 return phone.getCdmaMin();
4786 } else {
4787 return null;
4788 }
4789 } finally {
4790 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004791 }
4792 }
4793
Hall Liud892bec2018-11-30 14:51:45 -08004794 @Override
4795 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4796 INumberVerificationCallback callback, String callingPackage) {
4797 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4798 != PERMISSION_GRANTED) {
4799 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4800 }
4801 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4802
4803 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4804 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004805 throw new SecurityException("Calling package must be configured in the device config: "
4806 + "calling package: " + callingPackage
4807 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004808 }
4809
4810 if (range == null) {
4811 throw new NullPointerException("Range must be non-null");
4812 }
4813
4814 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004815 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004816
4817 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4818 }
4819
Junda Liuca05d5d2014-08-14 22:36:34 -07004820 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004821 * Returns true if CDMA provisioning needs to run.
4822 */
4823 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004824 final long identity = Binder.clearCallingIdentity();
4825 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004826 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004827 } finally {
4828 Binder.restoreCallingIdentity(identity);
4829 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004830 }
4831
4832 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004833 * Sets the voice mail number of a given subId.
4834 */
4835 @Override
4836 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004837 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4838 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004839
4840 final long identity = Binder.clearCallingIdentity();
4841 try {
4842 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4843 new Pair<String, String>(alphaTag, number), new Integer(subId));
4844 return success;
4845 } finally {
4846 Binder.restoreCallingIdentity(identity);
4847 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004848 }
4849
Ta-wei Yen87c49842016-05-13 21:19:52 -07004850 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004851 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4852 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004853 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4854 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004855 if (!TextUtils.equals(callingPackage, systemDialer)) {
4856 throw new SecurityException("caller must be system dialer");
4857 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004858
4859 final long identity = Binder.clearCallingIdentity();
4860 try {
4861 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4862 if (phoneAccountHandle == null) {
4863 return null;
4864 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004865 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004866 } finally {
4867 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004868 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004869 }
4870
4871 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004872 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4873 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004874 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004875 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004876 mApp, subId, callingPackage, callingFeatureId,
4877 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004878 return null;
4879 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004880
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004881 final long identity = Binder.clearCallingIdentity();
4882 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004883 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004884 } finally {
4885 Binder.restoreCallingIdentity(identity);
4886 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004887 }
4888
4889 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004890 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4891 VisualVoicemailSmsFilterSettings settings) {
4892 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004893
4894 final long identity = Binder.clearCallingIdentity();
4895 try {
4896 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004897 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004898 } finally {
4899 Binder.restoreCallingIdentity(identity);
4900 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004901 }
4902
4903 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004904 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4905 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004906
4907 final long identity = Binder.clearCallingIdentity();
4908 try {
4909 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004910 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004911 } finally {
4912 Binder.restoreCallingIdentity(identity);
4913 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004914 }
4915
4916 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004917 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4918 String callingPackage, int subId) {
4919 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004920
4921 final long identity = Binder.clearCallingIdentity();
4922 try {
4923 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004924 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004925 } finally {
4926 Binder.restoreCallingIdentity(identity);
4927 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004928 }
4929
4930 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004931 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004932 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004933
4934 final long identity = Binder.clearCallingIdentity();
4935 try {
4936 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004937 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004938 } finally {
4939 Binder.restoreCallingIdentity(identity);
4940 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004941 }
4942
4943 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004944 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4945 String callingAttributionTag, int subId, String number, int port, String text,
4946 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004947 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004948 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004949 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004950 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004951 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4952 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004953 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004954
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004955 /**
fionaxu0152e512016-11-14 13:36:14 -08004956 * Sets the voice activation state of a given subId.
4957 */
4958 @Override
4959 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004960 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4961 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004962
4963 final long identity = Binder.clearCallingIdentity();
4964 try {
4965 final Phone phone = getPhone(subId);
4966 if (phone != null) {
4967 phone.setVoiceActivationState(activationState);
4968 } else {
4969 loge("setVoiceActivationState fails with invalid subId: " + subId);
4970 }
4971 } finally {
4972 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004973 }
4974 }
4975
4976 /**
4977 * Sets the data activation state of a given subId.
4978 */
4979 @Override
4980 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004981 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4982 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004983
4984 final long identity = Binder.clearCallingIdentity();
4985 try {
4986 final Phone phone = getPhone(subId);
4987 if (phone != null) {
4988 phone.setDataActivationState(activationState);
4989 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004990 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004991 }
4992 } finally {
4993 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004994 }
4995 }
4996
4997 /**
4998 * Returns the voice activation state of a given subId.
4999 */
5000 @Override
5001 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005002 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005003
fionaxu0152e512016-11-14 13:36:14 -08005004 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005005 final long identity = Binder.clearCallingIdentity();
5006 try {
5007 if (phone != null) {
5008 return phone.getVoiceActivationState();
5009 } else {
5010 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
5011 }
5012 } finally {
5013 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08005014 }
5015 }
5016
5017 /**
5018 * Returns the data activation state of a given subId.
5019 */
5020 @Override
5021 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005022 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005023
fionaxu0152e512016-11-14 13:36:14 -08005024 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005025 final long identity = Binder.clearCallingIdentity();
5026 try {
5027 if (phone != null) {
5028 return phone.getDataActivationState();
5029 } else {
5030 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
5031 }
5032 } finally {
5033 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08005034 }
5035 }
5036
5037 /**
Wink Saville36469e72014-06-11 15:17:00 -07005038 * Returns the unread count of voicemails for a subId
5039 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005040 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005041 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
5042 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08005043 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005044 mApp, subId, callingPackage, callingFeatureId,
5045 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08005046 return 0;
5047 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005048 final long identity = Binder.clearCallingIdentity();
5049 try {
5050 final Phone phone = getPhone(subId);
5051 if (phone != null) {
5052 return phone.getVoiceMessageCount();
5053 } else {
5054 return 0;
5055 }
5056 } finally {
5057 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005058 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005059 }
5060
5061 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005062 * returns true, if the device is in a state where both voice and data
5063 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08005064 */
5065 @Override
5066 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005067 final long identity = Binder.clearCallingIdentity();
5068 try {
5069 final Phone phone = getPhone(subId);
5070 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
5071 } finally {
5072 Binder.restoreCallingIdentity(identity);
5073 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08005074 }
5075
5076 /**
fionaxu235cc5e2017-03-06 22:25:57 -08005077 * Send the dialer code if called from the current default dialer or the caller has
5078 * carrier privilege.
5079 * @param inputCode The dialer code to send
5080 */
5081 @Override
5082 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005083 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08005084 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07005085 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
5086 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08005087 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005088 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005089 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08005090 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005091
5092 final long identity = Binder.clearCallingIdentity();
5093 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005094 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005095 } finally {
5096 Binder.restoreCallingIdentity(identity);
5097 }
fionaxu235cc5e2017-03-06 22:25:57 -08005098 }
5099
Pengquan Menga1bb6272018-09-06 09:59:22 -07005100 @Override
5101 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08005102 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005103 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5104 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08005105 final long identity = Binder.clearCallingIdentity();
5106 try {
5107 if (!isActiveSubscription(subId)) {
5108 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
5109 }
5110 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
5111 } finally {
5112 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07005113 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005114 }
5115
Brad Ebinger35c841c2018-10-01 10:40:55 -07005116 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07005117 public boolean isInEmergencySmsMode() {
5118 enforceReadPrivilegedPermission("isInEmergencySmsMode");
5119 final long identity = Binder.clearCallingIdentity();
5120 try {
5121 for (Phone phone : PhoneFactory.getPhones()) {
5122 if (phone.isInEmergencySmsMode()) {
5123 return true;
5124 }
5125 }
5126 } finally {
5127 Binder.restoreCallingIdentity(identity);
5128 }
5129 return false;
5130 }
5131
shilu366312e2019-12-17 09:28:10 -08005132 /**
5133 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5134 * @param subId The subscription to use to check the configuration.
5135 * @param c The callback that will be used to send the result.
5136 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07005137 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005138 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
5139 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07005140 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005141 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00005142
5143 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5144 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5145 "IMS not available on device.");
5146 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07005147 final long token = Binder.clearCallingIdentity();
5148 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005149 int slotId = getSlotIndexOrException(subId);
5150 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00005151
5152 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5153 if (controller != null) {
5154 ImsManager imsManager = controller.getImsManager(subId);
5155 if (imsManager != null) {
5156 imsManager.addRegistrationCallbackForSubscription(c, subId);
5157 } else {
5158 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5159 }
5160 } else {
5161 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5162 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005163 } catch (ImsException e) {
5164 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005165 } finally {
5166 Binder.restoreCallingIdentity(token);
5167 }
5168 }
5169
shilu366312e2019-12-17 09:28:10 -08005170 /**
5171 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5172 * @param subId The subscription to use to check the configuration.
5173 * @param c The callback that will be used to send the result.
5174 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005175 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005176 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07005177 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005178 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005179 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5180 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5181 }
Meng Wangafbc5852019-09-19 17:37:13 -07005182 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00005183
Meng Wangafbc5852019-09-19 17:37:13 -07005184 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00005185 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5186 if (controller != null) {
5187 ImsManager imsManager = controller.getImsManager(subId);
5188 if (imsManager != null) {
5189 imsManager.removeRegistrationCallbackForSubscription(c, subId);
5190 } else {
5191 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
5192 + "is inactive, ignoring unregister.");
5193 // If the ImsManager is not valid, just return, since the callback
5194 // will already have been removed internally.
5195 }
5196 }
Meng Wangafbc5852019-09-19 17:37:13 -07005197 } finally {
5198 Binder.restoreCallingIdentity(token);
5199 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07005200 }
5201
Brad Ebingera34a6c22019-10-22 17:36:18 -07005202 /**
5203 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
5204 */
5205 @Override
5206 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
5207 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
5208 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5209 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5210 "IMS not available on device.");
5211 }
5212 final long token = Binder.clearCallingIdentity();
5213 try {
5214 Phone phone = getPhone(subId);
5215 if (phone == null) {
5216 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
5217 + subId + "'");
5218 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5219 }
5220 phone.getImsRegistrationState(regState -> {
5221 try {
5222 consumer.accept((regState == null)
5223 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
5224 } catch (RemoteException e) {
5225 // Ignore if the remote process is no longer available to call back.
5226 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
5227 }
5228 });
5229 } finally {
5230 Binder.restoreCallingIdentity(token);
5231 }
5232 }
5233
5234 /**
5235 * Get the transport type for the IMS service registration state.
5236 */
5237 @Override
5238 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07005239 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005240 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07005241 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5242 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5243 "IMS not available on device.");
5244 }
5245 final long token = Binder.clearCallingIdentity();
5246 try {
5247 Phone phone = getPhone(subId);
5248 if (phone == null) {
5249 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
5250 + subId + "'");
5251 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5252 }
5253 phone.getImsRegistrationTech(regTech -> {
5254 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
5255 int regTechConverted = (regTech == null)
5256 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
5257 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
5258 regTechConverted);
5259 try {
5260 consumer.accept(regTechConverted);
5261 } catch (RemoteException e) {
5262 // Ignore if the remote process is no longer available to call back.
5263 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
5264 }
5265 });
5266 } finally {
5267 Binder.restoreCallingIdentity(token);
5268 }
5269 }
5270
shilu366312e2019-12-17 09:28:10 -08005271 /**
5272 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5273 * @param subId The subscription to use to check the configuration.
5274 * @param c The callback that will be used to send the result.
5275 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005276 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005277 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
5278 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07005279 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005280 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00005281 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5282 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5283 "IMS not available on device.");
5284 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07005285 final long token = Binder.clearCallingIdentity();
5286 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005287 int slotId = getSlotIndexOrException(subId);
5288 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005289
5290 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5291 if (controller != null) {
5292 ImsManager imsManager = controller.getImsManager(subId);
5293 if (imsManager != null) {
5294 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
5295 } else {
5296 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5297 }
5298 } else {
5299 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5300 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005301 } catch (ImsException e) {
5302 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005303 } finally {
5304 Binder.restoreCallingIdentity(token);
5305 }
5306 }
5307
shilu366312e2019-12-17 09:28:10 -08005308 /**
5309 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5310 * @param subId The subscription to use to check the configuration.
5311 * @param c The callback that will be used to send the result.
5312 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005313 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005314 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07005315 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005316 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005317 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5318 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5319 }
Meng Wangafbc5852019-09-19 17:37:13 -07005320
5321 final long token = Binder.clearCallingIdentity();
5322 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005323 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5324 if (controller != null) {
5325 ImsManager imsManager = controller.getImsManager(subId);
5326 if (imsManager != null) {
5327 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
5328 } else {
5329 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
5330 + " is inactive, ignoring unregister.");
5331 // If the ImsManager is not valid, just return, since the callback
5332 // will already have been removed internally.
5333 }
5334 }
Meng Wangafbc5852019-09-19 17:37:13 -07005335 } finally {
5336 Binder.restoreCallingIdentity(token);
5337 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07005338 }
5339
5340 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005341 public boolean isCapable(int subId, int capability, int regTech) {
5342 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005343 final long token = Binder.clearCallingIdentity();
5344 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005345 int slotId = getSlotIndexOrException(subId);
5346 verifyImsMmTelConfiguredOrThrow(slotId);
5347 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
5348 } catch (com.android.ims.ImsException e) {
5349 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
5350 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005351 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08005352 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
5353 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07005354 } finally {
5355 Binder.restoreCallingIdentity(token);
5356 }
5357 }
5358
5359 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005360 public boolean isAvailable(int subId, int capability, int regTech) {
5361 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005362 final long token = Binder.clearCallingIdentity();
5363 try {
5364 Phone phone = getPhone(subId);
5365 if (phone == null) return false;
5366 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07005367 } catch (com.android.ims.ImsException e) {
5368 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
5369 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07005370 } finally {
5371 Binder.restoreCallingIdentity(token);
5372 }
5373 }
5374
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005375 /**
5376 * Determines if the MmTel feature capability is supported by the carrier configuration for this
5377 * subscription.
5378 * @param subId The subscription to use to check the configuration.
5379 * @param callback The callback that will be used to send the result.
5380 * @param capability The MmTelFeature capability that will be used to send the result.
5381 * @param transportType The transport type of the MmTelFeature capability.
5382 */
5383 @Override
5384 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
5385 int transportType) {
5386 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00005387 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5388 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5389 "IMS not available on device.");
5390 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005391 final long token = Binder.clearCallingIdentity();
5392 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005393 int slotId = getSlotIndex(subId);
5394 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5395 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
5396 + subId + "'");
5397 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5398 }
5399 verifyImsMmTelConfiguredOrThrow(slotId);
5400 ImsManager.getInstance(mApp, slotId).isSupported(capability,
5401 transportType, aBoolean -> {
5402 try {
5403 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
5404 } catch (RemoteException e) {
5405 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
5406 + "running. Ignore");
5407 }
5408 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005409 } catch (ImsException e) {
5410 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005411 } finally {
5412 Binder.restoreCallingIdentity(token);
5413 }
5414 }
5415
shilu366312e2019-12-17 09:28:10 -08005416 /**
5417 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5418 * @param subId The subscription to use to check the configuration.
5419 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005420 @Override
5421 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005422 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005423 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08005424
Brad Ebinger35c841c2018-10-01 10:40:55 -07005425 final long token = Binder.clearCallingIdentity();
5426 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005427 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005428 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005429 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005430 } catch (ImsException e) {
5431 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005432 } finally {
5433 Binder.restoreCallingIdentity(token);
5434 }
5435 }
5436
5437 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005438 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005439 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005440 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005441 final long identity = Binder.clearCallingIdentity();
5442 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005443 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005444 // This setting doesn't require an active ImsService connection, so do not verify. The
5445 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005446 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005447 } catch (ImsException e) {
5448 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005449 } finally {
5450 Binder.restoreCallingIdentity(identity);
5451 }
5452 }
5453
shilu366312e2019-12-17 09:28:10 -08005454 /**
5455 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5456 * @param subId The subscription to use to check the configuration.
5457 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005458 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005459 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005460 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005461 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005462 final long identity = Binder.clearCallingIdentity();
5463 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005464 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005465 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005466 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005467 } catch (ImsException e) {
5468 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005469 } finally {
5470 Binder.restoreCallingIdentity(identity);
5471 }
5472 }
5473
5474 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005475 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005476 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005477 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005478 final long identity = Binder.clearCallingIdentity();
5479 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005480 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005481 // This setting doesn't require an active ImsService connection, so do not verify. The
5482 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005483 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005484 } catch (ImsException e) {
5485 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005486 } finally {
5487 Binder.restoreCallingIdentity(identity);
5488 }
5489 }
5490
shilu366312e2019-12-17 09:28:10 -08005491 /**
5492 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5493 * @param subId The subscription to use to check the configuration.
5494 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005495 @Override
5496 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005497 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005498 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005499 final long identity = Binder.clearCallingIdentity();
5500 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005501 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005502 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005503 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005504 } catch (ImsException e) {
5505 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005506 } finally {
5507 Binder.restoreCallingIdentity(identity);
5508 }
5509 }
5510
5511 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005512 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005513 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005514 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005515 final long identity = Binder.clearCallingIdentity();
5516 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005517 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005518 // This setting doesn't require an active ImsService connection, so do not verify. The
5519 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005520 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005521 } catch (ImsException e) {
5522 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005523 } finally {
5524 Binder.restoreCallingIdentity(identity);
5525 }
5526 }
5527
shilu366312e2019-12-17 09:28:10 -08005528 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005529 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5530 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5531 * @param subId The subscription to use to check the configuration.
5532 */
5533 @Override
5534 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005535 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005536 mApp, subId, "isCrossSimCallingEnabledByUser");
5537 final long identity = Binder.clearCallingIdentity();
5538 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005539 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005540 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005541 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005542 } catch (ImsException e) {
5543 throw new ServiceSpecificException(e.getCode());
5544 } finally {
5545 Binder.restoreCallingIdentity(identity);
5546 }
5547 }
5548
5549 /**
5550 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5551 * Requires MODIFY_PHONE_STATE permission.
5552 * @param subId The subscription to use to check the configuration.
5553 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5554 * false otherwise
5555 */
5556 @Override
5557 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5559 "setCrossSimCallingEnabled");
5560 final long identity = Binder.clearCallingIdentity();
5561 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005562 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005563 // This setting doesn't require an active ImsService connection, so do not verify. The
5564 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005565 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005566 } catch (ImsException e) {
5567 throw new ServiceSpecificException(e.getCode());
5568 } finally {
5569 Binder.restoreCallingIdentity(identity);
5570 }
5571 }
5572
5573 /**
shilu366312e2019-12-17 09:28:10 -08005574 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5575 * @param subId The subscription to use to check the configuration.
5576 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005577 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005578
Brad Ebinger35c841c2018-10-01 10:40:55 -07005579 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005580 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005581 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005582 final long identity = Binder.clearCallingIdentity();
5583 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005584 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005585 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005586 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005587 } catch (ImsException e) {
5588 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005589 } finally {
5590 Binder.restoreCallingIdentity(identity);
5591 }
5592 }
5593
5594 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005595 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005597 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005598 final long identity = Binder.clearCallingIdentity();
5599 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005600 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005601 // This setting doesn't require an active ImsService connection, so do not verify. The
5602 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005603 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005604 } catch (ImsException e) {
5605 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005606 } finally {
5607 Binder.restoreCallingIdentity(identity);
5608 }
5609 }
5610
5611 @Override
5612 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5614 "setVoWiFiNonPersistent");
5615 final long identity = Binder.clearCallingIdentity();
5616 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005617 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005618 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005619 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005620 } catch (ImsException e) {
5621 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005622 } finally {
5623 Binder.restoreCallingIdentity(identity);
5624 }
5625 }
5626
shilu366312e2019-12-17 09:28:10 -08005627 /**
5628 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5629 * @param subId The subscription to use to check the configuration.
5630 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005631 @Override
5632 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005633 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005634 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005635 final long identity = Binder.clearCallingIdentity();
5636 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005637 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005638 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005639 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005640 } catch (ImsException e) {
5641 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005642 } finally {
5643 Binder.restoreCallingIdentity(identity);
5644 }
5645 }
5646
5647 @Override
5648 public void setVoWiFiModeSetting(int subId, int mode) {
5649 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5650 "setVoWiFiModeSetting");
5651 final long identity = Binder.clearCallingIdentity();
5652 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005653 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005654 // This setting doesn't require an active ImsService connection, so do not verify. The
5655 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005656 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005657 } catch (ImsException e) {
5658 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005659 } finally {
5660 Binder.restoreCallingIdentity(identity);
5661 }
5662 }
5663
5664 @Override
5665 public int getVoWiFiRoamingModeSetting(int subId) {
5666 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
5667 final long identity = Binder.clearCallingIdentity();
5668 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005669 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005670 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005671 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005672 } catch (ImsException e) {
5673 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005674 } finally {
5675 Binder.restoreCallingIdentity(identity);
5676 }
5677 }
5678
5679 @Override
5680 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5682 "setVoWiFiRoamingModeSetting");
5683 final long identity = Binder.clearCallingIdentity();
5684 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005685 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005686 // This setting doesn't require an active ImsService connection, so do not verify. The
5687 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005688 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005689 } catch (ImsException e) {
5690 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005691 } finally {
5692 Binder.restoreCallingIdentity(identity);
5693 }
5694 }
5695
5696 @Override
5697 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5699 "setRttCapabilityEnabled");
5700 final long identity = Binder.clearCallingIdentity();
5701 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005702 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005703 // This setting doesn't require an active ImsService connection, so do not verify. The
5704 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005705 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005706 } catch (ImsException e) {
5707 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005708 } finally {
5709 Binder.restoreCallingIdentity(identity);
5710 }
5711 }
5712
shilu366312e2019-12-17 09:28:10 -08005713 /**
5714 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5715 * @param subId The subscription to use to check the configuration.
5716 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005717 @Override
5718 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005719 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005720 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005721 final long identity = Binder.clearCallingIdentity();
5722 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005723 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005724 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005725 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005726 } catch (ImsException e) {
5727 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005728 } finally {
5729 Binder.restoreCallingIdentity(identity);
5730 }
5731 }
5732
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005733 @Override
5734 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5735 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005736
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005737 final long identity = Binder.clearCallingIdentity();
5738 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005739 if (!isImsAvailableOnDevice()) {
5740 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5741 "IMS not available on device.");
5742 }
5743 int slotId = getSlotIndexOrException(subId);
5744 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005745
5746 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5747 if (controller != null) {
5748 ImsManager imsManager = controller.getImsManager(subId);
5749 if (imsManager != null) {
5750 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5751 } else {
5752 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5753 }
5754 } else {
5755 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5756 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005757 } catch (ImsException e) {
5758 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005759 } finally {
5760 Binder.restoreCallingIdentity(identity);
5761 }
5762 }
5763
5764 @Override
5765 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5766 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005767
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005768 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005769 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5770 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5771 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005772 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005773 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5774 if (controller != null) {
5775 ImsManager imsManager = controller.getImsManager(subId);
5776 if (imsManager != null) {
5777 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5778 } else {
5779 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5780 + " is inactive, ignoring unregister.");
5781 // If the ImsManager is not valid, just return, since the callback will already
5782 // have been removed internally.
5783 }
5784 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005785 } finally {
5786 Binder.restoreCallingIdentity(identity);
5787 }
5788 }
5789
joonhunshincffb7fc2021-11-28 07:32:01 +00005790 @Override
5791 public void registerFeatureProvisioningChangedCallback(int subId,
5792 IFeatureProvisioningCallback callback) {
5793 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5794 mApp, subId, "registerFeatureProvisioningChangedCallback");
5795
5796 final long identity = Binder.clearCallingIdentity();
5797 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5798 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5799 }
5800
joonhunshin91bc1952022-04-29 08:47:15 +00005801 try {
5802 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5803 if (controller == null) {
5804 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5805 "Device does not support IMS");
5806 }
5807 controller.addFeatureProvisioningChangedCallback(subId, callback);
5808 } finally {
5809 Binder.restoreCallingIdentity(identity);
5810 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005811 }
5812
5813 @Override
5814 public void unregisterFeatureProvisioningChangedCallback(int subId,
5815 IFeatureProvisioningCallback callback) {
5816 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5817 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5818
5819 final long identity = Binder.clearCallingIdentity();
5820 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5821 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5822 }
5823
joonhunshin91bc1952022-04-29 08:47:15 +00005824 try {
5825 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5826 if (controller == null) {
5827 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5828 return;
5829 }
5830 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5831 } finally {
5832 Binder.restoreCallingIdentity(identity);
5833 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005834 }
allenwtsu99c623b2020-01-03 18:24:23 +08005835
5836 private void checkModifyPhoneStatePermission(int subId, String message) {
5837 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5838 message);
5839 }
5840
allenwtsu99c623b2020-01-03 18:24:23 +08005841 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005842 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005843 boolean isProvisioned) {
5844 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5845
5846 final long identity = Binder.clearCallingIdentity();
5847 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005848 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5849 if (controller == null) {
5850 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5851 return;
5852 }
5853 controller.setRcsProvisioningStatusForCapability(
5854 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005855 } finally {
5856 Binder.restoreCallingIdentity(identity);
5857 }
allenwtsu99c623b2020-01-03 18:24:23 +08005858 }
5859
5860
5861 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005862 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5863 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5864 mApp, subId, "getRcsProvisioningStatusForCapability");
5865
allenwtsu99c623b2020-01-03 18:24:23 +08005866 final long identity = Binder.clearCallingIdentity();
5867 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005868 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5869 if (controller == null) {
5870 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5871
5872 // device does not support IMS, this method will return true always.
5873 return true;
5874 }
5875 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005876 } finally {
5877 Binder.restoreCallingIdentity(identity);
5878 }
5879 }
5880
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005881 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005882 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5883 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005884 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005885
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005886 final long identity = Binder.clearCallingIdentity();
5887 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005888 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5889 if (controller == null) {
5890 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5891 return;
5892 }
5893 controller.setImsProvisioningStatusForCapability(
5894 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005895 } finally {
5896 Binder.restoreCallingIdentity(identity);
5897 }
5898 }
5899
5900 @Override
5901 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005902 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5903 mApp, subId, "getProvisioningStatusForCapability");
5904
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005905 final long identity = Binder.clearCallingIdentity();
5906 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005907 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5908 if (controller == null) {
5909 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005910
joonhunshin91bc1952022-04-29 08:47:15 +00005911 // device does not support IMS, this method will return true always.
5912 return true;
5913 }
5914 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005915 } finally {
5916 Binder.restoreCallingIdentity(identity);
5917 }
5918 }
5919
5920 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005921 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5922 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5923 mApp, subId, "isProvisioningRequiredForCapability");
5924
5925 final long identity = Binder.clearCallingIdentity();
5926 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005927 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5928 if (controller == null) {
5929 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5930
5931 // device does not support IMS, this method will return false
5932 return false;
5933 }
5934 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005935 } finally {
5936 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005937 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005938 }
5939
5940 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005941 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5942 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5943 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005944
joonhunshincffb7fc2021-11-28 07:32:01 +00005945 final long identity = Binder.clearCallingIdentity();
5946 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005947 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5948 if (controller == null) {
5949 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5950
5951 // device does not support IMS, this method will return false
5952 return false;
5953 }
5954 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005955 } finally {
5956 Binder.restoreCallingIdentity(identity);
5957 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005958 }
5959
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005960 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005961 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005962 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5963 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5964 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005965 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5966 mApp, subId, "getImsProvisioningInt");
5967
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005968 final long identity = Binder.clearCallingIdentity();
5969 try {
5970 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005971 int slotId = getSlotIndex(subId);
5972 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5973 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5974 + subId + "' for key:" + key);
5975 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5976 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005977
joonhunshin91bc1952022-04-29 08:47:15 +00005978 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5979 if (controller == null) {
5980 loge("getImsProvisioningInt: Device does not support IMS");
5981
5982 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5983 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5984 }
5985 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005986 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5987 return retVal;
5988 }
5989
calvinpanb5a34062021-02-08 19:59:36 +08005990 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005991 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005992 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5993 + subId + "' for key:" + key);
5994 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005995 } finally {
5996 Binder.restoreCallingIdentity(identity);
5997 }
5998 }
5999
6000 @Override
6001 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006002 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
6003 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
6004 }
joonhunshincffb7fc2021-11-28 07:32:01 +00006005 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6006 mApp, subId, "getImsProvisioningString");
6007
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07006008 final long identity = Binder.clearCallingIdentity();
6009 try {
6010 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006011 int slotId = getSlotIndex(subId);
6012 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6013 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
6014 + subId + "' for key:" + key);
6015 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
6016 }
calvinpanb5a34062021-02-08 19:59:36 +08006017 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07006018 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006019 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
6020 + subId + "' for key:" + key);
6021 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07006022 } finally {
6023 Binder.restoreCallingIdentity(identity);
6024 }
6025 }
6026
6027 @Override
6028 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006029 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
6030 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
6031 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08006032 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
6033 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00006034
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07006035 final long identity = Binder.clearCallingIdentity();
6036 try {
6037 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006038 int slotId = getSlotIndex(subId);
6039 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6040 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
6041 + subId + "' for key:" + key);
6042 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
6043 }
joonhunshincffb7fc2021-11-28 07:32:01 +00006044
joonhunshin91bc1952022-04-29 08:47:15 +00006045 ImsProvisioningController controller = ImsProvisioningController.getInstance();
6046 if (controller == null) {
6047 loge("setImsProvisioningInt: Device does not support IMS");
6048
6049 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
6050 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
6051 }
6052 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00006053 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
6054 return retVal;
6055 }
6056
calvinpanb5a34062021-02-08 19:59:36 +08006057 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
6058 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006059 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08006060 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006061 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07006062 } finally {
6063 Binder.restoreCallingIdentity(identity);
6064 }
6065 }
6066
6067 @Override
6068 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006069 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
6070 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
6071 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08006072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
6073 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07006074 final long identity = Binder.clearCallingIdentity();
6075 try {
6076 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006077 int slotId = getSlotIndex(subId);
6078 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6079 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
6080 + subId + "' for key:" + key);
6081 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
6082 }
calvinpanb5a34062021-02-08 19:59:36 +08006083 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
6084 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006085 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08006086 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006087 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07006088 } finally {
6089 Binder.restoreCallingIdentity(identity);
6090 }
6091 }
6092
Brad Ebinger919631e2021-06-02 17:46:35 -07006093 /**
6094 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
6095 * for the given slot ID or no ImsResolver instance has been created.
6096 * @param slotId The slot ID that the IMS service is created for.
6097 * @throws ImsException If there is no ImsService configured for this slot.
6098 */
6099 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
6100 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
6101 ImsFeature.FEATURE_MMTEL)) {
6102 throw new ImsException("This subscription does not support MMTEL over IMS",
6103 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
6104 }
6105 }
6106
Brad Ebinger1ce9c432019-07-16 13:19:44 -07006107 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006108 int slotId = SubscriptionManager.getSlotIndex(subId);
6109 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07006110 throw new ImsException("Invalid Subscription Id, subId=" + subId,
6111 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07006112 }
6113 return slotId;
6114 }
6115
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006116 private int getSlotIndex(int subId) {
6117 int slotId = SubscriptionManager.getSlotIndex(subId);
6118 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
6119 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
6120 }
6121 return slotId;
6122 }
6123
Wink Saville36469e72014-06-11 15:17:00 -07006124 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07006125 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07006126 */
6127 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006128 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
6129 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07006130 try {
6131 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6132 } catch (SecurityException se) {
6133 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
6134 throw new SecurityException("Package " + callingPackage + " does not belong to "
6135 + Binder.getCallingUid());
6136 }
Nathan Haroldf096d982020-11-18 17:18:06 -08006137 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07006138 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006139 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07006140 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07006141 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006142 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006143 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006144 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
6145 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07006146
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006147 final long identity = Binder.clearCallingIdentity();
6148 try {
6149 final Phone phone = getPhone(subId);
6150 if (phone != null) {
6151 return phone.getServiceState().getDataNetworkType();
6152 } else {
6153 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
6154 }
6155 } finally {
6156 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006157 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006158 }
6159
6160 /**
6161 * Returns the data network type
6162 */
6163 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006164 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08006165 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08006166 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07006167 }
6168
6169 /**
6170 * Returns the data network type for a subId
6171 */
6172 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006173 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
6174 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006175 String functionName = "getDataNetworkTypeForSubscriber";
6176 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
6177 mApp, functionName)) {
6178 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6179 mApp, subId, callingPackage, callingFeatureId, functionName)) {
6180 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
6181 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006182 }
6183
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006184 final long identity = Binder.clearCallingIdentity();
6185 try {
6186 final Phone phone = getPhone(subId);
6187 if (phone != null) {
6188 return phone.getServiceState().getDataNetworkType();
6189 } else {
6190 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
6191 }
6192 } finally {
6193 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006195 }
6196
6197 /**
Wink Saville36469e72014-06-11 15:17:00 -07006198 * Returns the Voice network type for a subId
6199 */
6200 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006201 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
6202 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006203 String functionName = "getVoiceNetworkTypeForSubscriber";
6204 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
6205 mApp, functionName)) {
6206 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6207 mApp, subId, callingPackage, callingFeatureId, functionName)) {
6208 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
6209 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07006210 }
6211
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006212 final long identity = Binder.clearCallingIdentity();
6213 try {
6214 final Phone phone = getPhone(subId);
6215 if (phone != null) {
6216 return phone.getServiceState().getVoiceNetworkType();
6217 } else {
6218 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
6219 }
6220 } finally {
6221 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006222 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006223 }
6224
6225 /**
6226 * @return true if a ICC card is present
6227 */
6228 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07006229 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08006230 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006231 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07006232 }
6233
6234 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006235 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07006236 */
Sanket Padawe356d7632015-06-22 14:03:32 -07006237 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006238 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006239 final long identity = Binder.clearCallingIdentity();
6240 try {
6241 final Phone phone = PhoneFactory.getPhone(slotIndex);
6242 if (phone != null) {
6243 return phone.getIccCard().hasIccCard();
6244 } else {
6245 return false;
6246 }
6247 } finally {
6248 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08006249 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006250 }
6251
6252 /**
6253 * Return if the current radio is LTE on CDMA. This
6254 * is a tri-state return value as for a period of time
6255 * the mode may be unknown.
6256 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006257 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006258 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08006259 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006260 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006261 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006262 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
6263 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
6264 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07006265 }
6266
Sanket Padawe356d7632015-06-22 14:03:32 -07006267 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006268 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
6269 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08006270 try {
6271 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
6272 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006273 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
6274 }
6275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006276 final long identity = Binder.clearCallingIdentity();
6277 try {
6278 final Phone phone = getPhone(subId);
6279 if (phone == null) {
6280 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
6281 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07006282 return TelephonyProperties.lte_on_cdma_device()
6283 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006284 }
6285 } finally {
6286 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006287 }
Wink Saville36469e72014-06-11 15:17:00 -07006288 }
6289
Wink Saville36469e72014-06-11 15:17:00 -07006290 /**
6291 * {@hide}
6292 * Returns Default subId, 0 in the case of single standby.
6293 */
Wink Savilleb564aae2014-10-23 10:18:09 -07006294 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08006295 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07006296 }
6297
Shishir Agrawala9f32182016-04-12 12:00:16 -07006298 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08006299 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07006300 }
6301
Wink Savilleb564aae2014-10-23 10:18:09 -07006302 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08006303 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006304 }
Ihab Awadf2177b72013-11-25 13:33:23 -08006305
Pengquan Menge92a50d2018-09-21 15:54:48 -07006306 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08006307 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08006308 return getSubscriptionManagerService().isActiveSubId(subId,
Jack Yu285100e2022-12-02 22:48:35 -08006309 mApp.getOpPackageName(), mApp.getFeatureId());
6310 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07006311 return mSubscriptionController.isActiveSubId(subId);
6312 }
6313
Ihab Awadf2177b72013-11-25 13:33:23 -08006314 /**
6315 * @see android.telephony.TelephonyManager.WifiCallingChoices
6316 */
6317 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006318 final long identity = Binder.clearCallingIdentity();
6319 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006320 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006321 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
6322 getWhenToMakeWifiCallsDefaultPreference());
6323 } finally {
6324 Binder.restoreCallingIdentity(identity);
6325 }
Ihab Awadf2177b72013-11-25 13:33:23 -08006326 }
6327
6328 /**
6329 * @see android.telephony.TelephonyManager.WifiCallingChoices
6330 */
6331 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332 final long identity = Binder.clearCallingIdentity();
6333 try {
6334 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006335 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006336 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
6337 } finally {
6338 Binder.restoreCallingIdentity(identity);
6339 }
Ihab Awadf9e92732013-12-05 18:02:52 -08006340 }
6341
Sailesh Nepald1e68152013-12-12 19:08:02 -08006342 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07006343 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08006344 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08006345 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08006346
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006347 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
6348 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
6349 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08006350 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006351 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006352 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08006353 }
6354 return PhoneFactory.getPhone(phoneId);
6355 }
6356
Shishir Agrawal566b7612013-10-28 14:41:00 -07006357 @Override
Derek Tan740e1672017-06-27 14:56:27 -07006358 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08006359 @NonNull IccLogicalChannelRequest request) {
6360 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6361 /*message=*/ "iccOpenLogicalChannel");
6362
6363 if (DBG) log("iccOpenLogicalChannel: request=" + request);
6364 // Verify that the callingPackage in the request belongs to the calling UID
6365 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
6366
6367 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006368 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006369
Rambo Wanga1782702021-11-10 20:15:19 -08006370 private Phone getPhoneFromValidIccLogicalChannelRequest(
6371 @NonNull IccLogicalChannelRequest request, String message) {
6372 Phone phone;
6373 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
6374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6375 mApp, request.subId, message);
6376 phone = getPhoneFromSubId(request.subId);
6377 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6378 enforceModifyPermission();
6379 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
6380 } else {
6381 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08006382 }
Rambo Wanga1782702021-11-10 20:15:19 -08006383 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08006384 }
6385
6386 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08006387 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006388 final long identity = Binder.clearCallingIdentity();
6389 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006390 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006391 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006392 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6393 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08006394 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
6395 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006396 loge("The calling package is not allowed to access ISD-R.");
6397 throw new SecurityException(
6398 "The calling package is not allowed to access ISD-R.");
6399 }
Derek Tan740e1672017-06-27 14:56:27 -07006400 }
Derek Tan740e1672017-06-27 14:56:27 -07006401
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006402 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006403 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6404 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405 return response;
6406 } finally {
6407 Binder.restoreCallingIdentity(identity);
6408 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006409 }
6410
6411 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006412 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
6413 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6414 /*message=*/"iccCloseLogicalChannel");
6415
6416 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6417
6418 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006419 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006420
Rambo Wanga1782702021-11-10 20:15:19 -08006421 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6422 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006423 // before this feature is enabled, this API should only return false if
6424 // the operation fails instead of throwing runtime exception for
6425 // backward-compatibility.
6426 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6427 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006428 final long identity = Binder.clearCallingIdentity();
6429 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006430 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006431 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006432 }
Chen Xue9d737e2022-01-01 23:41:31 -08006433 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006434 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006435 Boolean success = false;
6436 if (result instanceof RuntimeException) {
6437 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006438 if (shouldThrowExceptionOnFailure) {
6439 throw (RuntimeException) result;
6440 } else {
6441 return false;
6442 }
Chen Xue9d737e2022-01-01 23:41:31 -08006443 } else if (result instanceof Boolean) {
6444 success = (Boolean) result;
6445 } else {
6446 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6447 }
Rambo Wanga1782702021-11-10 20:15:19 -08006448 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006449 return success;
6450 } finally {
6451 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006452 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006453 }
6454
6455 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006456 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006457 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6459 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08006460 if (DBG) {
6461 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6462 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6463 + p3 + " data=" + data);
6464 }
6465 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6466 command, p1, p2, p3, data);
6467 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006468
Jordan Liu4c733742019-02-28 12:03:40 -08006469 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006470 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006471 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006472 enforceModifyPermission();
6473 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006474 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006475 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6476 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006477 }
6478 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006479 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6480 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006481 }
6482
6483 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6484 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006485 final long identity = Binder.clearCallingIdentity();
6486 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006487 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006488 return "";
6489 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006490
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006491 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006492 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6493 null /* workSource */);
6494 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006495
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006496 // Append the returned status code to the end of the response payload.
6497 String s = Integer.toHexString(
6498 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6499 if (response.payload != null) {
6500 s = IccUtils.bytesToHexString(response.payload) + s;
6501 }
6502 return s;
6503 } finally {
6504 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006505 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006506 }
Jake Hambye994d462014-02-03 13:10:13 -08006507
Evan Charltonc66da362014-05-16 14:06:40 -07006508 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006509 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6510 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006511 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6512 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006513 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08006514 if (DBG) {
6515 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6516 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6517 }
6518 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6519 cla, command, p1, p2, p3, data);
6520 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006521
Jordan Liu4c733742019-02-28 12:03:40 -08006522 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006523 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006524 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006525 enforceModifyPermission();
6526 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6527 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006528 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006529 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6530 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006531 }
6532
6533 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006534 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6535 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006536 }
6537
6538 // open APDU basic channel assuming the caller has sufficient permissions
6539 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6540 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006541 final long identity = Binder.clearCallingIdentity();
6542 try {
6543 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6544 && TextUtils.equals(ISDR_AID, data)) {
6545 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006546 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6547 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006548 if (bestComponent == null
6549 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6550 loge("The calling package is not allowed to select ISD-R.");
6551 throw new SecurityException(
6552 "The calling package is not allowed to select ISD-R.");
6553 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006554 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006555
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006556 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006557 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6558 null /* workSource */);
6559 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006560
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006561 // Append the returned status code to the end of the response payload.
6562 String s = Integer.toHexString(
6563 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6564 if (response.payload != null) {
6565 s = IccUtils.bytesToHexString(response.payload) + s;
6566 }
6567 return s;
6568 } finally {
6569 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006570 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006571 }
6572
6573 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006574 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006575 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6577 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006578
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006579 final long identity = Binder.clearCallingIdentity();
6580 try {
6581 if (DBG) {
6582 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6583 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6584 }
6585
6586 IccIoResult response =
6587 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6588 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6589 subId);
6590
6591 if (DBG) {
6592 log("Exchange SIM_IO [R]" + response);
6593 }
6594
6595 byte[] result = null;
6596 int length = 2;
6597 if (response.payload != null) {
6598 length = 2 + response.payload.length;
6599 result = new byte[length];
6600 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6601 } else {
6602 result = new byte[length];
6603 }
6604
6605 result[length - 1] = (byte) response.sw2;
6606 result[length - 2] = (byte) response.sw1;
6607 return result;
6608 } finally {
6609 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006610 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006611 }
6612
Nathan Haroldb3014052017-01-25 15:57:32 -08006613 /**
6614 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6615 * on a particular subscription
6616 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006617 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6618 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006619 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006620 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006621 return null;
6622 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006623
6624 final long identity = Binder.clearCallingIdentity();
6625 try {
6626 if (appType != TelephonyManager.APPTYPE_USIM
6627 && appType != TelephonyManager.APPTYPE_SIM) {
6628 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6629 return null;
6630 }
6631 Object response = sendRequest(
6632 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6633 if (response instanceof String[]) {
6634 return (String[]) response;
6635 }
yincheng zhao2737e882019-09-06 17:06:54 -07006636 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006637 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006638 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006639 } finally {
6640 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006641 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006642 }
6643
yincheng zhao2737e882019-09-06 17:06:54 -07006644 /**
6645 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6646 * subscription.
6647 *
6648 * @param subId the id of the subscription.
6649 * @param appType the uicc app type, must be USIM or SIM.
6650 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6651 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006652 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006653 * @return number of fplmns that is successfully written to the SIM.
6654 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006655 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6656 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6658 mApp, subId, "setForbiddenPlmns");
6659
yincheng zhao2737e882019-09-06 17:06:54 -07006660 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6661 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6662 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6663 }
6664 if (fplmns == null) {
6665 throw new IllegalArgumentException("Fplmn List provided is null");
6666 }
6667 for (String fplmn : fplmns) {
6668 if (!CellIdentity.isValidPlmn(fplmn)) {
6669 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6670 }
6671 }
6672 final long identity = Binder.clearCallingIdentity();
6673 try {
6674 Object response = sendRequest(
6675 CMD_SET_FORBIDDEN_PLMNS,
6676 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6677 subId);
6678 return (int) response;
6679 } finally {
6680 Binder.restoreCallingIdentity(identity);
6681 }
6682 }
6683
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006684 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006685 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006686 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6687 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006688
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006689 final long identity = Binder.clearCallingIdentity();
6690 try {
6691 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6692 if (response.payload == null) {
6693 return "";
6694 }
Evan Charltonc66da362014-05-16 14:06:40 -07006695
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006696 // Append the returned status code to the end of the response payload.
6697 String s = Integer.toHexString(
6698 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6699 s = IccUtils.bytesToHexString(response.payload) + s;
6700 return s;
6701 } finally {
6702 Binder.restoreCallingIdentity(identity);
6703 }
Evan Charltonc66da362014-05-16 14:06:40 -07006704 }
6705
Jake Hambye994d462014-02-03 13:10:13 -08006706 /**
6707 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6708 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6709 *
6710 * @param itemID the ID of the item to read
6711 * @return the NV item as a String, or null on error.
6712 */
6713 @Override
6714 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006715 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006716 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6717 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006718
6719 final long identity = Binder.clearCallingIdentity();
6720 try {
6721 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006722 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006723 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6724 return value;
6725 } finally {
6726 Binder.restoreCallingIdentity(identity);
6727 }
Jake Hambye994d462014-02-03 13:10:13 -08006728 }
6729
6730 /**
6731 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6732 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6733 *
6734 * @param itemID the ID of the item to read
6735 * @param itemValue the value to write, as a String
6736 * @return true on success; false on any failure
6737 */
6738 @Override
6739 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006740 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006741 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6742 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006743
6744 final long identity = Binder.clearCallingIdentity();
6745 try {
6746 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6747 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006748 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006749 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6750 return success;
6751 } finally {
6752 Binder.restoreCallingIdentity(identity);
6753 }
Jake Hambye994d462014-02-03 13:10:13 -08006754 }
6755
6756 /**
6757 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6758 * Used for device configuration by some CDMA operators.
6759 *
6760 * @param preferredRoamingList byte array containing the new PRL
6761 * @return true on success; false on any failure
6762 */
6763 @Override
6764 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006765 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6766 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006767
6768 final long identity = Binder.clearCallingIdentity();
6769 try {
6770 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6771 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6772 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6773 return success;
6774 } finally {
6775 Binder.restoreCallingIdentity(identity);
6776 }
Jake Hambye994d462014-02-03 13:10:13 -08006777 }
6778
6779 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006780 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006781 * Used for device configuration by some CDMA operators.
6782 *
chen xu6dac5ab2018-10-26 17:39:23 -07006783 * @param slotIndex - device slot.
6784 *
Jake Hambye994d462014-02-03 13:10:13 -08006785 * @return true on success; false on any failure
6786 */
6787 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006788 public boolean resetModemConfig(int slotIndex) {
6789 Phone phone = PhoneFactory.getPhone(slotIndex);
6790 if (phone != null) {
6791 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6792 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006793
chen xu6dac5ab2018-10-26 17:39:23 -07006794 final long identity = Binder.clearCallingIdentity();
6795 try {
6796 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6797 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6798 return success;
6799 } finally {
6800 Binder.restoreCallingIdentity(identity);
6801 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006802 }
chen xu6dac5ab2018-10-26 17:39:23 -07006803 return false;
6804 }
6805
6806 /**
6807 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6808 *
6809 * @param slotIndex - device slot.
6810 *
6811 * @return true on success; false on any failure
6812 */
6813 @Override
6814 public boolean rebootModem(int slotIndex) {
6815 Phone phone = PhoneFactory.getPhone(slotIndex);
6816 if (phone != null) {
6817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6818 mApp, phone.getSubId(), "rebootModem");
6819
6820 final long identity = Binder.clearCallingIdentity();
6821 try {
6822 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6823 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6824 return success;
6825 } finally {
6826 Binder.restoreCallingIdentity(identity);
6827 }
6828 }
6829 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006830 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006831
Brad Ebinger51f743a2017-01-23 13:50:20 -08006832 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006833 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6834 * {@link #disableIms(int)}.
6835 * @param slotIndex device slot.
6836 */
6837 public void resetIms(int slotIndex) {
6838 enforceModifyPermission();
6839
6840 final long identity = Binder.clearCallingIdentity();
6841 try {
6842 if (mImsResolver == null) {
6843 // may happen if the does not support IMS.
6844 return;
6845 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006846 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006847 } finally {
6848 Binder.restoreCallingIdentity(identity);
6849 }
6850 }
6851
6852 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006853 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6854 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006855 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006856 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006857 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006858
6859 final long identity = Binder.clearCallingIdentity();
6860 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006861 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006862 // may happen if the device does not support IMS.
6863 return;
6864 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006865 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006866 } finally {
6867 Binder.restoreCallingIdentity(identity);
6868 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006869 }
6870
6871 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006872 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6873 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006874 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006875 public void disableIms(int slotId) {
6876 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006877
6878 final long identity = Binder.clearCallingIdentity();
6879 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006880 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006881 // may happen if the device does not support IMS.
6882 return;
6883 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006884 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006885 } finally {
6886 Binder.restoreCallingIdentity(identity);
6887 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006888 }
6889
6890 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006891 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6892 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006893 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006894 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006895 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006896 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006897
6898 final long identity = Binder.clearCallingIdentity();
6899 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006900 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006901 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6902 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006903 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006904 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006905 } finally {
6906 Binder.restoreCallingIdentity(identity);
6907 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006908 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006909 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006910 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6911 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006912 @Override
6913 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006914 enforceModifyPermission();
6915
6916 final long identity = Binder.clearCallingIdentity();
6917 try {
6918 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006919 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006920 } finally {
6921 Binder.restoreCallingIdentity(identity);
6922 }
6923 }
6924
6925 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006926 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006927 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006928 */
6929 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6930 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006931
6932 final long identity = Binder.clearCallingIdentity();
6933 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006934 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006935 // may happen if the device does not support IMS.
6936 return null;
6937 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006938 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006939 } finally {
6940 Binder.restoreCallingIdentity(identity);
6941 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006942 }
6943
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006944 /**
6945 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006946 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006947 */
6948 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6949 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006950
6951 final long identity = Binder.clearCallingIdentity();
6952 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006953 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006954 // may happen if the device does not support IMS.
6955 return null;
6956 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006957 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006958 } finally {
6959 Binder.restoreCallingIdentity(identity);
6960 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006961 }
6962
Brad Ebinger884c07b2018-02-15 16:17:40 -08006963 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006964 * Sets the ImsService Package Name that Telephony will bind to.
6965 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006966 * @param slotIndex the slot ID that the ImsService should bind for.
6967 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006968 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006969 * @param featureTypes An integer array of feature types associated with a packageName.
6970 * @param packageName The name of the package that the current configuration will be replaced
6971 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006972 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006973 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006974 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6975 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006976 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006978 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006979
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006980 final long identity = Binder.clearCallingIdentity();
6981 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006982 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006983 // may happen if the device does not support IMS.
6984 return false;
6985 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006986 Map<Integer, String> featureConfig = new HashMap<>();
6987 for (int featureType : featureTypes) {
6988 featureConfig.put(featureType, packageName);
6989 }
6990 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6991 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006992 } finally {
6993 Binder.restoreCallingIdentity(identity);
6994 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006995 }
6996
6997 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006998 * Clears any carrier ImsService overrides for the slot index specified that were previously
6999 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
7000 *
7001 * This should only be used for testing.
7002 *
7003 * @param slotIndex the slot ID that the ImsService should bind for.
7004 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
7005 */
7006 @Override
7007 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08007008 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7009 "clearCarrierImsServiceOverride");
7010 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08007011 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08007012
7013 final long identity = Binder.clearCallingIdentity();
7014 try {
7015 if (mImsResolver == null) {
7016 // may happen if the device does not support IMS.
7017 return false;
7018 }
7019 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
7020 } finally {
7021 Binder.restoreCallingIdentity(identity);
7022 }
7023 }
7024
7025 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08007026 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07007027 *
7028 * @param slotId The slot that the ImsService is associated with.
7029 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
7030 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08007031 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07007032 * @return the package name of the ImsService configuration.
7033 */
Brad Ebinger24c29992019-12-05 13:03:21 -08007034 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
7035 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08007036 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08007037 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
7038 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07007039
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007040 final long identity = Binder.clearCallingIdentity();
7041 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08007042 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08007043 // may happen if the device does not support IMS.
7044 return "";
7045 }
Brad Ebingera80c3312019-12-02 10:59:39 -08007046 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08007047 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
7048 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007049 } finally {
7050 Binder.restoreCallingIdentity(identity);
7051 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07007052 }
7053
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007054 /**
7055 * Get the MmTelFeature state associated with the requested subscription id.
7056 * @param subId The subscription that the MmTelFeature is associated with.
7057 * @param callback A callback with an integer containing the
7058 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
7059 */
7060 @Override
7061 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
7062 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00007063 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
7064 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
7065 "IMS not available on device.");
7066 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007067 final long token = Binder.clearCallingIdentity();
7068 try {
Brad Ebingera2628302022-02-18 03:44:55 +00007069 int slotId = getSlotIndex(subId);
7070 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7071 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
7072 + subId + "'");
7073 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
7074 }
7075 verifyImsMmTelConfiguredOrThrow(slotId);
7076 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
7077 try {
7078 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
7079 } catch (RemoteException e) {
7080 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
7081 + "Ignore");
7082 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007083 });
Brad Ebinger919631e2021-06-02 17:46:35 -07007084 } catch (ImsException e) {
7085 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007086 } finally {
7087 Binder.restoreCallingIdentity(token);
7088 }
7089 }
7090
Daniel Brightbb5840b2021-01-12 15:48:18 -08007091 /**
7092 * Sets the ims registration state on all valid {@link Phone}s.
7093 */
7094 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07007095 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007096
7097 final long identity = Binder.clearCallingIdentity();
7098 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08007099 // NOTE: Before S, this method only set the default phone.
7100 for (final Phone phone : PhoneFactory.getPhones()) {
7101 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
7102 phone.setImsRegistrationState(registered);
7103 }
7104 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007105 } finally {
7106 Binder.restoreCallingIdentity(identity);
7107 }
Wink Saville36469e72014-06-11 15:17:00 -07007108 }
7109
7110 /**
Stuart Scott54788802015-03-30 13:18:01 -07007111 * Set the network selection mode to automatic.
7112 *
7113 */
7114 @Override
7115 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007116 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7117 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007118
7119 final long identity = Binder.clearCallingIdentity();
7120 try {
shilufc958392020-01-20 11:36:01 -08007121 if (!isActiveSubscription(subId)) {
7122 return;
7123 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007124 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08007125 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
7126 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007127 } finally {
7128 Binder.restoreCallingIdentity(identity);
7129 }
Stuart Scott54788802015-03-30 13:18:01 -07007130 }
7131
Jack Yud10cdd42020-09-28 20:28:01 -07007132 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07007133 * Ask the radio to connect to the input network and change selection mode to manual.
7134 *
7135 * @param subId the id of the subscription.
7136 * @param operatorInfo the operator information, included the PLMN, long name and short name of
7137 * the operator to attach to.
7138 * @param persistSelection whether the selection will persist until reboot. If true, only allows
7139 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
7140 * normal network selection next time.
7141 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07007142 */
7143 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07007144 public boolean setNetworkSelectionModeManual(
7145 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007146 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7147 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07007148
Jack Yu285100e2022-12-02 22:48:35 -08007149 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07007150 if (!isActiveSubscription(subId)) {
7151 return false;
7152 }
7153
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007154 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07007155 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007156 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07007157 if (DBG) {
7158 log("setNetworkSelectionModeManual: subId: " + subId
7159 + " operator: " + operatorInfo);
7160 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007161 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
7162 } finally {
7163 Binder.restoreCallingIdentity(identity);
7164 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07007165 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007166 /**
shilu84f6e8b2019-12-19 13:58:01 -08007167 * Get the manual network selection
7168 *
7169 * @param subId the id of the subscription.
7170 *
7171 * @return the previously saved user selected PLMN
7172 */
7173 @Override
7174 public String getManualNetworkSelectionPlmn(int subId) {
7175 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007176 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
7177 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08007178
7179 final long identity = Binder.clearCallingIdentity();
7180 try {
7181 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07007182 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08007183 }
7184
7185 final Phone phone = getPhone(subId);
7186 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07007187 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08007188 }
7189 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
7190 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007191 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08007192 } finally {
7193 Binder.restoreCallingIdentity(identity);
7194 }
7195 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07007196
7197 /**
7198 * Scans for available networks.
7199 */
7200 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007201 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
7202 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007203 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7204 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08007205 LocationAccessPolicy.LocationPermissionResult locationResult =
7206 LocationAccessPolicy.checkLocationPermission(mApp,
7207 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7208 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007209 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007210 .setCallingPid(Binder.getCallingPid())
7211 .setCallingUid(Binder.getCallingUid())
7212 .setMethod("getCellNetworkScanResults")
7213 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007214 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7215 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007216 .build());
7217 switch (locationResult) {
7218 case DENIED_HARD:
7219 throw new SecurityException("Not allowed to access scan results -- location");
7220 case DENIED_SOFT:
7221 return null;
7222 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007223
Pengquan Menga1bb6272018-09-06 09:59:22 -07007224 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007225 try {
7226 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07007227 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007228 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007229 } finally {
7230 Binder.restoreCallingIdentity(identity);
7231 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07007232 }
7233
7234 /**
Shuo Qian4a594052020-01-23 11:59:30 -08007235 * Get the call forwarding info, given the call forwarding reason.
7236 */
7237 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007238 public void getCallForwarding(int subId, int callForwardingReason,
7239 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007240 enforceReadPrivilegedPermission("getCallForwarding");
7241 long identity = Binder.clearCallingIdentity();
7242 try {
7243 if (DBG) {
7244 log("getCallForwarding: subId " + subId
7245 + " callForwardingReason" + callForwardingReason);
7246 }
Hall Liu27d24262020-09-18 19:04:59 -07007247
7248 Phone phone = getPhone(subId);
7249 if (phone == null) {
7250 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07007251 callback.onError(
7252 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07007253 } catch (RemoteException e) {
7254 // ignore
7255 }
7256 return;
7257 }
7258
7259 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
7260 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
7261 @Override
7262 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
7263 try {
7264 callback.onCallForwardingInfoAvailable(info);
7265 } catch (RemoteException e) {
7266 // ignore
7267 }
7268 }
7269
7270 @Override
7271 public void onError(int error) {
7272 try {
7273 callback.onError(error);
7274 } catch (RemoteException e) {
7275 // ignore
7276 }
7277 }
7278 });
7279 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08007280 } finally {
7281 Binder.restoreCallingIdentity(identity);
7282 }
7283 }
7284
7285 /**
7286 * Sets the voice call forwarding info including status (enable/disable), call forwarding
7287 * reason, the number to forward, and the timeout before the forwarding is attempted.
7288 */
7289 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007290 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
7291 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007292 enforceModifyPermission();
7293 long identity = Binder.clearCallingIdentity();
7294 try {
7295 if (DBG) {
7296 log("setCallForwarding: subId " + subId
7297 + " callForwardingInfo" + callForwardingInfo);
7298 }
Hall Liu27d24262020-09-18 19:04:59 -07007299
7300 Phone phone = getPhone(subId);
7301 if (phone == null) {
7302 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07007303 callback.accept(
7304 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07007305 } catch (RemoteException e) {
7306 // ignore
7307 }
7308 return;
7309 }
7310
7311 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
7312 FunctionalUtils.ignoreRemoteException(callback::accept));
7313
7314 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08007315 } finally {
7316 Binder.restoreCallingIdentity(identity);
7317 }
7318 }
7319
7320 /**
Hall Liu27d24262020-09-18 19:04:59 -07007321 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007322 */
7323 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007324 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08007325 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08007326 long identity = Binder.clearCallingIdentity();
7327 try {
Hall Liu27d24262020-09-18 19:04:59 -07007328 Phone phone = getPhone(subId);
7329 if (phone == null) {
7330 try {
7331 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7332 } catch (RemoteException e) {
7333 // ignore
7334 }
7335 return;
7336 }
SongFerngWang0e767992021-03-31 22:08:45 +08007337 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7338 PersistableBundle c = configManager.getConfigForSubId(subId);
7339 boolean requireUssd = c.getBoolean(
7340 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007341
Shuo Qian4a594052020-01-23 11:59:30 -08007342 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007343 if (requireUssd) {
7344 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7345 getSubscriptionCarrierId(subId));
7346 String newUssdCommand = "";
7347 try {
7348 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007349 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007350 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7351 } catch (NullPointerException e) {
7352 loge("Failed to generate USSD number" + e);
7353 }
7354 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7355 mMainThreadHandler, callback, carrierXmlParser,
7356 CarrierXmlParser.SsEntry.SSAction.QUERY);
7357 final String ussdCommand = newUssdCommand;
7358 Executors.newSingleThreadExecutor().execute(() -> {
7359 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7360 });
7361 } else {
7362 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7363 callback::accept);
7364 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7365 }
Shuo Qian4a594052020-01-23 11:59:30 -08007366 } finally {
7367 Binder.restoreCallingIdentity(identity);
7368 }
7369 }
7370
7371 /**
Hall Liu27d24262020-09-18 19:04:59 -07007372 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007373 */
7374 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007375 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007376 enforceModifyPermission();
7377 long identity = Binder.clearCallingIdentity();
7378 try {
Hall Liu27d24262020-09-18 19:04:59 -07007379 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7380
7381 Phone phone = getPhone(subId);
7382 if (phone == null) {
7383 try {
7384 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7385 } catch (RemoteException e) {
7386 // ignore
7387 }
7388 return;
7389 }
7390
SongFerngWang0e767992021-03-31 22:08:45 +08007391 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7392 PersistableBundle c = configManager.getConfigForSubId(subId);
7393 boolean requireUssd = c.getBoolean(
7394 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007395
SongFerngWang0e767992021-03-31 22:08:45 +08007396 if (DBG) log("getCallWaitingStatus: subId " + subId);
7397 if (requireUssd) {
7398 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7399 getSubscriptionCarrierId(subId));
7400 CarrierXmlParser.SsEntry.SSAction ssAction =
7401 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7402 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7403 String newUssdCommand = "";
7404 try {
7405 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007406 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007407 .makeCommand(ssAction, null);
7408 } catch (NullPointerException e) {
7409 loge("Failed to generate USSD number" + e);
7410 }
7411 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7412 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7413 final String ussdCommand = newUssdCommand;
7414 Executors.newSingleThreadExecutor().execute(() -> {
7415 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7416 });
7417 } else {
7418 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7419 FunctionalUtils.ignoreRemoteException(callback::accept));
7420
7421 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7422 }
Shuo Qian4a594052020-01-23 11:59:30 -08007423 } finally {
7424 Binder.restoreCallingIdentity(identity);
7425 }
7426 }
7427
7428 /**
yinxub1bed742017-04-17 11:45:04 -07007429 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007430 *
yinxub1bed742017-04-17 11:45:04 -07007431 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007432 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7433 * location related information which will be sent if the caller already possess
7434 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007435 * @param request contains the radio access networks with bands/channels to scan
7436 * @param messenger callback messenger for scan results or errors
7437 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007438 * @return the id of the requested scan which can be used to stop the scan.
7439 */
7440 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007441 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7442 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007443 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007444 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7445 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007446 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007447 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7448 if (!renounceFineLocationAccess) {
7449 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007450 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7451 .setCallingPackage(callingPackage)
7452 .setCallingFeatureId(callingFeatureId)
7453 .setCallingPid(Binder.getCallingPid())
7454 .setCallingUid(Binder.getCallingUid())
7455 .setMethod("requestNetworkScan")
7456 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7457 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7458 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7459 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007460 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007461 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007462 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7463 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007464 if (e != null) {
7465 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7466 throw e;
7467 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007468 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007469 return TelephonyScanManager.INVALID_SCAN_ID;
7470 }
7471 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007472 }
Hall Liu912dfd32019-04-25 14:02:26 -07007473 int callingUid = Binder.getCallingUid();
7474 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007475 final long identity = Binder.clearCallingIdentity();
7476 try {
7477 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007478 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007479 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007480 } finally {
7481 Binder.restoreCallingIdentity(identity);
7482 }
yinxu504e1392017-04-12 16:03:22 -07007483 }
7484
Hall Liub2ac8ef2019-02-28 15:56:23 -08007485 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007486 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007487 boolean hasCarrierPriv;
7488 final long identity = Binder.clearCallingIdentity();
7489 try {
7490 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7491 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7492 } finally {
7493 Binder.restoreCallingIdentity(identity);
7494 }
Hall Liu558027f2019-05-15 19:14:05 -07007495 boolean hasNetworkScanPermission =
7496 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007497 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007498
7499 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7500 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7501 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007502 }
7503
7504 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7505 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007506 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7507 return new SecurityException("Specific channels must not be"
7508 + " scanned without location access.");
7509 }
7510 }
7511 }
7512
Hall Liub2ac8ef2019-02-28 15:56:23 -08007513 return null;
7514 }
7515
yinxu504e1392017-04-12 16:03:22 -07007516 /**
7517 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007518 *
7519 * @param subId id of the subscription
7520 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007521 */
7522 @Override
7523 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007524 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7525 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007526
Hall Liu912dfd32019-04-25 14:02:26 -07007527 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007528 final long identity = Binder.clearCallingIdentity();
7529 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007530 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007531 } finally {
7532 Binder.restoreCallingIdentity(identity);
7533 }
yinxu504e1392017-04-12 16:03:22 -07007534 }
7535
7536 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007537 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007538 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007539 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007540 */
7541 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007542 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007543 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007544 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007545 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007546
7547 final long identity = Binder.clearCallingIdentity();
7548 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007549 if (DBG) log("getAllowedNetworkTypesBitmask");
7550 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7551 int networkTypesBitmask = (result != null ? result[0] : -1);
7552 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7553 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007554 } finally {
7555 Binder.restoreCallingIdentity(identity);
7556 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007557 }
7558
7559 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007560 * Get the allowed network types for certain reason.
7561 *
7562 * @param subId the id of the subscription.
7563 * @param reason the reason the allowed network type change is taking place
7564 * @return the allowed network types.
7565 */
7566 @Override
7567 public long getAllowedNetworkTypesForReason(int subId,
7568 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007569 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007570 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007571 final long identity = Binder.clearCallingIdentity();
7572 try {
7573 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
7574 } finally {
7575 Binder.restoreCallingIdentity(identity);
7576 }
7577 }
7578
7579 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007580 * Enable/Disable E-UTRA-NR Dual Connectivity
7581 * @param subId subscription id of the sim card
7582 * @param nrDualConnectivityState expected NR dual connectivity state
7583 * This can be passed following states
7584 * <ol>
7585 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7586 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7587 * <li>Disable NR dual connectivity and force secondary cell to be released
7588 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7589 * </ol>
7590 * @return operation result.
7591 */
7592 @Override
7593 public int setNrDualConnectivityState(int subId,
7594 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7596 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007597 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007598 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7599 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7600 }
7601
Sooraj Sasindran37444802020-08-11 10:40:43 -07007602 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7603 final long identity = Binder.clearCallingIdentity();
7604 try {
7605 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7606 nrDualConnectivityState, subId,
7607 workSource);
7608 if (DBG) log("enableNRDualConnectivity result: " + result);
7609 return result;
7610 } finally {
7611 Binder.restoreCallingIdentity(identity);
7612 }
7613 }
7614
7615 /**
7616 * Is E-UTRA-NR Dual Connectivity enabled
7617 * @return true if dual connectivity is enabled else false
7618 */
7619 @Override
7620 public boolean isNrDualConnectivityEnabled(int subId) {
7621 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007622 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007623 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007624 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007625 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7626 return false;
7627 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007628 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7629 final long identity = Binder.clearCallingIdentity();
7630 try {
7631 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7632 null, subId, workSource);
7633 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7634 return isEnabled;
7635 } finally {
7636 Binder.restoreCallingIdentity(identity);
7637 }
7638 }
7639
7640 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007641 * Set the allowed network types of the device and
7642 * provide the reason triggering the allowed network change.
7643 *
7644 * @param subId the id of the subscription.
7645 * @param reason the reason the allowed network type change is taking place
7646 * @param allowedNetworkTypes the allowed network types.
7647 * @return true on success; false on any failure.
7648 */
7649 @Override
7650 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007651 @TelephonyManager.AllowedNetworkTypesReason int reason,
7652 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007653 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7654 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007655 // If the caller only has carrier privileges, then they should not be able to override
7656 // any network types which were set for security reasons.
7657 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7658 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007659 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007660 throw new SecurityException(
7661 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007662 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007663 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08007664 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007665 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007666 return false;
7667 }
7668 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7669 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007670 return false;
7671 }
7672
Jack Yu5b494332023-01-23 18:18:04 +00007673 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7674 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007675
Jack Yue37dd262022-12-16 11:53:37 -08007676 Phone phone = getPhone(subId);
7677 if (phone == null) {
7678 return false;
7679 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007680
Jack Yue37dd262022-12-16 11:53:37 -08007681 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007682 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007683 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007684 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007685
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007686 final long identity = Binder.clearCallingIdentity();
7687 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007688 Boolean success = (Boolean) sendRequest(
7689 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7690 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7691
7692 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7693 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007694 } finally {
7695 Binder.restoreCallingIdentity(identity);
7696 }
7697 }
7698
7699 /**
Miaoa84611c2019-03-15 09:21:10 +08007700 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007701 *
Miaoa84611c2019-03-15 09:21:10 +08007702 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007703 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007704 * @hide
7705 */
7706 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007707 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007708 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007709 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007710 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007711 try {
Miaoa84611c2019-03-15 09:21:10 +08007712 if (phone != null) {
7713 return phone.hasMatchedTetherApnSetting();
7714 } else {
7715 return false;
7716 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007717 } finally {
7718 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007719 }
Junda Liu475951f2014-11-07 16:45:03 -08007720 }
7721
7722 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007723 * Get the user enabled state of Mobile Data.
7724 *
7725 * TODO: remove and use isUserDataEnabled.
7726 * This can't be removed now because some vendor codes
7727 * calls through ITelephony directly while they should
7728 * use TelephonyManager.
7729 *
7730 * @return true on enabled
7731 */
7732 @Override
7733 public boolean getDataEnabled(int subId) {
7734 return isUserDataEnabled(subId);
7735 }
7736
7737 /**
7738 * Get whether mobile data is enabled per user setting.
7739 *
7740 * There are other factors deciding whether mobile data is actually enabled, but they are
7741 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007742 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007743 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7744 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007745 *
7746 * @return {@code true} if data is enabled else {@code false}
7747 */
7748 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007749 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007750 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007751 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007752 try {
7753 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7754 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007755 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007756 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7757 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007758 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007759 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007760 mApp, subId, functionName);
7761
Robert Greenwalt646120a2014-05-23 11:54:03 -07007762 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007763
7764 final long identity = Binder.clearCallingIdentity();
7765 try {
Jack Yu285100e2022-12-02 22:48:35 -08007766 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007767 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7768 Phone phone = PhoneFactory.getPhone(phoneId);
7769 if (phone != null) {
7770 boolean retVal = phone.isUserDataEnabled();
7771 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7772 return retVal;
7773 } else {
7774 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7775 return false;
7776 }
7777 } finally {
7778 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007779 }
7780 }
7781
7782 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007783 * Checks if the device is capable of mobile data by considering whether whether the
7784 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7785 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007786 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007787 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007788 */
7789 @Override
7790 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007791 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007792 try {
7793 try {
7794 mApp.enforceCallingOrSelfPermission(
7795 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007796 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007797 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007798 try {
7799 mApp.enforceCallingOrSelfPermission(
7800 android.Manifest.permission.READ_PHONE_STATE,
7801 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007802 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007803 mApp.enforceCallingOrSelfPermission(
7804 permission.READ_BASIC_PHONE_STATE, functionName);
7805 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007806 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007807 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007808 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007809 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007810
7811 final long identity = Binder.clearCallingIdentity();
7812 try {
Jack Yu285100e2022-12-02 22:48:35 -08007813 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007814 Phone phone = PhoneFactory.getPhone(phoneId);
7815 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007816 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007817 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007818 return retVal;
7819 } else {
7820 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7821 return false;
7822 }
7823 } finally {
7824 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007825 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007826 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007827
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007828 /**
7829 * Check if data is enabled for a specific reason
7830 * @param subId Subscription index
7831 * @param reason the reason the data enable change is taking place
7832 * @return {@code true} if the overall data is enabled; {@code false} if not.
7833 */
7834 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007835 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007836 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007837 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007838 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007839 try {
7840 mApp.enforceCallingOrSelfPermission(
7841 android.Manifest.permission.ACCESS_NETWORK_STATE,
7842 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007843 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007844 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7845 functionName);
7846 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007847 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007848 try {
7849 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007850 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007851 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007853 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007854 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007855 }
7856
7857
7858 final long identity = Binder.clearCallingIdentity();
7859 try {
Jack Yu285100e2022-12-02 22:48:35 -08007860 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007861 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007862 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007863 + " reason=" + reason);
7864 }
7865 Phone phone = PhoneFactory.getPhone(phoneId);
7866 if (phone != null) {
7867 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007868 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007869 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007870 return retVal;
7871 } else {
7872 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007873 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007874 + subId + " retVal=false");
7875 }
7876 return false;
7877 }
7878 } finally {
7879 Binder.restoreCallingIdentity(identity);
7880 }
7881 }
7882
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007883 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007884 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007885 // No permission needed; this only lets the caller inspect their own status.
7886 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007887 }
Junda Liu29340342014-07-10 15:23:27 -07007888
7889 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007890 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007891 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007892 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7893 }
7894
7895 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7896 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007897 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007898 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007899 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7900 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007901 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7902 if (cpt == null) {
7903 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007904 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7905 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007906 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007907 }
7908
7909 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007910 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007911 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007912 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007913 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007914 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007915 Phone phone = getPhone(subId);
7916 if (phone == null) {
7917 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7918 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7919 }
7920 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7921 if (cpt == null) {
7922 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007923 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7924 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007925 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007926 }
7927
7928 @Override
7929 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007930 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007931 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7932 }
7933
7934 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007935 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007936 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007937 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007938 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007939 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7940 Phone phone = PhoneFactory.getPhone(phoneId);
7941 if (phone == null) {
7942 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007943 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007944 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7945 if (cpt == null) {
7946 continue;
7947 }
7948 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007949 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7950 break;
7951 }
7952 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007953 return result;
Junda Liu29340342014-07-10 15:23:27 -07007954 }
Derek Tan89e89d42014-07-08 17:00:10 -07007955
7956 @Override
Junda Liue64de782015-04-16 17:19:16 -07007957 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007958 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007959 Phone phone = PhoneFactory.getPhone(phoneId);
7960 if (phone == null) {
7961 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007962 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007963 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7964 if (cpt == null) {
7965 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007966 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007967 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007968 }
7969
Amith Yamasani6e118872016-02-19 12:53:51 -08007970 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007971 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007972 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007973 Phone phone = PhoneFactory.getPhone(phoneId);
7974 if (phone == null) {
7975 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007976 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007977 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7978 if (cpt == null) {
7979 return Collections.emptyList();
7980 }
7981 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007982 }
7983
chen xuf7e9fe82019-05-09 19:31:02 -07007984 @Override
7985 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007986 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007987 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007988 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007989 try {
7990 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7991 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7992 }
7993 } finally {
7994 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007995 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007996 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007997 }
7998
Rambo Wang6812ffb2022-03-15 16:54:17 -07007999 @Override
8000 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
8001 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
8002
8003 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
8004 if (phone == null) {
8005 return null;
8006 }
8007 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8008 if (cpt == null) {
8009 return null;
8010 }
8011 return cpt.getCarrierServicePackageName();
8012 }
8013
Wink Savilleb564aae2014-10-23 10:18:09 -07008014 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07008015 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008016 UiccPort port = phone == null ? null : phone.getUiccPort();
8017 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07008018 return null;
8019 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008020 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07008021 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07008022 return null;
8023 }
8024 return iccId;
8025 }
8026
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07008027 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08008028 public void setCallComposerStatus(int subId, int status) {
8029 enforceModifyPermission();
8030
8031 final long identity = Binder.clearCallingIdentity();
8032 try {
8033 Phone phone = getPhone(subId);
8034 if (phone != null) {
8035 Phone defaultPhone = phone.getImsPhone();
8036 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8037 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8038 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08008039 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
8040 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08008041 }
8042 }
Shuo Qian284ae752020-12-22 19:10:14 -08008043 } catch (ImsException e) {
8044 throw new ServiceSpecificException(e.getCode());
8045 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08008046 Binder.restoreCallingIdentity(identity);
8047 }
8048 }
8049
8050 @Override
8051 public int getCallComposerStatus(int subId) {
8052 enforceReadPrivilegedPermission("getCallComposerStatus");
8053
8054 final long identity = Binder.clearCallingIdentity();
8055 try {
8056 Phone phone = getPhone(subId);
8057 if (phone != null) {
8058 Phone defaultPhone = phone.getImsPhone();
8059 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8060 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8061 return imsPhone.getCallComposerStatus();
8062 }
8063 }
8064 } finally {
8065 Binder.restoreCallingIdentity(identity);
8066 }
8067 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
8068 }
8069
8070 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08008071 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
8072 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008073 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008074 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07008075
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008076 final long identity = Binder.clearCallingIdentity();
8077 try {
8078 final String iccId = getIccId(subId);
8079 final Phone phone = getPhone(subId);
8080 if (phone == null) {
8081 return false;
8082 }
8083 final String subscriberId = phone.getSubscriberId();
8084
8085 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008086 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008087 + subscriberId + " to " + number);
8088 }
8089
8090 if (TextUtils.isEmpty(iccId)) {
8091 return false;
8092 }
8093
8094 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
8095
8096 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
8097 if (alphaTag == null) {
8098 editor.remove(alphaTagPrefKey);
8099 } else {
8100 editor.putString(alphaTagPrefKey, alphaTag);
8101 }
8102
8103 // Record both the line number and IMSI for this ICCID, since we need to
8104 // track all merged IMSIs based on line number
8105 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
8106 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
8107 if (number == null) {
8108 editor.remove(numberPrefKey);
8109 editor.remove(subscriberPrefKey);
8110 } else {
8111 editor.putString(numberPrefKey, number);
8112 editor.putString(subscriberPrefKey, subscriberId);
8113 }
8114
8115 editor.commit();
8116 return true;
8117 } finally {
8118 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07008119 }
Derek Tan7226c842014-07-02 17:42:23 -07008120 }
8121
8122 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008123 public String getLine1NumberForDisplay(int subId, String callingPackage,
8124 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07008125 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08008126 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008127 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08008128 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07008129 return null;
8130 }
Derek Tan97ebb422014-09-05 16:55:38 -07008131
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008132 final long identity = Binder.clearCallingIdentity();
8133 try {
8134 String iccId = getIccId(subId);
8135 if (iccId != null) {
8136 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
8137 if (DBG_MERGE) {
8138 log("getLine1NumberForDisplay returning "
8139 + mTelephonySharedPreferences.getString(numberPrefKey, null));
8140 }
8141 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08008142 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008143 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
8144 return null;
8145 } finally {
8146 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07008147 }
Derek Tan7226c842014-07-02 17:42:23 -07008148 }
8149
8150 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008151 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
8152 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008153 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008154 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07008155 return null;
8156 }
Derek Tan97ebb422014-09-05 16:55:38 -07008157
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008158 final long identity = Binder.clearCallingIdentity();
8159 try {
8160 String iccId = getIccId(subId);
8161 if (iccId != null) {
8162 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
8163 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
8164 }
8165 return null;
8166 } finally {
8167 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07008168 }
Derek Tan7226c842014-07-02 17:42:23 -07008169 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008170
8171 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008172 public String[] getMergedSubscriberIds(int subId, String callingPackage,
8173 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008174 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
8175 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08008176 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08008177 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008178 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008179 return null;
8180 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008181
Jordan Liub49b04b2019-05-06 14:45:15 -07008182 // Clear calling identity, when calling TelephonyManager, because callerUid must be
8183 // the process, where TelephonyManager was instantiated.
8184 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008185 final long identity = Binder.clearCallingIdentity();
8186 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008187 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008188 final TelephonyManager tele = TelephonyManager.from(context);
8189 final SubscriptionManager sub = SubscriptionManager.from(context);
8190
8191 // Figure out what subscribers are currently active
8192 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008193
Jordan Liub49b04b2019-05-06 14:45:15 -07008194 // Only consider subs which match the current subId
8195 // This logic can be simplified. See b/131189269 for progress.
8196 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008197 activeSubscriberIds.add(tele.getSubscriberId(subId));
8198 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008199
8200 // First pass, find a number override for an active subscriber
8201 String mergeNumber = null;
8202 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
8203 for (String key : prefs.keySet()) {
8204 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
8205 final String subscriberId = (String) prefs.get(key);
8206 if (activeSubscriberIds.contains(subscriberId)) {
8207 final String iccId = key.substring(
8208 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
8209 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
8210 mergeNumber = (String) prefs.get(numberKey);
8211 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008212 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008213 + " for active subscriber " + subscriberId);
8214 }
8215 if (!TextUtils.isEmpty(mergeNumber)) {
8216 break;
8217 }
8218 }
8219 }
8220 }
8221
8222 // Shortcut when no active merged subscribers
8223 if (TextUtils.isEmpty(mergeNumber)) {
8224 return null;
8225 }
8226
8227 // Second pass, find all subscribers under that line override
8228 final ArraySet<String> result = new ArraySet<>();
8229 for (String key : prefs.keySet()) {
8230 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
8231 final String number = (String) prefs.get(key);
8232 if (mergeNumber.equals(number)) {
8233 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
8234 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
8235 final String subscriberId = (String) prefs.get(subscriberKey);
8236 if (!TextUtils.isEmpty(subscriberId)) {
8237 result.add(subscriberId);
8238 }
8239 }
8240 }
8241 }
8242
8243 final String[] resultArray = result.toArray(new String[result.size()]);
8244 Arrays.sort(resultArray);
8245 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008246 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008247 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
8248 }
8249 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008250 } finally {
8251 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08008252 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008253 }
8254
8255 @Override
zoey chen38003472019-12-13 17:16:31 +08008256 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
8257 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07008258
8259 final long identity = Binder.clearCallingIdentity();
8260 try {
8261 final TelephonyManager telephonyManager = mApp.getSystemService(
8262 TelephonyManager.class);
8263 String subscriberId = telephonyManager.getSubscriberId(subId);
8264 if (subscriberId == null) {
8265 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008266 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008267 + subId);
8268 }
8269 return null;
8270 }
8271
Jack Yu285100e2022-12-02 22:48:35 -08008272 ParcelUuid groupUuid;
8273 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008274 final SubscriptionInfo info = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08008275 .getSubscriptionInfo(subId);
8276 groupUuid = info.getGroupUuid();
8277 } else {
8278 final SubscriptionInfo info = mSubscriptionController
8279 .getSubscriptionInfo(subId);
8280 groupUuid = info.getGroupUuid();
8281 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07008282 // If it doesn't belong to any group, return just subscriberId of itself.
8283 if (groupUuid == null) {
8284 return new String[]{subscriberId};
8285 }
8286
8287 // Get all subscriberIds from the group.
8288 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08008289 List<SubscriptionInfo> groupInfos;
8290 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008291 groupInfos = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08008292 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8293 mApp.getAttributionTag());
8294 } else {
8295 groupInfos = mSubscriptionController
8296 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8297 mApp.getAttributionTag());
8298 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07008299 for (SubscriptionInfo subInfo : groupInfos) {
8300 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8301 if (subscriberId != null) {
8302 mergedSubscriberIds.add(subscriberId);
8303 }
8304 }
8305
8306 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8307 } finally {
8308 Binder.restoreCallingIdentity(identity);
8309
8310 }
8311 }
8312
8313 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008314 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008315 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008316 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008317
8318 final long identity = Binder.clearCallingIdentity();
8319 try {
8320 final Phone phone = getPhone(subId);
8321 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8322 } finally {
8323 Binder.restoreCallingIdentity(identity);
8324 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008325 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008326
8327 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008328 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008329 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8330 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008331 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8332 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008333
8334 final long identity = Binder.clearCallingIdentity();
8335 try {
8336 final Phone phone = getPhone(subId);
8337 if (phone == null) {
8338 return false;
8339 }
8340 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8341 cdmaNonRoamingList);
8342 } finally {
8343 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008344 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008345 }
8346
8347 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00008348 @Deprecated
8349 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
8350 enforceModifyPermission();
8351
8352 int returnValue = 0;
8353 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07008354 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00008355 if(result.exception == null) {
8356 if (result.result != null) {
8357 byte[] responseData = (byte[])(result.result);
8358 if(responseData.length > oemResp.length) {
8359 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
8360 responseData.length + "bytes. Buffer Size is " +
8361 oemResp.length + "bytes.");
8362 }
8363 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
8364 returnValue = responseData.length;
8365 }
8366 } else {
8367 CommandException ex = (CommandException) result.exception;
8368 returnValue = ex.getCommandError().ordinal();
8369 if(returnValue > 0) returnValue *= -1;
8370 }
8371 } catch (RuntimeException e) {
8372 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
8373 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
8374 if(returnValue > 0) returnValue *= -1;
8375 }
8376
8377 return returnValue;
8378 }
8379
8380 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008381 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008382 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07008383 try {
8384 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008385 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008386 mApp, phone.getSubId(), "getRadioAccessFamily");
8387 } catch (SecurityException e) {
8388 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8389 throw e;
8390 }
chen xub97461a2018-10-26 14:17:57 -07008391 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008392 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07008393 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08008394 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008395 final long identity = Binder.clearCallingIdentity();
8396 try {
chen xub97461a2018-10-26 14:17:57 -07008397 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008398 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07008399 mApp, phone.getSubId(), "getRadioAccessFamily");
8400 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008401 } finally {
8402 Binder.restoreCallingIdentity(identity);
8403 }
chen xub97461a2018-10-26 14:17:57 -07008404 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008405 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008406
8407 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008408 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008409 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008410 try {
8411 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8412 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008413 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008414 }
8415 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008416 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008417 }
8418 RoleManager rm = mApp.getSystemService(RoleManager.class);
8419 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8420 if (!dialerRoleHolders.contains(callingPackage)) {
8421 throw new SecurityException("App must be the dialer role holder to"
8422 + " upload a call composer pic");
8423 }
8424
8425 Executors.newSingleThreadExecutor().execute(() -> {
8426 ByteArrayOutputStream output = new ByteArrayOutputStream(
8427 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8428 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8429 boolean readUntilEnd = false;
8430 int totalBytesRead = 0;
8431 byte[] buffer = new byte[16 * 1024];
8432 while (true) {
8433 int numRead;
8434 try {
8435 numRead = input.read(buffer);
8436 } catch (IOException e) {
8437 try {
8438 fd.checkError();
8439 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8440 null);
8441 } catch (IOException e1) {
8442 // This means that the other side closed explicitly with an error. If this
8443 // happens, log and ignore.
8444 loge("Remote end of call composer picture pipe closed: " + e1);
8445 }
8446 break;
8447 }
8448 if (numRead == -1) {
8449 readUntilEnd = true;
8450 break;
8451 }
8452 totalBytesRead += numRead;
8453 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8454 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8455 try {
8456 input.close();
8457 } catch (IOException e) {
8458 // ignore
8459 }
8460 break;
8461 }
8462 output.write(buffer, 0, numRead);
8463 }
8464 // Generally, the remote end will close the file descriptors. The only case where we
8465 // close is above, where the picture size is too big.
8466
8467 try {
8468 fd.checkError();
8469 } catch (IOException e) {
8470 loge("Remote end for call composer closed with an error: " + e);
8471 return;
8472 }
8473
Hall Liuaa4211e2021-01-20 15:43:39 -08008474 if (!readUntilEnd) {
8475 loge("Did not finish reading entire image; aborting");
8476 return;
8477 }
Hall Liu82694d52020-12-11 18:22:04 -08008478
Hall Liuaa4211e2021-01-20 15:43:39 -08008479 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8480 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8481 new CallComposerPictureTransfer.Factory() {},
8482 imageData,
8483 (result) -> {
8484 if (result.first != null) {
8485 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8486 Bundle outputResult = new Bundle();
8487 outputResult.putParcelable(
8488 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8489 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8490 outputResult);
8491 } else {
8492 callback.send(result.second, null);
8493 }
8494 }
8495 );
Hall Liu82694d52020-12-11 18:22:04 -08008496 });
8497 }
8498
8499 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008500 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008501 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008502 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008503
8504 final long identity = Binder.clearCallingIdentity();
8505 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008506 ImsManager.getInstance(defaultPhone.getContext(),
8507 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008508 } finally {
8509 Binder.restoreCallingIdentity(identity);
8510 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008511 }
8512
8513 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008514 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008515 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008516 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8517 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008518 return false;
8519 }
Svet Ganovb320e182015-04-16 12:30:10 -07008520
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008521 final long identity = Binder.clearCallingIdentity();
8522 try {
8523 // Check the user preference and the system-level IMS setting. Even if the user has
8524 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8525 // In the long run, we may instead need to check if there exists a connection service
8526 // which can support video calling.
8527 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008528 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008529 return imsManager.isVtEnabledByPlatform()
8530 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8531 && imsManager.isVtEnabledByUser();
8532 } finally {
8533 Binder.restoreCallingIdentity(identity);
8534 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008535 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008536
Andrew Leea1239f22015-03-02 17:44:07 -08008537 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008538 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8539 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008540 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008541 mApp, subId, callingPackage, callingFeatureId,
8542 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008543 return false;
8544 }
8545
8546 final long identity = Binder.clearCallingIdentity();
8547 try {
8548 CarrierConfigManager configManager =
8549 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008550 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008551 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8552 } finally {
8553 Binder.restoreCallingIdentity(identity);
8554 }
Andrew Leea1239f22015-03-02 17:44:07 -08008555 }
8556
8557 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008558 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008559 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008560 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008561 return false;
8562 }
8563
8564 final long identity = Binder.clearCallingIdentity();
8565 try {
8566 CarrierConfigManager configManager =
8567 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008568 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008569 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8570 } finally {
8571 Binder.restoreCallingIdentity(identity);
8572 }
Andrew Leea1239f22015-03-02 17:44:07 -08008573 }
8574
Andrew Lee9431b832015-03-09 18:46:45 -07008575 @Override
8576 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008577 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008578 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008579 }
8580
8581 @Override
8582 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008583 final long identity = Binder.clearCallingIdentity();
8584 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008585 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008586 } finally {
8587 Binder.restoreCallingIdentity(identity);
8588 }
Andrew Lee9431b832015-03-09 18:46:45 -07008589 }
8590
Hall Liuf6668912018-10-31 17:05:23 -07008591 /**
8592 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8593 * support for the feature and device firmware support.
8594 *
8595 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8596 */
8597 @Override
8598 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008599 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008600 final Phone phone = getPhone(subscriptionId);
8601 if (phone == null) {
8602 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8603 return false;
8604 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008605 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008606 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008607 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
8608 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008609 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008610 return isCarrierSupported && isDeviceSupported;
8611 } finally {
8612 Binder.restoreCallingIdentity(identity);
8613 }
Hall Liu98187582018-01-22 19:15:32 -08008614 }
8615
Hall Liuf6668912018-10-31 17:05:23 -07008616 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008617 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8618 * RTT setting, will return true if the device and carrier both support RTT.
8619 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008620 */
8621 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008622 final long identity = Binder.clearCallingIdentity();
8623 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00008624 boolean isRttSupported = isRttSupported(subscriptionId);
8625 boolean isUserRttSettingOn = Settings.Secure.getInt(
8626 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8627 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8628 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8629 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008630 } finally {
8631 Binder.restoreCallingIdentity(identity);
8632 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008633 }
8634
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008635 @Deprecated
8636 @Override
8637 public String getDeviceId(String callingPackage) {
8638 return getDeviceIdWithFeature(callingPackage, null);
8639 }
8640
Sanket Padawe7310cc72015-01-14 09:53:20 -08008641 /**
8642 * Returns the unique device ID of phone, for example, the IMEI for
8643 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8644 *
8645 * <p>Requires Permission:
8646 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8647 */
8648 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008649 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008650 try {
8651 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8652 } catch (SecurityException se) {
8653 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8654 throw new SecurityException("Package " + callingPackage + " does not belong to "
8655 + Binder.getCallingUid());
8656 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008657 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008658 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008659 return null;
8660 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008661 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008662 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008663 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008664 return null;
8665 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008666
8667 final long identity = Binder.clearCallingIdentity();
8668 try {
8669 return phone.getDeviceId();
8670 } finally {
8671 Binder.restoreCallingIdentity(identity);
8672 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008673 }
8674
Ping Sunc67b7c22016-03-02 19:16:45 +08008675 /**
8676 * {@hide}
8677 * Returns the IMS Registration Status on a particular subid
8678 *
8679 * @param subId
8680 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008681 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008682 Phone phone = getPhone(subId);
8683 if (phone != null) {
8684 return phone.isImsRegistered();
8685 } else {
8686 return false;
8687 }
8688 }
8689
Santos Cordon7a1885b2015-02-03 11:15:19 -08008690 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008691 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008692 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008693 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008694 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008695 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8696 }
8697 final long identity = Binder.clearCallingIdentity();
8698 try {
8699 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8700 } finally {
8701 Binder.restoreCallingIdentity(identity);
8702 }
8703 }
8704
8705 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008706 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008707 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008708 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008709 mApp,
8710 subscriptionId,
8711 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8712 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07008713 final long identity = Binder.clearCallingIdentity();
8714 try {
8715 Phone phone = getPhone(subscriptionId);
8716 if (phone == null) {
8717 return null;
8718 }
8719 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8720 } finally {
8721 Binder.restoreCallingIdentity(identity);
8722 }
8723 }
8724
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008725 /**
8726 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008727 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008728 public boolean isWifiCallingAvailable(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.isWifiCallingEnabled();
8734 } else {
8735 return false;
8736 }
8737 } finally {
8738 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008739 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008740 }
8741
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008742 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008743 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008744 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008745 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008746 final long identity = Binder.clearCallingIdentity();
8747 try {
8748 Phone phone = getPhone(subId);
8749 if (phone != null) {
8750 return phone.isVideoEnabled();
8751 } else {
8752 return false;
8753 }
8754 } finally {
8755 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008756 }
8757 }
8758
8759 /**
8760 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8761 * defined in {@link ImsRegistrationImplBase}.
8762 */
8763 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008764 final long identity = Binder.clearCallingIdentity();
8765 try {
8766 Phone phone = getPhone(subId);
8767 if (phone != null) {
8768 return phone.getImsRegistrationTech();
8769 } else {
8770 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8771 }
8772 } finally {
8773 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008774 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008775 }
8776
Stuart Scott8eef64f2015-04-08 15:13:54 -07008777 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008778 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008779 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07008780 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8781 return;
8782 }
Kai Shif70f46f2021-03-03 13:59:46 -08008783 Phone defaultPhone = getDefaultPhone();
8784 if (defaultPhone != null) {
8785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8786 mApp, getDefaultPhone().getSubId(), "factoryReset");
8787 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008788 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008789
Svet Ganovcc087f82015-05-12 20:35:54 -07008790 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008791 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8792 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008793 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008794 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008795 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008796 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008797 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008798 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08008799 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008800 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008801 // There has been issues when Sms raw table somehow stores orphan
8802 // fragments. They lead to garbled message when new fragments come
8803 // in and combined with those stale ones. In case this happens again,
8804 // user can reset all network settings which will clean up this table.
8805 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008806 // Clean up IMS settings as well here.
8807 int slotId = getSlotIndex(subId);
8808 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8809 ImsManager.getInstance(mApp, slotId).factoryReset();
8810 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008811
Kai Shif70f46f2021-03-03 13:59:46 -08008812 if (defaultPhone == null) {
8813 return;
8814 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008815 // Erase modem config if erase modem on network setting is enabled.
8816 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8817 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8818 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008819 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008820 }
Kai Shif70f46f2021-03-03 13:59:46 -08008821
8822 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008823 } finally {
8824 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008825 }
8826 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008827
SongFerngWangfd89b102021-05-27 22:44:54 +08008828 @VisibleForTesting
8829 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8830 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8831 return;
8832 }
8833 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8834 RILConstants.PREFERRED_NETWORK_MODE);
8835 SubscriptionManager.setSubscriptionProperty(subId,
8836 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8837 "user=" + defaultNetworkType);
8838 phone.loadAllowedNetworksFromSubscriptionDatabase();
8839 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8840 defaultNetworkType, null);
8841 }
8842
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008843 private void cleanUpSmsRawTable(Context context) {
8844 ContentResolver resolver = context.getContentResolver();
8845 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8846 resolver.delete(uri, null, null);
8847 }
8848
Narayan Kamath1c496c22015-04-16 14:40:19 +01008849 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008850 public String getSimLocaleForSubscriber(int subId) {
8851 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
8852 final Phone phone = getPhone(subId);
8853 if (phone == null) {
8854 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008855 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008856 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008857 final long identity = Binder.clearCallingIdentity();
8858 try {
Jack Yu285100e2022-12-02 22:48:35 -08008859 SubscriptionInfo info;
8860 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008861 info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
Jack Yu285100e2022-12-02 22:48:35 -08008862 phone.getContext().getOpPackageName(),
8863 phone.getContext().getAttributionTag());
8864 if (info == null) {
8865 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8866 return null;
8867 }
8868 } else {
8869 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
8870 phone.getContext().getOpPackageName(),
8871 phone.getContext().getAttributionTag());
8872 if (info == null) {
8873 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8874 return null;
8875 }
chen xu6291c472019-02-04 12:55:53 -08008876 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008877 // Try and fetch the locale from the carrier properties or from the SIM language
8878 // preferences (EF-PL and EF-LI)...
8879 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008880 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008881 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8882 if (localeFromDefaultSim != null) {
8883 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8884 if (DBG) log("Using locale from subId: " + subId + " locale: "
8885 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008886 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008887 } else {
8888 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008889 }
8890 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008891
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008892 // The SIM language preferences only store a language (e.g. fr = French), not an
8893 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8894 // the SIM and carrier preferences does not include a country we add the country
8895 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008896 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008897 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008898 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008899 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008900 }
8901
8902 if (DBG) log("No locale found - returning null");
8903 return null;
8904 } finally {
8905 Binder.restoreCallingIdentity(identity);
8906 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008907 }
8908
tom hsu0b59d292022-09-29 23:49:21 +08008909 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008910 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008911 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008912 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008913 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008914 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8915 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008916 Locale.forLanguageTag(localeTag).getCountry())) {
8917 return localeTag;
8918 }
8919 }
8920 return inputLocale.toLanguageTag();
8921 }
8922
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008923 /**
8924 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8925 */
8926 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08008927 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008928 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Jack Yu285100e2022-12-02 22:48:35 -08008929 mApp.getOpPackageName(), mApp.getAttributionTag());
8930 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008931 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08008932 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008933 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008934
Gary Jian3aa9a762022-01-24 16:41:19 +08008935 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8936 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008937
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008938 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008939 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8940 * representing the state of the modem.
8941 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008942 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8943 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008944 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008945 */
8946 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008947 public void requestModemActivityInfo(ResultReceiver result) {
8948 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008949 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008950
8951 final long identity = Binder.clearCallingIdentity();
8952 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008953 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008954 } finally {
8955 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008956 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008957 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008958
Gary Jian76280a42022-12-07 16:18:33 +08008959 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008960 // less than total activity duration.
8961 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8962 if (info == null) {
8963 return false;
8964 }
8965 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008966 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008967 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8968
Hall Liu49656c02020-10-09 19:00:11 -07008969 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8970
Siddharth Rayb8114062018-06-17 15:02:38 -07008971 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008972 && (info.getSleepTimeMillis() <= activityDurationMs)
8973 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008974 }
8975
Gary Jian3aa9a762022-01-24 16:41:19 +08008976 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8977 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8978 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8979 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8980
8981 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8982 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8983 }
8984
8985 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8986 mLastModemActivityInfo.setReceiveTimeMillis(
8987 rat,
8988 freq,
8989 info.getReceiveTimeMillis(rat, freq)
8990 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8991 }
8992
8993 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8994 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8995 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8996 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8997
8998 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8999 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
9000 }
9001 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
9002 mLastModemActivityInfo.setReceiveTimeMillis(
9003 rat,
9004 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
9005 }
9006
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009007 /**
9008 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
9009 * @param info recent ModemActivityInfo
9010 */
Gary Jian3aa9a762022-01-24 16:41:19 +08009011 private void mergeModemActivityInfo(ModemActivityInfo info) {
9012 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08009013 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08009014 boolean matched;
9015 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
9016 matched = false;
9017 int rat = info.getSpecificInfoRat(i);
9018 int freq = info.getSpecificInfoFrequencyRange(i);
9019 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
9020 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
9021 //if it already exists
9022 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
9023 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
9024 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
9025 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
9026 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
9027 updateLastModemActivityInfo(info, rat, freq);
9028 matched = true;
9029 }
9030 } else {
9031 updateLastModemActivityInfo(info, rat);
9032 matched = true;
9033 }
9034 }
9035 }
9036
9037 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08009038 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08009039 new ActivityStatsTechSpecificInfo(
9040 rat,
9041 freq,
9042 info.getTransmitTimeMillis(rat, freq),
9043 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08009044 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08009045 }
9046 }
9047 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
9048 mLastModemActivitySpecificInfo =
9049 new ActivityStatsTechSpecificInfo[merged.size()];
9050 merged.toArray(mLastModemActivitySpecificInfo);
9051
9052 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
9053 mLastModemActivityInfo.setSleepTimeMillis(
9054 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009055 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08009056 mLastModemActivityInfo.setIdleTimeMillis(
9057 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009058 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08009059
9060 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009061 new ModemActivityInfo(
9062 mLastModemActivityInfo.getTimestampMillis(),
9063 mLastModemActivityInfo.getSleepTimeMillis(),
9064 mLastModemActivityInfo.getIdleTimeMillis(),
9065 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08009066 }
9067
9068 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
9069 ActivityStatsTechSpecificInfo[] info) {
9070 int infoSize = info.length;
9071 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
9072 for (int i = 0; i < infoSize; i++) {
9073 ret[i] = new ActivityStatsTechSpecificInfo(
9074 info[i].getRat(), info[i].getFrequencyRange(),
9075 info[i].getTransmitTimeMillis(),
9076 (int) info[i].getReceiveTimeMillis());
9077 }
9078 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08009079 }
9080
Jack Yu85bd38a2015-11-09 11:34:32 -08009081 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08009082 * Returns the service state information on specified subscription.
9083 */
9084 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08009085 public ServiceState getServiceStateForSubscriber(int subId,
9086 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
9087 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009088 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009089 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08009090 return null;
9091 }
9092
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08009093 boolean hasFinePermission = false;
9094 boolean hasCoarsePermission = false;
9095 if (!renounceFineLocationAccess) {
9096 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
9097 LocationAccessPolicy.checkLocationPermission(mApp,
9098 new LocationAccessPolicy.LocationPermissionQuery.Builder()
9099 .setCallingPackage(callingPackage)
9100 .setCallingFeatureId(callingFeatureId)
9101 .setCallingPid(Binder.getCallingPid())
9102 .setCallingUid(Binder.getCallingUid())
9103 .setMethod("getServiceStateForSubscriber")
9104 .setLogAsInfo(true)
9105 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
9106 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
9107 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
9108 .build());
9109 hasFinePermission =
9110 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
9111 }
Hall Liuf19c44f2018-11-27 14:38:17 -08009112
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08009113 if (!renounceCoarseLocationAccess) {
9114 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
9115 LocationAccessPolicy.checkLocationPermission(mApp,
9116 new LocationAccessPolicy.LocationPermissionQuery.Builder()
9117 .setCallingPackage(callingPackage)
9118 .setCallingFeatureId(callingFeatureId)
9119 .setCallingPid(Binder.getCallingPid())
9120 .setCallingUid(Binder.getCallingUid())
9121 .setMethod("getServiceStateForSubscriber")
9122 .setLogAsInfo(true)
9123 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
9124 .setMinSdkVersionForFine(Integer.MAX_VALUE)
9125 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
9126 .build());
9127 hasCoarsePermission =
9128 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
9129 }
Hall Liuf19c44f2018-11-27 14:38:17 -08009130
Jack Yu479f40e2020-10-27 21:29:25 -07009131 final Phone phone = getPhone(subId);
9132 if (phone == null) {
9133 return null;
9134 }
9135
Jordan Liu0f2bc442020-11-18 16:47:37 -08009136 final long identity = Binder.clearCallingIdentity();
9137
Jack Yu479f40e2020-10-27 21:29:25 -07009138 boolean isCallingPackageDataService = phone.getDataServicePackages()
9139 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009140 try {
Jordan Liuc437b192020-08-17 10:59:12 -07009141 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08009142 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08009143 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08009144 .getSubscriptionInfoInternal(subId);
9145 if (subInfo == null || !subInfo.isActive()) {
9146 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
9147 + "subId=" + subId);
9148 return null;
9149 }
9150 } else {
9151 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
9152 callingFeatureId)) {
9153 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
9154 + "subId=" + subId);
9155 return null;
9156 }
Jordan Liuc437b192020-08-17 10:59:12 -07009157 }
9158
Hall Liuf19c44f2018-11-27 14:38:17 -08009159 ServiceState ss = phone.getServiceState();
9160
9161 // Scrub out the location info in ServiceState depending on what level of access
9162 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07009163 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08009164 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
9165 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009166 } finally {
9167 Binder.restoreCallingIdentity(identity);
9168 }
Jack Yu85bd38a2015-11-09 11:34:32 -08009169 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009170
9171 /**
9172 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
9173 *
9174 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
9175 * voicemail ringtone.
9176 * @return The URI for the ringtone to play when receiving a voicemail from a specific
9177 * PhoneAccount.
9178 */
9179 @Override
9180 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009181 final long identity = Binder.clearCallingIdentity();
9182 try {
9183 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9184 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009185 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009186 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009187
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009188 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
9189 } finally {
9190 Binder.restoreCallingIdentity(identity);
9191 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009192 }
9193
9194 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009195 * Sets the per-account voicemail ringtone.
9196 *
9197 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9198 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9199 *
9200 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9201 * voicemail ringtone.
9202 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
9203 * PhoneAccount.
9204 */
9205 @Override
9206 public void setVoicemailRingtoneUri(String callingPackage,
9207 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009208 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009209 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009210 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9211 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9213 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9214 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009215 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009216
9217 final long identity = Binder.clearCallingIdentity();
9218 try {
9219 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9220 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009221 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009222 }
9223 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
9224 } finally {
9225 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009226 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009227 }
9228
9229 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08009230 * Returns whether vibration is set for voicemail notification in Phone settings.
9231 *
9232 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
9233 * voicemail vibration setting.
9234 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
9235 */
9236 @Override
9237 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009238 final long identity = Binder.clearCallingIdentity();
9239 try {
9240 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9241 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009242 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009243 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009244
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009245 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
9246 } finally {
9247 Binder.restoreCallingIdentity(identity);
9248 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009249 }
9250
Youhan Wange64578a2016-05-02 15:32:42 -07009251 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009252 * Sets the per-account voicemail vibration.
9253 *
9254 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9255 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9256 *
9257 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9258 * voicemail vibration setting.
9259 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9260 * specific PhoneAccount.
9261 */
9262 @Override
9263 public void setVoicemailVibrationEnabled(String callingPackage,
9264 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009265 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009266 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009267 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9268 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9270 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9271 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009272 }
9273
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009274 final long identity = Binder.clearCallingIdentity();
9275 try {
9276 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9277 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009278 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009279 }
9280 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9281 } finally {
9282 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009283 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009284 }
9285
9286 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009287 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9288 *
9289 * @throws SecurityException if the caller does not have the required permission
9290 */
arunvoddud7401012022-12-15 16:08:12 +00009291 @VisibleForTesting
9292 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009293 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009294 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009295 }
9296
9297 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009298 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9299 * permission.
9300 *
9301 * @throws SecurityException if the caller does not have the required permission
9302 */
9303 private void enforceSendSmsPermission() {
9304 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9305 }
9306
9307 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009308 * Make sure either called from same process as self (phone) or IPC caller has interact across
9309 * users permission.
9310 *
9311 * @throws SecurityException if the caller does not have the required permission
9312 */
9313 private void enforceInteractAcrossUsersPermission(String message) {
9314 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9315 }
9316
9317 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009318 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009319 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009320 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009321 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009322 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009323 final long identity = Binder.clearCallingIdentity();
9324 try {
9325 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009326 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009327 if (componentName == null) {
9328 throw new SecurityException(
9329 "Caller not current active visual voicemail package[null]");
9330 }
9331 String vvmPackage = componentName.getPackageName();
9332 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009333 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009334 }
9335 } finally {
9336 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009337 }
9338 }
9339
9340 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009341 * Return the application ID for the app type.
9342 *
9343 * @param subId the subscription ID that this request applies to.
9344 * @param appType the uicc app type.
9345 * @return Application ID for specificied app type, or null if no uicc.
9346 */
9347 @Override
9348 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009349 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07009350 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009351
9352 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009353 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009354 if (phone == null) {
9355 return null;
9356 }
9357 String aid = null;
9358 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009359 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009360 .getApplicationByType(appType).getAid();
9361 } catch (Exception e) {
9362 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9363 }
9364 return aid;
9365 } finally {
9366 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009367 }
Youhan Wange64578a2016-05-02 15:32:42 -07009368 }
9369
Youhan Wang4001d252016-05-11 10:29:41 -07009370 /**
9371 * Return the Electronic Serial Number.
9372 *
9373 * @param subId the subscription ID that this request applies to.
9374 * @return ESN or null if error.
9375 */
9376 @Override
9377 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009378 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009379 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009380
9381 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009382 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009383 if (phone == null) {
9384 return null;
9385 }
9386 String esn = null;
9387 try {
9388 esn = phone.getEsn();
9389 } catch (Exception e) {
9390 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9391 }
9392 return esn;
9393 } finally {
9394 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009395 }
Youhan Wang4001d252016-05-11 10:29:41 -07009396 }
9397
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009398 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009399 * Return the Preferred Roaming List Version.
9400 *
9401 * @param subId the subscription ID that this request applies to.
9402 * @return PRLVersion or null if error.
9403 */
9404 @Override
9405 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009406 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07009407 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009408
9409 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009410 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009411 if (phone == null) {
9412 return null;
9413 }
9414 String cdmaPrlVersion = null;
9415 try {
9416 cdmaPrlVersion = phone.getCdmaPrlVersion();
9417 } catch (Exception e) {
9418 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9419 }
9420 return cdmaPrlVersion;
9421 } finally {
9422 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009423 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009424 }
9425
9426 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009427 * Get snapshot of Telephony histograms
9428 * @return List of Telephony histograms
9429 * @hide
9430 */
9431 @Override
9432 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009433 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9434 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009435
9436 final long identity = Binder.clearCallingIdentity();
9437 try {
9438 return RIL.getTelephonyRILTimingHistograms();
9439 } finally {
9440 Binder.restoreCallingIdentity(identity);
9441 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009442 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009443
9444 /**
9445 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009446 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9447 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009448 * Require system privileges. In the future we may add this to carrier APIs.
9449 *
Michele Berionne482f8202018-11-27 18:57:59 -08009450 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009451 */
9452 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009453 @TelephonyManager.SetCarrierRestrictionResult
9454 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009455 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07009456 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009457
Michele Berionne482f8202018-11-27 18:57:59 -08009458 if (carrierRestrictionRules == null) {
9459 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009460 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009461
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009462 final long identity = Binder.clearCallingIdentity();
9463 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009464 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009465 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009466 } finally {
9467 Binder.restoreCallingIdentity(identity);
9468 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009469 }
9470
9471 /**
9472 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009473 * Get the allowed carrier list and the excluded carrier list, including the priority between
9474 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009475 * Require system privileges. In the future we may add this to carrier APIs.
9476 *
Michele Berionne482f8202018-11-27 18:57:59 -08009477 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009478 */
9479 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009480 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009481 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07009482 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009483
9484 final long identity = Binder.clearCallingIdentity();
9485 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009486 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9487 if (response instanceof CarrierRestrictionRules) {
9488 return (CarrierRestrictionRules) response;
9489 }
9490 // Response is an Exception of some kind,
9491 // which is signalled to the user as a NULL retval
9492 return null;
9493 } catch (Exception e) {
9494 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9495 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009496 } finally {
9497 Binder.restoreCallingIdentity(identity);
9498 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009499 }
9500
fionaxu59545b42016-05-25 15:53:37 -07009501 /**
arunvoddud7401012022-12-15 16:08:12 +00009502 * Fetches the carrier restriction status of the device and sends the status to the caller
9503 * through the callback.
9504 *
9505 * @param callback The callback that will be used to send the result.
9506 * @throws SecurityException if the caller does not have the required permission/privileges or
9507 * the caller is not allowlisted.
9508 */
9509 @Override
9510 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9511 enforceReadPermission("getCarrierRestrictionStatus");
9512 int carrierId = validateCallerAndGetCarrierId(packageName);
9513 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
9514 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9515 throw new SecurityException("Not an authorized caller");
9516 }
9517 final long identity = Binder.clearCallingIdentity();
9518 try {
9519 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
9520 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
9521 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9522 } finally {
9523 Binder.restoreCallingIdentity(identity);
9524 }
9525 }
9526
9527 @VisibleForTesting
9528 public int validateCallerAndGetCarrierId(String packageName) {
9529 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9530 return allowListInfo.validateCallerAndGetCarrierId(packageName);
9531 }
9532
9533 /**
fionaxu59545b42016-05-25 15:53:37 -07009534 * Action set from carrier signalling broadcast receivers to enable/disable radio
9535 * @param subId the subscription ID that this action applies to.
9536 * @param enabled control enable or disable radio.
9537 * {@hide}
9538 */
9539 @Override
9540 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9541 enforceModifyPermission();
9542 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009543
9544 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009545 if (phone == null) {
9546 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9547 return;
9548 }
9549 try {
9550 phone.carrierActionSetRadioEnabled(enabled);
9551 } catch (Exception e) {
9552 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009553 } finally {
9554 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009555 }
9556 }
9557
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009558 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009559 * Enable or disable Voice over NR (VoNR)
9560 * @param subId the subscription ID that this action applies to.
9561 * @param enabled enable or disable VoNR.
9562 * @return operation result.
9563 */
9564 @Override
9565 public int setVoNrEnabled(int subId, boolean enabled) {
9566 enforceModifyPermission();
9567 final Phone phone = getPhone(subId);
9568
9569 final long identity = Binder.clearCallingIdentity();
9570 if (phone == null) {
9571 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9572 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9573 }
9574
9575 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9576 try {
9577 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9578 workSource);
9579 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009580
9581 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9582 if (DBG) {
9583 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9584 }
9585 SubscriptionManager.setSubscriptionProperty(
9586 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9587 (enabled ? "1" : "0"));
9588 }
9589
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009590 return result;
9591 } finally {
9592 Binder.restoreCallingIdentity(identity);
9593 }
9594 }
9595
9596 /**
9597 * Is voice over NR enabled
9598 * @return true if VoNR is enabled else false
9599 */
9600 @Override
9601 public boolean isVoNrEnabled(int subId) {
9602 enforceReadPrivilegedPermission("isVoNrEnabled");
9603 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9604 final long identity = Binder.clearCallingIdentity();
9605 try {
9606 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9607 null, subId, workSource);
9608 if (DBG) log("isVoNrEnabled: " + isEnabled);
9609 return isEnabled;
9610 } finally {
9611 Binder.restoreCallingIdentity(identity);
9612 }
9613 }
9614
9615 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009616 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9617 * network status based on which carrier apps could apply actions accordingly,
9618 * enable/disable default url handler for example.
9619 *
9620 * @param subId the subscription ID that this action applies to.
9621 * @param report control start/stop reporting the default network status.
9622 * {@hide}
9623 */
9624 @Override
9625 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9626 enforceModifyPermission();
9627 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009628
9629 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009630 if (phone == null) {
9631 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9632 return;
9633 }
9634 try {
9635 phone.carrierActionReportDefaultNetworkStatus(report);
9636 } catch (Exception e) {
9637 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009638 } finally {
9639 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009640 }
9641 }
9642
9643 /**
fionaxud9622282017-07-17 17:51:30 -07009644 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9645 * @param subId the subscription ID that this action applies to.
9646 * {@hide}
9647 */
9648 @Override
9649 public void carrierActionResetAll(int subId) {
9650 enforceModifyPermission();
9651 final Phone phone = getPhone(subId);
9652 if (phone == null) {
9653 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9654 return;
9655 }
9656 try {
9657 phone.carrierActionResetAll();
9658 } catch (Exception e) {
9659 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9660 }
9661 }
9662
9663 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009664 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9665 * bug report is being generated.
9666 */
9667 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009668 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009669 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9670 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009671 writer.println("Permission Denial: can't dump Phone from pid="
9672 + Binder.getCallingPid()
9673 + ", uid=" + Binder.getCallingUid()
9674 + "without permission "
9675 + android.Manifest.permission.DUMP);
9676 return;
9677 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009678 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009679 }
Jack Yueb89b242016-06-22 13:27:47 -07009680
Brad Ebingerdac2f002018-04-03 15:17:52 -07009681 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009682 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9683 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9684 @NonNull String[] args) {
9685 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9686 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009687 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009688 }
9689
Jack Yueb89b242016-06-22 13:27:47 -07009690 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009691 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009692 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009693 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009694 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009695 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009696 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009697 */
9698 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009699 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009700 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009701 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9702 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9703 try {
9704 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009705 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009706 } catch (SecurityException se) {
9707 enforceModifyPermission();
9708 }
9709 } else {
9710 enforceModifyPermission();
9711 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009712
9713 final long identity = Binder.clearCallingIdentity();
9714 try {
9715 Phone phone = getPhone(subId);
9716 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009717 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9718 phone.carrierActionSetMeteredApnsEnabled(enabled);
9719 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009720 phone.getDataSettingsManager().setDataEnabled(
9721 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009722 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009723 }
9724 } finally {
9725 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009726 }
9727 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009728
9729 /**
9730 * Get Client request stats
9731 * @return List of Client Request Stats
9732 * @hide
9733 */
9734 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009735 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9736 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009737 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009738 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009739 return null;
9740 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009741 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009742
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009743 final long identity = Binder.clearCallingIdentity();
9744 try {
9745 if (phone != null) {
9746 return phone.getClientRequestStats();
9747 }
9748
9749 return null;
9750 } finally {
9751 Binder.restoreCallingIdentity(identity);
9752 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009753 }
9754
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009755 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009756 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009757 if (uid == Process.ROOT_UID && packageName == null) {
9758 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9759 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9760 // exception. ROOT_UID seems not to have a valid package name returned by
9761 // PackageManager, so just fake it here to avoid issues when running telephony shell
9762 // commands that plumb through the RIL as root, like so:
9763 // $ adb root
9764 // $ adb shell cmd phone ...
9765 packageName = "root";
9766 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009767 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009768 }
Jack Yueb4124c2017-02-16 15:32:43 -08009769
9770 /**
Grace Chen70990072017-03-24 17:21:30 -07009771 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009772 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009773 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009774 * @param state State of SIM (power down, power up, pass through)
9775 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9776 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9777 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009778 *
9779 **/
9780 @Override
Grace Chen70990072017-03-24 17:21:30 -07009781 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009782 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009783 Phone phone = PhoneFactory.getPhone(slotIndex);
9784
vagdeviaf9a5b92018-08-15 16:01:53 -07009785 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9786
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009787 final long identity = Binder.clearCallingIdentity();
9788 try {
9789 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009790 phone.setSimPowerState(state, null, workSource);
9791 }
9792 } finally {
9793 Binder.restoreCallingIdentity(identity);
9794 }
9795 }
9796
9797 /**
9798 * Set SIM card power state.
9799 *
9800 * @param slotIndex SIM slot id.
9801 * @param state State of SIM (power down, power up, pass through)
9802 * @param callback callback to trigger after success or failure
9803 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9804 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9805 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9806 *
9807 **/
9808 @Override
9809 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9810 IIntegerConsumer callback) {
9811 enforceModifyPermission();
9812 Phone phone = PhoneFactory.getPhone(slotIndex);
9813
9814 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9815
9816 final long identity = Binder.clearCallingIdentity();
9817 try {
9818 if (phone != null) {
9819 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9820 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009821 }
9822 } finally {
9823 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009824 }
9825 }
Shuo Qiandd210312017-04-12 22:11:33 +00009826
Tyler Gunn65d45c22017-06-05 11:22:26 -07009827 private boolean isUssdApiAllowed(int subId) {
9828 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009829 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009830 if (configManager == null) {
9831 return false;
9832 }
9833 PersistableBundle pb = configManager.getConfigForSubId(subId);
9834 if (pb == null) {
9835 return false;
9836 }
9837 return pb.getBoolean(
9838 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9839 }
9840
Shuo Qiandd210312017-04-12 22:11:33 +00009841 /**
9842 * Check if phone is in emergency callback mode
9843 * @return true if phone is in emergency callback mode
9844 * @param subId sub id
9845 */
goneil9c5f4872017-12-05 14:07:56 -08009846 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009847 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009848 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00009849 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009850
9851 final long identity = Binder.clearCallingIdentity();
9852 try {
9853 if (phone != null) {
9854 return phone.isInEcm();
9855 } else {
9856 return false;
9857 }
9858 } finally {
9859 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009860 }
9861 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009862
9863 /**
9864 * Get the current signal strength information for the given subscription.
9865 * Because this information is not updated when the device is in a low power state
9866 * it should not be relied-upon to be current.
9867 * @param subId Subscription index
9868 * @return the most recent cached signal strength info from the modem
9869 */
9870 @Override
9871 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009872 final long identity = Binder.clearCallingIdentity();
9873 try {
9874 Phone p = getPhone(subId);
9875 if (p == null) {
9876 return null;
9877 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009879 return p.getSignalStrength();
9880 } finally {
9881 Binder.restoreCallingIdentity(identity);
9882 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009883 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009884
Pengquan Meng77b7f132018-08-22 14:49:57 -07009885 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009886 * Get the current modem radio state for the given slot.
9887 * @param slotIndex slot index.
9888 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009889 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009890 * @return the current radio power state from the modem
9891 */
9892 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009893 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009894 Phone phone = PhoneFactory.getPhone(slotIndex);
9895 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009896 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9897 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009898 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9899 }
9900
9901 final long identity = Binder.clearCallingIdentity();
9902 try {
9903 return phone.getRadioPowerState();
9904 } finally {
9905 Binder.restoreCallingIdentity(identity);
9906 }
9907 }
9908 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9909 }
9910
9911 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009912 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9913 *
9914 * <p>Requires one of the following permissions:
9915 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009916 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009917 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9918 * privileges.
9919 *
9920 * @param subId subscription id
9921 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9922 * {@code false}.
9923 */
9924 @Override
9925 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009926 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009927 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009928 try {
9929 mApp.enforceCallingOrSelfPermission(
9930 android.Manifest.permission.ACCESS_NETWORK_STATE,
9931 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009932 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009933 mApp.enforceCallingOrSelfPermission(
9934 permission.READ_BASIC_PHONE_STATE, functionName);
9935 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009936 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009937 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009938 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009939 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009940
Pengquan Menga1bb6272018-09-06 09:59:22 -07009941 boolean isEnabled = false;
9942 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009943 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009944 Phone phone = getPhone(subId);
9945 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009946 } finally {
9947 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009948 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009949 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009950 }
9951
9952
9953 /**
9954 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9955 *
9956 * <p> Requires permission:
9957 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9958 * privileges.
9959 *
9960 * @param subId subscription id
9961 * @param isEnabled {@code true} means enable, {@code false} means disable.
9962 */
9963 @Override
9964 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009965 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9966 mApp, subId, "setDataRoamingEnabled");
9967
Pengquan Menga1bb6272018-09-06 09:59:22 -07009968 final long identity = Binder.clearCallingIdentity();
9969 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009970 Phone phone = getPhone(subId);
9971 if (phone != null) {
9972 phone.setDataRoamingEnabled(isEnabled);
9973 }
9974 } finally {
9975 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009976 }
9977 }
9978
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009979 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009980 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009981 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009982 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009983 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009984
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009985 boolean isAllowed = true;
9986 final long identity = Binder.clearCallingIdentity();
9987 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009988 Phone phone = getPhone(subId);
9989 if (phone != null) {
9990 isAllowed = phone.isCspPlmnEnabled();
9991 }
9992 } finally {
9993 Binder.restoreCallingIdentity(identity);
9994 }
9995 return isAllowed;
9996 }
9997
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009998 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9999 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -080010000 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010001 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010002 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -080010003 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
10004 if (phone == null) {
10005 return false;
10006 }
10007 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10008 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
10009 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010010 }
10011
Pengquan Meng6884a2c2018-10-03 12:19:13 -070010012 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -080010013 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +000010014 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -070010015 mApp.getSystemService(AppOpsManager.class)
10016 .checkPackage(Binder.getCallingUid(), callingPackage);
10017
Jordan Liu1e142fc2019-04-22 15:10:43 -070010018 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +000010019 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -080010020 try {
10021 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -070010022 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -080010023 } catch (SecurityException e) {
10024 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
10025 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -080010026 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010027 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -070010028 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -080010029 }
Jordan Liu75f43ea2019-01-17 16:56:37 -080010030 }
sandeepjsb6c87872021-09-27 15:34:44 +000010031 // checking compatibility, if calling app's target SDK is T and beyond.
10032 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
10033 Binder.getCallingUid())) {
10034 isIccIdAccessRestricted = true;
10035 }
Jordan Liu5aa07002018-12-18 15:44:48 -080010036 final long identity = Binder.clearCallingIdentity();
10037 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -080010038 UiccController uiccController = UiccController.getInstance();
10039 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -070010040 if (hasReadPermission) {
10041 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -080010042 }
Jordan Liu1e142fc2019-04-22 15:10:43 -070010043
10044 // Remove private info if the caller doesn't have access
10045 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
10046 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +000010047 //setting the value after compatibility check
10048 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -070010049 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
10050 // is available
sandeepjsb6c87872021-09-27 15:34:44 +000010051 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010052 if (card == null) {
10053 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +000010054 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -070010055 continue;
10056 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010057 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
10058 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +000010059 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010060 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -070010061 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010062 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
10063 for (UiccPortInfo portInfo : portInfos) {
10064 UiccPort port = uiccController.getUiccPortForSlot(
10065 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
10066 if (port == null) {
10067 // assume no access if port is null
10068 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
10069 continue;
10070 }
10071 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10072 uiccPortInfos.add(portInfo);
10073 } else {
10074 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
10075 }
10076 }
10077 filteredInfos.add(new UiccCardInfo(
10078 cardInfo.isEuicc(),
10079 cardInfo.getCardId(),
10080 null,
10081 cardInfo.getPhysicalSlotIndex(),
10082 cardInfo.isRemovable(),
10083 cardInfo.isMultipleEnabledProfilesSupported(),
10084 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -070010085 }
10086 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -080010087 } finally {
10088 Binder.restoreCallingIdentity(identity);
10089 }
10090 }
10091
sandeepjsb6c87872021-09-27 15:34:44 +000010092 /**
10093 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
10094 * generally private and require carrier privileges to view.
10095 *
10096 * @hide
10097 */
10098 @NonNull
10099 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
10100 List<UiccPortInfo> portinfo = new ArrayList<>();
10101 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
10102 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
10103 }
10104 return new UiccCardInfo(
10105 cardInfo.isEuicc(),
10106 cardInfo.getCardId(),
10107 null,
10108 cardInfo.getPhysicalSlotIndex(),
10109 cardInfo.isRemovable(),
10110 cardInfo.isMultipleEnabledProfilesSupported(),
10111 portinfo
10112 );
10113 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010114
sandeepjsb6c87872021-09-27 15:34:44 +000010115 /**
10116 * @hide
10117 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
10118 * These values are generally private and require carrier privileges to view.
10119 */
10120 @NonNull
10121 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
10122 return new UiccPortInfo(
10123 UiccPortInfo.ICCID_REDACTED,
10124 portInfo.getPortIndex(),
10125 portInfo.getLogicalSlotIndex(),
10126 portInfo.isActive()
10127 );
10128 }
10129 @Override
10130 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +000010131 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +000010132 mApp.getSystemService(AppOpsManager.class)
10133 .checkPackage(Binder.getCallingUid(), callingPackage);
10134
sandeepjsb6c87872021-09-27 15:34:44 +000010135 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +000010136
Aman Guptaf3c90b32022-03-17 04:54:16 +000010137 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
10138 // we are reading iccId which is PII data.
10139 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +000010140
10141 // checking compatibility, if calling app's target SDK is T and beyond.
10142 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
10143 Binder.getCallingUid())) {
10144 isLogicalSlotAccessRestricted = true;
10145 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010146 final long identity = Binder.clearCallingIdentity();
10147 try {
10148 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +000010149 if (slots == null || slots.length == 0) {
10150 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010151 return null;
10152 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010153 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
10154 for (int i = 0; i < slots.length; i++) {
10155 UiccSlot slot = slots[i];
10156 if (slot == null) {
10157 continue;
10158 }
10159
Jordan Liu7be7e652019-05-06 18:55:02 +000010160 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010161 UiccCard card = slot.getUiccCard();
10162 if (card != null) {
10163 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +000010164 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -070010165 cardId = slot.getEid();
10166 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +000010167 // If cardId is null, use iccId of default port as cardId.
10168 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -070010169 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010170 }
10171
Jordan Liu857451f2019-05-09 16:35:35 -070010172 if (cardId != null) {
10173 // if cardId is an ICCID, strip off trailing Fs before exposing to user
10174 // if cardId is an EID, it's all digits so this is fine
10175 cardId = IccUtils.stripTrailingFs(cardId);
10176 }
10177
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010178 int cardState = 0;
10179 switch (slot.getCardState()) {
10180 case CARDSTATE_ABSENT:
10181 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
10182 break;
10183 case CARDSTATE_PRESENT:
10184 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
10185 break;
10186 case CARDSTATE_ERROR:
10187 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
10188 break;
10189 case CARDSTATE_RESTRICTED:
10190 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
10191 break;
10192 default:
10193 break;
10194
10195 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010196 List<UiccPortInfo> portInfos = new ArrayList<>();
10197 int[] portIndexes = slot.getPortList();
10198 for (int portIdx : portIndexes) {
10199 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010200 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010201 portInfos.add(new UiccPortInfo(iccId, portIdx,
10202 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010203 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010204 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010205 slot.isEuicc(),
10206 cardId,
10207 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010208 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010209 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010210 //setting the value after compatibility check
10211 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010212 }
10213 return infos;
10214 } finally {
10215 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010216 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010217 }
10218
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010219 /* Returns null if doesn't have read permission or carrier privilege access. */
10220 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10221 boolean hasReadPermission) {
10222 String iccId = slot.getIccId(portIndex);
10223 if (hasReadPermission) { // if has read permission
10224 return iccId;
10225 } else {
10226 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10227 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10228 // if no read permission, checking carrier privilege access
10229 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10230 return iccId;
10231 }
10232 }
10233 }
10234 // No read permission or carrier privilege access.
10235 return UiccPortInfo.ICCID_REDACTED;
10236 }
10237
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010238 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010239 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010240 public boolean switchSlots(int[] physicalSlots) {
10241 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010242
10243 final long identity = Binder.clearCallingIdentity();
10244 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010245 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10246 for (int i = 0; i < physicalSlots.length; i++) {
10247 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10248 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10249 physicalSlots[i], i));
10250 }
10251 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010252 } finally {
10253 Binder.restoreCallingIdentity(identity);
10254 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010255 }
Jack Yu4c988042018-02-27 15:30:01 -080010256
10257 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010258 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10259 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10260 enforceModifyPermission();
10261
10262 final long identity = Binder.clearCallingIdentity();
10263 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010264 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010265 } finally {
10266 Binder.restoreCallingIdentity(identity);
10267 }
10268 }
10269
10270 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010271 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -080010272 final long identity = Binder.clearCallingIdentity();
10273 try {
10274 return UiccController.getInstance().getCardIdForDefaultEuicc();
10275 } finally {
10276 Binder.restoreCallingIdentity(identity);
10277 }
10278 }
10279
Pengquan Meng85728fb2018-03-12 16:31:21 -070010280 /**
goneil47ffb6e2018-04-06 15:40:58 -070010281 * A test API to reload the UICC profile.
10282 *
10283 * <p>Requires that the calling app has permission
10284 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10285 * @hide
10286 */
10287 @Override
10288 public void refreshUiccProfile(int subId) {
10289 enforceModifyPermission();
10290
10291 final long identity = Binder.clearCallingIdentity();
10292 try {
10293 Phone phone = getPhone(subId);
10294 if (phone == null) {
10295 return;
10296 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010297 UiccPort uiccPort = phone.getUiccPort();
10298 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010299 return;
10300 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010301 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010302 if (uiccProfile == null) {
10303 return;
10304 }
10305 uiccProfile.refresh();
10306 } finally {
10307 Binder.restoreCallingIdentity(identity);
10308 }
10309 }
10310
10311 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010312 * Returns false if the mobile data is disabled by default, otherwise return true.
10313 */
10314 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010315 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010316 }
10317
10318 /**
10319 * Returns true if the data roaming is enabled by default, i.e the system property
10320 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
10321 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
10322 */
10323 private boolean getDefaultDataRoamingEnabled(int subId) {
10324 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010325 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -070010326 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010327 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
10328 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
10329 return isDataRoamingEnabled;
10330 }
10331
10332 /**
10333 * Returns the default network type for the given {@code subId}, if the default network type is
10334 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10335 */
10336 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010337 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010338 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010339 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10340 return list.get(phoneId);
10341 }
10342 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010343 }
fionaxua13278b2018-03-21 00:08:13 -070010344
10345 @Override
10346 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010347 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010348 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010349
10350 final long identity = Binder.clearCallingIdentity();
10351 try {
10352 final Phone phone = getPhone(subId);
10353 if (phone == null) {
10354 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10355 return;
10356 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010357 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10358 if (cpt != null) {
10359 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10360 }
10361 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010362 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10363 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010364 if (carrierPrivilegeRules == null) {
10365 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10366 } else {
10367 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10368 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010369 } finally {
10370 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010371 }
fionaxua13278b2018-03-21 00:08:13 -070010372 }
10373
10374 @Override
10375 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010376 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010377
10378 final long identity = Binder.clearCallingIdentity();
10379 try {
10380 final Phone phone = getPhone(subId);
10381 if (phone == null) {
10382 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10383 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10384 }
10385 return phone.getCarrierIdListVersion();
10386 } finally {
10387 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010388 }
fionaxua13278b2018-03-21 00:08:13 -070010389 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010390
10391 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010392 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10393 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010394 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010395 mApp, subId, callingPackage, callingFeatureId,
10396 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010397 return -1;
10398 }
10399
10400 final long identity = Binder.clearCallingIdentity();
10401 try {
10402 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10403 } finally {
10404 Binder.restoreCallingIdentity(identity);
10405 }
10406 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010407
10408 @Override
10409 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010410 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010411 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010412 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010413
10414 final long identity = Binder.clearCallingIdentity();
10415 try {
10416 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10417 } finally {
10418 Binder.restoreCallingIdentity(identity);
10419 }
10420 }
10421
10422 @Override
10423 public boolean setCdmaRoamingMode(int subId, int mode) {
10424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10425 mApp, subId, "setCdmaRoamingMode");
10426
10427 final long identity = Binder.clearCallingIdentity();
10428 try {
10429 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10430 } finally {
10431 Binder.restoreCallingIdentity(identity);
10432 }
10433 }
10434
10435 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010436 public int getCdmaSubscriptionMode(int subId) {
10437 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010438 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010439 mApp, subId, "getCdmaSubscriptionMode");
10440
10441 final long identity = Binder.clearCallingIdentity();
10442 try {
10443 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10444 } finally {
10445 Binder.restoreCallingIdentity(identity);
10446 }
10447 }
10448
10449 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010450 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10451 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10452 mApp, subId, "setCdmaSubscriptionMode");
10453
10454 final long identity = Binder.clearCallingIdentity();
10455 try {
10456 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10457 } finally {
10458 Binder.restoreCallingIdentity(identity);
10459 }
10460 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010461
sqianc5eccab2018-10-19 18:46:41 -070010462 @Override
sqian8c685422019-02-22 15:55:18 -080010463 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010464 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010465 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010466 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10467 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010468 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10469 }
10470 final long identity = Binder.clearCallingIdentity();
10471 try {
sqian854d44b2018-12-12 16:48:18 -080010472 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10473 for (Phone phone: PhoneFactory.getPhones()) {
10474 if (phone.getEmergencyNumberTracker() != null
10475 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10476 emergencyNumberListInternal.put(
10477 phone.getSubId(),
10478 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10479 }
sqian11b7a0e2018-12-05 18:48:28 -080010480 }
sqian854d44b2018-12-12 16:48:18 -080010481 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010482 } finally {
10483 Binder.restoreCallingIdentity(identity);
10484 }
sqianc5eccab2018-10-19 18:46:41 -070010485 }
10486
10487 @Override
sqian8c685422019-02-22 15:55:18 -080010488 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010489 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010490 if (!exactMatch) {
10491 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010492 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010493 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010494 }
10495 final long identity = Binder.clearCallingIdentity();
10496 try {
sqian854d44b2018-12-12 16:48:18 -080010497 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010498 //Note: we ignore passed in param exactMatch. We can remove it once
10499 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010500 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010501 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010502 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010503 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010504 }
sqian11b7a0e2018-12-05 18:48:28 -080010505 }
10506 return false;
10507 } finally {
10508 Binder.restoreCallingIdentity(identity);
10509 }
10510 }
10511
sqianf4ca7ed2019-01-15 18:32:07 -080010512 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010513 * Start emergency callback mode for GsmCdmaPhone for testing.
10514 */
10515 @Override
10516 public void startEmergencyCallbackMode() {
10517 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10518 "startEmergencyCallbackMode");
10519 enforceModifyPermission();
10520 final long identity = Binder.clearCallingIdentity();
10521 try {
10522 for (Phone phone : PhoneFactory.getPhones()) {
10523 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10524 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10525 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10526 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10527 gsmCdmaPhone.obtainMessage(
10528 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10529 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10530 }
10531 }
10532 } finally {
10533 Binder.restoreCallingIdentity(identity);
10534 }
10535 }
10536
10537 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010538 * Update emergency number list for test mode.
10539 */
10540 @Override
10541 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10542 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10543 "updateEmergencyNumberListTestMode");
10544
10545 final long identity = Binder.clearCallingIdentity();
10546 try {
10547 for (Phone phone: PhoneFactory.getPhones()) {
10548 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10549 if (tracker != null) {
10550 tracker.executeEmergencyNumberTestModeCommand(action, num);
10551 }
10552 }
10553 } finally {
10554 Binder.restoreCallingIdentity(identity);
10555 }
10556 }
10557
10558 /**
10559 * Get the full emergency number list for test mode.
10560 */
10561 @Override
10562 public List<String> getEmergencyNumberListTestMode() {
10563 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10564 "getEmergencyNumberListTestMode");
10565
10566 final long identity = Binder.clearCallingIdentity();
10567 try {
10568 Set<String> emergencyNumbers = new HashSet<>();
10569 for (Phone phone: PhoneFactory.getPhones()) {
10570 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10571 if (tracker != null) {
10572 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10573 emergencyNumbers.add(num.getNumber());
10574 }
10575 }
10576 }
10577 return new ArrayList<>(emergencyNumbers);
10578 } finally {
10579 Binder.restoreCallingIdentity(identity);
10580 }
10581 }
10582
chen xud6b45bd2018-10-30 22:27:10 -070010583 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010584 public int getEmergencyNumberDbVersion(int subId) {
10585 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10586
10587 final long identity = Binder.clearCallingIdentity();
10588 try {
10589 final Phone phone = getPhone(subId);
10590 if (phone == null) {
10591 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10592 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10593 }
10594 return phone.getEmergencyNumberDbVersion();
10595 } finally {
10596 Binder.restoreCallingIdentity(identity);
10597 }
10598 }
10599
10600 @Override
10601 public void notifyOtaEmergencyNumberDbInstalled() {
10602 enforceModifyPermission();
10603
10604 final long identity = Binder.clearCallingIdentity();
10605 try {
10606 for (Phone phone: PhoneFactory.getPhones()) {
10607 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10608 if (tracker != null) {
10609 tracker.updateOtaEmergencyNumberDatabase();
10610 }
10611 }
10612 } finally {
10613 Binder.restoreCallingIdentity(identity);
10614 }
10615 }
10616
10617 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010618 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010619 enforceActiveEmergencySessionPermission();
10620
10621 final long identity = Binder.clearCallingIdentity();
10622 try {
10623 for (Phone phone: PhoneFactory.getPhones()) {
10624 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10625 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010626 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10627 }
10628 }
10629 } finally {
10630 Binder.restoreCallingIdentity(identity);
10631 }
10632 }
10633
10634 @Override
10635 public void resetOtaEmergencyNumberDbFilePath() {
10636 enforceActiveEmergencySessionPermission();
10637
10638 final long identity = Binder.clearCallingIdentity();
10639 try {
10640 for (Phone phone: PhoneFactory.getPhones()) {
10641 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10642 if (tracker != null) {
10643 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010644 }
10645 }
10646 } finally {
10647 Binder.restoreCallingIdentity(identity);
10648 }
10649 }
10650
10651 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010652 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10653 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10654 Phone phone = getPhone(subId);
10655 if (phone == null) {
10656 return null;
10657 }
10658 final long identity = Binder.clearCallingIdentity();
10659 try {
10660 UiccProfile profile = UiccController.getInstance()
10661 .getUiccProfileForPhone(phone.getPhoneId());
10662 if (profile != null) {
10663 return profile.getCertsFromCarrierPrivilegeAccessRules();
10664 }
10665 } finally {
10666 Binder.restoreCallingIdentity(identity);
10667 }
10668 return null;
10669 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010670
10671 /**
10672 * Enable or disable a modem stack.
10673 */
10674 @Override
10675 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10676 enforceModifyPermission();
10677
10678 final long identity = Binder.clearCallingIdentity();
10679 try {
10680 Phone phone = PhoneFactory.getPhone(slotIndex);
10681 if (phone == null) {
10682 return false;
10683 } else {
10684 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10685 }
10686 } finally {
10687 Binder.restoreCallingIdentity(identity);
10688 }
10689 }
Michelecea4cf22018-12-21 15:00:11 -080010690
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010691 /**
10692 * Whether a modem stack is enabled or not.
10693 */
10694 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010695 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10696 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010697 Phone phone = PhoneFactory.getPhone(slotIndex);
10698 if (phone == null) return false;
10699
10700 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010701 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10702 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010703 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10704 }
10705
10706 final long identity = Binder.clearCallingIdentity();
10707 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010708 try {
10709 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10710 } catch (NoSuchElementException ex) {
10711 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10712 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010713 } finally {
10714 Binder.restoreCallingIdentity(identity);
10715 }
10716 }
10717
Michelecea4cf22018-12-21 15:00:11 -080010718 @Override
Michele0ea7d782019-03-19 14:58:42 -070010719 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010720 enforceModifyPermission();
10721
10722 final long identity = Binder.clearCallingIdentity();
10723 try {
10724 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010725 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010726 .commit();
10727 } finally {
10728 Binder.restoreCallingIdentity(identity);
10729 }
10730 }
10731
10732 @Override
Michele0ea7d782019-03-19 14:58:42 -070010733 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010734 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010735 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010736 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10737 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010738 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010739 }
Michelecea4cf22018-12-21 15:00:11 -080010740
10741 final long identity = Binder.clearCallingIdentity();
10742 try {
Michele0ea7d782019-03-19 14:58:42 -070010743 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010744 } finally {
10745 Binder.restoreCallingIdentity(identity);
10746 }
10747 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010748
Michele0ea7d782019-03-19 14:58:42 -070010749 @TelephonyManager.IsMultiSimSupportedResult
10750 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010751 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10752 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10753 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010754 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10755 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010756 }
10757 // Check if the hardware supports multisim functionality. If usage of multisim is not
10758 // supported by the modem, indicate that it is restricted.
10759 PhoneCapability staticCapability =
10760 mPhoneConfigurationManager.getStaticPhoneCapability();
10761 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010762 loge("isMultiSimSupportedInternal: no static configuration available");
10763 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010764 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010765 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010766 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10767 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010768 }
10769 // Check if support of multiple SIMs is restricted by carrier
10770 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010771 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010772 }
10773
Michele0ea7d782019-03-19 14:58:42 -070010774 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010775 }
10776
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010777 /**
10778 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010779 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10780 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10781 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010782 * @param numOfSims number of active sims we want to switch to
10783 */
10784 @Override
10785 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010786 if (numOfSims == 1) {
10787 enforceModifyPermission();
10788 } else {
10789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10790 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10791 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010792 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010793
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010794 try {
Michele30b57b22019-03-01 12:01:14 -080010795 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010796 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010797 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10798 return;
10799 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010800 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10801 } finally {
10802 Binder.restoreCallingIdentity(identity);
10803 }
10804 }
10805
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010806 @Override
10807 public boolean isApplicationOnUicc(int subId, int appType) {
10808 enforceReadPrivilegedPermission("isApplicationOnUicc");
10809 Phone phone = getPhone(subId);
10810 if (phone == null) {
10811 return false;
10812 }
10813 final long identity = Binder.clearCallingIdentity();
10814 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010815 UiccPort uiccPort = phone.getUiccPort();
10816 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010817 return false;
10818 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010819 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010820 if (uiccProfile == null) {
10821 return false;
10822 }
10823 if (TelephonyManager.APPTYPE_SIM <= appType
10824 && appType <= TelephonyManager.APPTYPE_ISIM) {
10825 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10826 }
10827 return false;
10828 } finally {
10829 Binder.restoreCallingIdentity(identity);
10830 }
10831 }
10832
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010833 /**
chen xub4baa772019-04-03 10:23:41 -070010834 * Get whether making changes to modem configurations will trigger reboot.
10835 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010836 */
10837 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010838 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10839 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010840 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010841 mApp, subId, callingPackage, callingFeatureId,
10842 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010843 return false;
10844 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010845 final long identity = Binder.clearCallingIdentity();
10846 try {
10847 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10848 } finally {
10849 Binder.restoreCallingIdentity(identity);
10850 }
10851 }
10852
Nathan Harold29f5f052019-02-15 13:41:57 -080010853 private void updateModemStateMetrics() {
10854 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10855 // TODO: check the state for each modem if the api is ready.
10856 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10857 }
10858
Pengquan Meng3889a572019-01-23 11:16:29 -080010859 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010860 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010861 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010862 // Verify that the callingPackage belongs to the calling UID
10863 mApp.getSystemService(AppOpsManager.class)
10864 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010865 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010866 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010867 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010868 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10869 if (slotInfos != null) {
10870 for (int i = 0; i < slotInfos.length; i++) {
10871 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10872 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10873 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10874 portInfo.getLogicalSlotIndex()));
10875 }
10876 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010877 }
10878 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010879 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010880 } finally {
10881 Binder.restoreCallingIdentity(identity);
10882 }
10883 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010884
10885 /**
10886 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010887 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010888 */
jimsunf9ec1622022-09-13 21:18:43 +080010889 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010890 @Override
10891 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010892 return getHalVersion(HAL_SERVICE_RADIO);
10893 }
10894
10895 /**
10896 * Get the HAL Version of a specific service
10897 */
10898 @Override
10899 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010900 Phone phone = getDefaultPhone();
10901 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010902 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010903 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10904 return hv.major * 100 + hv.minor;
10905 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010906
10907 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010908 * Get the current calling package name.
10909 * @return the current calling package name
10910 */
10911 @Override
10912 public String getCurrentPackageName() {
10913 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10914 }
10915
10916 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010917 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10918 * corresponding network requests on a subId.
10919 *
10920 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010921 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010922 * 2) APN is un-metered for this subscription, or
10923 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010924 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010925 *
10926 * @return whether data is allowed for a apn type.
10927 *
10928 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010929 */
10930 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010931 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010932 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10933 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010934
10935 // Now that all security checks passes, perform the operation as ourselves.
10936 final long identity = Binder.clearCallingIdentity();
10937 try {
10938 Phone phone = getPhone(subId);
10939 if (phone == null) return false;
10940
Jack Yu27422a52022-03-21 10:38:05 -070010941 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010942 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010943 isMetered = phone.getDataNetworkController().getDataConfigManager()
10944 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10945 phone.getServiceState().getDataRoaming());
10946 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010947 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010948 } finally {
10949 Binder.restoreCallingIdentity(identity);
10950 }
10951 }
10952
10953 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010954 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010955 enforceReadPrivilegedPermission("isApnMetered");
10956
10957 // Now that all security checks passes, perform the operation as ourselves.
10958 final long identity = Binder.clearCallingIdentity();
10959 try {
10960 Phone phone = getPhone(subId);
10961 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010962 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10963 DataUtils.apnTypeToNetworkCapability(apnType),
10964 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010965 } finally {
10966 Binder.restoreCallingIdentity(identity);
10967 }
10968 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010969
10970 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010971 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10972 int subscriptionId, IBooleanConsumer resultCallback) {
10973 enforceModifyPermission();
10974 long token = Binder.clearCallingIdentity();
10975 try {
10976 Phone phone = getPhone(subscriptionId);
10977 if (phone == null) {
10978 try {
10979 if (resultCallback != null) {
10980 resultCallback.accept(false);
10981 }
10982 } catch (RemoteException e) {
10983 // ignore
10984 }
10985 return;
10986 }
10987 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10988 Pair.create(specifiers, (x) -> {
10989 try {
10990 if (resultCallback != null) {
10991 resultCallback.accept(x);
10992 }
10993 } catch (RemoteException e) {
10994 // ignore
10995 }
10996 });
10997 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10998 } finally {
10999 Binder.restoreCallingIdentity(token);
11000 }
11001 }
11002
11003 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080011004 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
11005 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070011006 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080011007 mApp, subId, "getSystemSelectionChannels");
11008 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11009 final long identity = Binder.clearCallingIdentity();
11010 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080011011 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
11012 if (result instanceof IllegalStateException) {
11013 throw (IllegalStateException) result;
11014 }
11015 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080011016 if (DBG) log("getSystemSelectionChannels: " + specifiers);
11017 return specifiers;
11018 } finally {
11019 Binder.restoreCallingIdentity(identity);
11020 }
11021 }
11022
11023 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070011024 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080011025 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070011026 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080011027 }
11028
11029 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011030 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
11031 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080011032 if (callingPackage == null) {
11033 callingPackage = getCurrentPackageName();
11034 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070011035 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
11036 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011037 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
11038 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070011039 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
11040 }
11041 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
11042 Intent intent = new Intent();
11043 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
11044 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11045 // Bring up choose default SMS subscription dialog right now
11046 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
11047 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
11048 mApp.startActivity(intent);
11049 }
chen xud5ca2d52019-05-28 15:20:57 -070011050
11051 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000011052 public void showSwitchToManagedProfileDialog() {
11053 enforceModifyPermission();
11054
11055 Intent intent = new Intent();
11056 intent.setClass(mApp, ErrorDialogActivity.class);
11057 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11058 mApp.startActivity(intent);
11059 }
11060
11061 @Override
chen xud5ca2d52019-05-28 15:20:57 -070011062 public String getMmsUAProfUrl(int subId) {
11063 //TODO investigate if this API should require proper permission check in R b/133791609
11064 final long identity = Binder.clearCallingIdentity();
11065 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011066 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
11067 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
11068 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
11069 return carrierUAProfUrl;
11070 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011071 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11072 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070011073 } finally {
11074 Binder.restoreCallingIdentity(identity);
11075 }
11076 }
11077
11078 @Override
11079 public String getMmsUserAgent(int subId) {
11080 //TODO investigate if this API should require proper permission check in R b/133791609
11081 final long identity = Binder.clearCallingIdentity();
11082 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011083 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
11084 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
11085 if (!TextUtils.isEmpty(carrierUserAgent)) {
11086 return carrierUserAgent;
11087 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011088 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11089 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011090 } finally {
11091 Binder.restoreCallingIdentity(identity);
11092 }
11093 }
Jack Yub07d4972019-05-28 16:12:25 -070011094
11095 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011096 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11097 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011098
Jack Yub07d4972019-05-28 16:12:25 -070011099 final long identity = Binder.clearCallingIdentity();
11100 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011101 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070011102 if (phone == null) return false;
11103
Ling Maf188d502022-09-16 15:22:36 -070011104 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011105 } finally {
11106 Binder.restoreCallingIdentity(identity);
11107 }
11108 }
11109
11110 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011111 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011112 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011113 enforceModifyPermission();
11114
changbettyd5c246e2019-12-24 15:40:37 +080011115 final long identity = Binder.clearCallingIdentity();
11116 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011117 Phone phone = getPhone(subscriptionId);
11118 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011119
Ling Maf188d502022-09-16 15:22:36 -070011120 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011121 } finally {
11122 Binder.restoreCallingIdentity(identity);
11123 }
11124 }
11125
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011126 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011127 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011128 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11129 * otherwise.
11130 */
11131 @Override
11132 public void setCepEnabled(boolean isCepEnabled) {
11133 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11134
11135 final long identity = Binder.clearCallingIdentity();
11136 try {
11137 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11138 for (Phone phone : PhoneFactory.getPhones()) {
11139 Phone defaultPhone = phone.getImsPhone();
11140 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11141 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11142 ImsPhoneCallTracker imsPhoneCallTracker =
11143 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11144 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11145 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11146 + imsPhone.getMsisdn());
11147 }
11148 }
11149 } finally {
11150 Binder.restoreCallingIdentity(identity);
11151 }
11152 }
allenwtsu46dcc572020-01-08 18:24:03 +080011153
11154 /**
11155 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11156 *
11157 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11158 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11159 * before being read.
11160 */
11161 @Override
11162 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11163 isCompressed) {
11164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11165 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011166 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11167 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11168 }
11169 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011170 // ProvisioningManager can not handle ServiceSpecificException.
11171 // Throw the IllegalStateException and annotate ProvisioningManager.
11172 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000011173 }
11174
11175 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011176 try {
Hui Wang761a6682020-10-31 05:12:53 +000011177 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11178 } finally {
11179 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011180 }
11181 }
zoey chene02881a2019-12-30 16:11:23 +080011182
11183 @Override
11184 public boolean isIccLockEnabled(int subId) {
11185 enforceReadPrivilegedPermission("isIccLockEnabled");
11186
11187 // Now that all security checks passes, perform the operation as ourselves.
11188 final long identity = Binder.clearCallingIdentity();
11189 try {
11190 Phone phone = getPhone(subId);
11191 if (phone != null && phone.getIccCard() != null) {
11192 return phone.getIccCard().getIccLockEnabled();
11193 } else {
11194 return false;
11195 }
11196 } finally {
11197 Binder.restoreCallingIdentity(identity);
11198 }
11199 }
11200
11201 /**
11202 * Set the ICC pin lock enabled or disabled.
11203 *
11204 * @return an integer representing the status of IccLock enabled or disabled in the following
11205 * three cases:
11206 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11207 * successfully.
11208 * - Positive number and zero for remaining password attempts.
11209 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11210 *
11211 */
11212 @Override
11213 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11214 enforceModifyPermission();
11215
11216 Phone phone = getPhone(subId);
11217 if (phone == null) {
11218 return 0;
11219 }
11220 // Now that all security checks passes, perform the operation as ourselves.
11221 final long identity = Binder.clearCallingIdentity();
11222 try {
11223 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11224 new Pair<Boolean, String>(enabled, password), phone, null);
11225 return attemptsRemaining;
11226
11227 } catch (Exception e) {
11228 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11229 } finally {
11230 Binder.restoreCallingIdentity(identity);
11231 }
11232 return 0;
11233 }
11234
11235 /**
11236 * Change the ICC password used in ICC pin lock.
11237 *
11238 * @return an integer representing the status of IccLock changed in the following three cases:
11239 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11240 * - Positive number and zero for remaining password attempts.
11241 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11242 *
11243 */
11244 @Override
11245 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11246 enforceModifyPermission();
11247
11248 Phone phone = getPhone(subId);
11249 if (phone == null) {
11250 return 0;
11251 }
11252 // Now that all security checks passes, perform the operation as ourselves.
11253 final long identity = Binder.clearCallingIdentity();
11254 try {
11255 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11256 new Pair<String, String>(oldPassword, newPassword), phone, null);
11257 return attemptsRemaining;
11258
11259 } catch (Exception e) {
11260 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11261 } finally {
11262 Binder.restoreCallingIdentity(identity);
11263 }
11264 return 0;
11265 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011266
11267 /**
11268 * Request for receiving user activity notification
11269 */
11270 @Override
11271 public void requestUserActivityNotification() {
11272 if (!mNotifyUserActivity.get()
11273 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11274 mNotifyUserActivity.set(true);
11275 }
11276 }
11277
11278 /**
11279 * Called when userActivity is signalled in the power manager.
11280 * This is safe to call from any thread, with any window manager locks held or not.
11281 */
11282 @Override
11283 public void userActivity() {
11284 // ***************************************
11285 // * Inherited from PhoneWindowManager *
11286 // ***************************************
11287 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11288 // WITH ITS LOCKS HELD.
11289 //
11290 // This code must be VERY careful about the locks
11291 // it acquires.
11292 // In fact, the current code acquires way too many,
11293 // and probably has lurking deadlocks.
11294
11295 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11296 throw new SecurityException("Only the OS may call notifyUserActivity()");
11297 }
11298
11299 if (mNotifyUserActivity.getAndSet(false)) {
11300 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11301 USER_ACTIVITY_NOTIFICATION_DELAY);
11302 }
11303 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011304
11305 @Override
11306 public boolean canConnectTo5GInDsdsMode() {
11307 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11308 }
Jack Yud10cdd42020-09-28 20:28:01 -070011309
11310 @Override
11311 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11312 String callingFeatureId) {
11313 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11314 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11315 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11316 }
11317
11318 Phone phone = getPhone(subId);
11319 if (phone == null) {
11320 throw new RuntimeException("phone is not available");
11321 }
11322 // Now that all security checks passes, perform the operation as ourselves.
11323 final long identity = Binder.clearCallingIdentity();
11324 try {
11325 return phone.getEquivalentHomePlmns();
11326 } finally {
11327 Binder.restoreCallingIdentity(identity);
11328 }
11329 }
Daniel Bright59e67312020-11-13 11:49:37 -080011330
11331 @Override
11332 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011333 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
11334 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011335 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011336 if (radioInterfaceCapabilities == null) {
11337 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011338 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011339 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011340 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011341
Hui Wang641e81c2020-10-12 12:14:23 -070011342 @Override
11343 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11344 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011345 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11346 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11347 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11348 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11349 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070011350 if (DBG) {
11351 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11352 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11353 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11354 }
11355
11356 if (!SubscriptionManager.isValidSubscriptionId(subId)
11357 || appType < TelephonyManager.APPTYPE_UNKNOWN
11358 || appType > TelephonyManager.APPTYPE_ISIM
11359 || nafUrl == null || securityProtocol == null || callback == null) {
11360 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11361 if (callback != null) {
11362 try {
11363 callback.onAuthenticationFailure(
11364 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11365 } catch (RemoteException exception) {
11366 log("Fail to notify onAuthenticationFailure due to " + exception);
11367 }
11368 return;
11369 }
11370 }
11371
11372 final long token = Binder.clearCallingIdentity();
11373 try {
11374 getGbaManager(subId).bootstrapAuthenticationRequest(
11375 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011376 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011377 } finally {
11378 Binder.restoreCallingIdentity(token);
11379 }
11380 }
11381
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011382 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011383 * Attempts to set the radio power state for all phones for thermal reason.
11384 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011385 * requested radio power state will actually be set. See {@link
11386 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11387 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011388 * @param enable {@code true} if trying to turn radio on.
11389 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11390 * false}.
11391 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011392 private boolean setRadioPowerForThermal(boolean enable) {
11393 boolean isPhoneAvailable = false;
11394 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11395 Phone phone = PhoneFactory.getPhone(i);
11396 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011397 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011398 isPhoneAvailable = true;
11399 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011400 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011401
11402 // return true if successfully informed the phone object about the thermal radio power
11403 // request.
11404 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011405 }
11406
11407 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011408 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011409 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11410 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11411 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11412 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11413 throw new IllegalArgumentException("modem does not support data throttling");
11414 }
11415
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011416 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11417 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011418 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011419 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11420 }
11421
Sarah Chinecc78c42022-03-31 21:16:48 -070011422 setDataEnabledForReason(
11423 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011424
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011425 if (isDataThrottlingSupported) {
11426 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011427 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011428 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11429 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11430 } else if (thermalMitigationResult
11431 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011432 log("Modem likely does not support data throttling on secondary carrier. Data " +
11433 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11434 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011435 }
11436 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011437 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011438
11439 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011440 }
11441
Jack Nudelman644b91a2021-03-12 14:09:48 -080011442 private static List<String> getThermalMitigationAllowlist(Context context) {
11443 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11444 for (String pckg : context.getResources()
11445 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11446 sThermalMitigationAllowlistedPackages.add(pckg);
11447 }
11448 }
11449
11450 return sThermalMitigationAllowlistedPackages;
11451 }
11452
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011453 private boolean isAnyPhoneInEmergencyState() {
11454 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11455 if (tm.isInEmergencyCall()) {
11456 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11457 return true;
11458 }
11459 for (Phone phone : PhoneFactory.getPhones()) {
11460 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11461 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011462 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11463 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011464 return true;
11465 }
11466 }
11467
11468 return false;
11469 }
11470
Jack Nudelman644b91a2021-03-12 14:09:48 -080011471 /**
11472 * Used by shell commands to add an authorized package name for thermal mitigation.
11473 * @param packageName name of package to be allowlisted
11474 * @param context
11475 */
11476 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11477 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11478 sThermalMitigationAllowlistedPackages.add(packageName);
11479 }
11480
11481 /**
11482 * Used by shell commands to remove an authorized package name for thermal mitigation.
11483 * @param packageName name of package to remove from allowlist
11484 * @param context
11485 */
11486 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11487 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11488 sThermalMitigationAllowlistedPackages.remove(packageName);
11489 }
11490
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011491 /**
11492 * Thermal mitigation request to control functionalities at modem.
11493 *
11494 * @param subId the id of the subscription.
11495 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011496 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011497 *
11498 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11499 */
11500 @Override
11501 @ThermalMitigationResult
11502 public int sendThermalMitigationRequest(
11503 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011504 ThermalMitigationRequest thermalMitigationRequest,
11505 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011506 enforceModifyPermission();
11507
Jack Nudelman644b91a2021-03-12 14:09:48 -080011508 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11509 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11510 .contains(callingPackage)) {
11511 throw new SecurityException("Calling package must be configured in the device config. "
11512 + "calling package: " + callingPackage);
11513 }
11514
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011515 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11516 final long identity = Binder.clearCallingIdentity();
11517
11518 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11519 try {
11520 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11521 switch (thermalMitigationAction) {
11522 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11523 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011524 handleDataThrottlingRequest(subId,
11525 thermalMitigationRequest.getDataThrottlingRequest(),
11526 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011527 break;
11528 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11529 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11530 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11531 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11532 }
11533
11534 // Ensure that radio is on. If not able to power on due to phone being
11535 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011536 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011537 thermalMitigationResult =
11538 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11539 break;
11540 }
11541
11542 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011543 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011544 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11545 break;
11546 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11547 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11548 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11549 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11550 }
11551
11552 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11553 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011554 Phone phone = getPhone(subId);
11555 if (phone == null) {
11556 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011557 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011558 break;
11559 }
11560
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011561 TelephonyConnectionService service =
11562 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011563 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011564 Log.e(LOG_TAG, "An emergency call is pending");
11565 thermalMitigationResult =
11566 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11567 break;
11568 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011569 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011570 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011571 break;
11572 }
11573 } else {
11574 thermalMitigationResult =
11575 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11576 break;
11577 }
11578
11579 // Turn radio off. If not able to power off due to phone being unavailable,
11580 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011581 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011582 thermalMitigationResult =
11583 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11584 break;
11585 }
11586 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011587 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011588 break;
11589 default:
11590 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11591 + "not exist. Requested action: " + thermalMitigationAction);
11592 }
11593 } catch (IllegalArgumentException e) {
11594 throw e;
11595 } catch (Exception e) {
11596 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11597 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11598 } finally {
11599 Binder.restoreCallingIdentity(identity);
11600 }
11601
11602 if (DBG) {
11603 log("thermalMitigationRequest returning with thermalMitigationResult: "
11604 + thermalMitigationResult);
11605 }
11606
11607 return thermalMitigationResult;
11608 }
Hui Wang641e81c2020-10-12 12:14:23 -070011609
11610 /**
11611 * Set the GbaService Package Name that Telephony will bind to.
11612 *
11613 * @param subId The sim that the GbaService is associated with.
11614 * @param packageName The name of the package to be replaced with.
11615 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11616 */
11617 @Override
11618 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11619 enforceModifyPermission();
11620
11621 final long identity = Binder.clearCallingIdentity();
11622 try {
11623 return getGbaManager(subId).overrideServicePackage(packageName);
11624 } finally {
11625 Binder.restoreCallingIdentity(identity);
11626 }
11627 }
11628
11629 /**
11630 * Return the package name of the currently bound GbaService.
11631 *
11632 * @param subId The sim that the GbaService is associated with.
11633 * @return the package name of the GbaService configuration, null if GBA is not supported.
11634 */
11635 @Override
11636 public String getBoundGbaService(int subId) {
11637 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11638
11639 final long identity = Binder.clearCallingIdentity();
11640 try {
11641 return getGbaManager(subId).getServicePackage();
11642 } finally {
11643 Binder.restoreCallingIdentity(identity);
11644 }
11645 }
11646
11647 /**
11648 * Set the release time for telephony to unbind GbaService.
11649 *
11650 * @param subId The sim that the GbaService is associated with.
11651 * @param interval The release time to unbind GbaService by millisecond.
11652 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11653 */
11654 @Override
11655 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11656 enforceModifyPermission();
11657
11658 final long identity = Binder.clearCallingIdentity();
11659 try {
11660 return getGbaManager(subId).overrideReleaseTime(interval);
11661 } finally {
11662 Binder.restoreCallingIdentity(identity);
11663 }
11664 }
11665
11666 /**
11667 * Return the release time for telephony to unbind GbaService.
11668 *
11669 * @param subId The sim that the GbaService is associated with.
11670 * @return The release time to unbind GbaService by millisecond.
11671 */
11672 @Override
11673 public int getGbaReleaseTime(int subId) {
11674 enforceReadPrivilegedPermission("getGbaReleaseTime");
11675
11676 final long identity = Binder.clearCallingIdentity();
11677 try {
11678 return getGbaManager(subId).getReleaseTime();
11679 } finally {
11680 Binder.restoreCallingIdentity(identity);
11681 }
11682 }
11683
11684 private GbaManager getGbaManager(int subId) {
11685 GbaManager instance = GbaManager.getInstance(subId);
11686 if (instance == null) {
11687 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11688 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11689 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11690 }
11691 return instance;
11692 }
Hui Wang761a6682020-10-31 05:12:53 +000011693
11694 /**
11695 * indicate whether the device and the carrier can support
11696 * RCS VoLTE single registration.
11697 */
11698 @Override
11699 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011700 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11701 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11702 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11703 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011704
11705 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11706 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11707 }
11708
11709 final long identity = Binder.clearCallingIdentity();
11710 try {
11711 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11712 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011713 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11714 if (isCapable != null) {
11715 return isCapable;
11716 }
Hui Wang761a6682020-10-31 05:12:53 +000011717 }
Hui Wang67af90e2021-06-04 16:57:15 -070011718 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11719 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011720 } finally {
11721 Binder.restoreCallingIdentity(identity);
11722 }
11723 }
11724
11725 /**
11726 * Register RCS provisioning callback.
11727 */
11728 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011729 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011730 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011731 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011732 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011733 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11734 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011735
11736 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11737 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11738 }
11739 if (!isImsAvailableOnDevice()) {
11740 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11741 "IMS not available on device.");
11742 }
11743
11744 final long identity = Binder.clearCallingIdentity();
11745 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011746 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011747 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011748 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11749 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011750 }
Hui Wang761a6682020-10-31 05:12:53 +000011751 } finally {
11752 Binder.restoreCallingIdentity(identity);
11753 }
11754 }
11755
11756 /**
11757 * Unregister RCS provisioning callback.
11758 */
11759 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011760 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011761 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011762 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011763 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011764 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11765 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011766
11767 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11768 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11769 }
11770 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011771 // operation failed silently
11772 Rlog.w(LOG_TAG, "IMS not available on device.");
11773 return;
Hui Wang761a6682020-10-31 05:12:53 +000011774 }
11775
11776 final long identity = Binder.clearCallingIdentity();
11777 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011778 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011779 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011780 } finally {
11781 Binder.restoreCallingIdentity(identity);
11782 }
11783 }
11784
11785 /**
11786 * trigger RCS reconfiguration.
11787 */
11788 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011789 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11790 "triggerRcsReconfiguration",
11791 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011792
11793 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11794 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11795 }
11796 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011797 // ProvisioningManager can not handle ServiceSpecificException.
11798 // Throw the IllegalStateException and annotate ProvisioningManager.
11799 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000011800 }
11801
11802 final long identity = Binder.clearCallingIdentity();
11803 try {
11804 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11805 } finally {
11806 Binder.restoreCallingIdentity(identity);
11807 }
11808 }
11809
11810 /**
11811 * Provide the client configuration parameters of the RCS application.
11812 */
11813 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011814 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11815 "setRcsClientConfiguration",
11816 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011817
11818 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11819 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11820 }
11821 if (!isImsAvailableOnDevice()) {
11822 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11823 "IMS not available on device.");
11824 }
11825
11826 final long identity = Binder.clearCallingIdentity();
11827
11828 try {
11829 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11830 if (configBinder == null) {
11831 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011832 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11833 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011834 } else {
11835 configBinder.setRcsClientConfiguration(rcc);
11836 }
joonhunshin3e154242021-09-17 06:33:39 +000011837
11838 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11839 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011840 } catch (RemoteException e) {
11841 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011842 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11843 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011844 } finally {
11845 Binder.restoreCallingIdentity(identity);
11846 }
11847 }
11848
11849 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011850 * Enables or disables the test mode for RCS VoLTE single registration.
11851 */
11852 @Override
11853 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11854 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11855 "setRcsSingleRegistrationTestModeEnabled");
11856
11857 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11858 }
11859
11860 /**
11861 * Gets the test mode for RCS VoLTE single registration.
11862 */
11863 @Override
11864 public boolean getRcsSingleRegistrationTestModeEnabled() {
11865 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11866 "getRcsSingleRegistrationTestModeEnabled");
11867
11868 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11869 }
11870
11871 /**
Hui Wang761a6682020-10-31 05:12:53 +000011872 * Overrides the config of RCS VoLTE single registration enabled for the device.
11873 */
11874 @Override
11875 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11876 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11877 "setDeviceSingleRegistrationEnabledOverride");
11878 enforceModifyPermission();
11879
11880 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11881 : Boolean.parseBoolean(enabledStr);
11882 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011883 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011884 }
11885
11886 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011887 * Sends a device to device communication message. Only usable via shell.
11888 * @param message message to send.
11889 * @param value message value.
11890 */
11891 @Override
11892 public void sendDeviceToDeviceMessage(int message, int value) {
11893 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011894 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011895 enforceModifyPermission();
11896
11897 final long identity = Binder.clearCallingIdentity();
11898 try {
11899 TelephonyConnectionService service =
11900 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11901 if (service == null) {
11902 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11903 return;
11904 }
11905 service.sendTestDeviceToDeviceMessage(message, value);
11906 } finally {
11907 Binder.restoreCallingIdentity(identity);
11908 }
11909 }
11910
Tyler Gunnbabbda02021-02-10 11:05:02 -080011911 /**
11912 * Sets the specified device to device transport active.
11913 * @param transport The transport to set active.
11914 */
11915 @Override
11916 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11917 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11918 "setActiveDeviceToDeviceTransport");
11919 enforceModifyPermission();
11920
11921 final long identity = Binder.clearCallingIdentity();
11922 try {
11923 TelephonyConnectionService service =
11924 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11925 if (service == null) {
11926 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11927 return;
11928 }
11929 service.setActiveDeviceToDeviceTransport(transport);
11930 } finally {
11931 Binder.restoreCallingIdentity(identity);
11932 }
11933 }
Tyler Gunn92479152021-01-20 16:30:10 -080011934
Tyler Gunnd4339262021-05-03 14:46:49 -070011935 @Override
11936 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11937 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11938 "setDeviceToDeviceForceEnabled");
11939
11940 final long identity = Binder.clearCallingIdentity();
11941 try {
11942 Arrays.stream(PhoneFactory.getPhones()).forEach(
11943 p -> {
11944 Phone thePhone = p.getImsPhone();
11945 if (thePhone != null && thePhone instanceof ImsPhone) {
11946 ImsPhone imsPhone = (ImsPhone) thePhone;
11947 CallTracker tracker = imsPhone.getCallTracker();
11948 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11949 ImsPhoneCallTracker imsPhoneCallTracker =
11950 (ImsPhoneCallTracker) tracker;
11951 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11952 }
11953 }
11954 }
11955 );
11956 } finally {
11957 Binder.restoreCallingIdentity(identity);
11958 }
11959 }
11960
Tyler Gunn92479152021-01-20 16:30:10 -080011961 /**
Hui Wang761a6682020-10-31 05:12:53 +000011962 * Gets the config of RCS VoLTE single registration enabled for the device.
11963 */
11964 @Override
11965 public boolean getDeviceSingleRegistrationEnabled() {
11966 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11967 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11968 }
11969
11970 /**
11971 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11972 */
11973 @Override
11974 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11975 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11976 "setCarrierSingleRegistrationEnabledOverride");
11977 enforceModifyPermission();
11978
11979 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11980 : Boolean.parseBoolean(enabledStr);
11981 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11982 subId, enabled);
11983 }
11984
11985 /**
11986 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11987 */
11988 @Override
11989 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11990 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11991 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11992 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011993
11994 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011995 * Overrides the ims feature validation result
11996 */
11997 @Override
11998 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11999 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12000 "setImsFeatureValidationOverride");
12001
12002 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12003 : Boolean.parseBoolean(enabledStr);
12004 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
12005 subId, enabled);
12006 }
12007
12008 /**
12009 * Gets the ims feature validation override value
12010 */
12011 @Override
12012 public boolean getImsFeatureValidationOverride(int subId) {
12013 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12014 "getImsFeatureValidationOverride");
12015 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
12016 }
12017
12018 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012019 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12020 * their mobile plan.
12021 */
12022 @Override
12023 public String getMobileProvisioningUrl() {
12024 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12025 final long identity = Binder.clearCallingIdentity();
12026 try {
12027 return getDefaultPhone().getMobileProvisioningUrl();
12028 } finally {
12029 Binder.restoreCallingIdentity(identity);
12030 }
12031 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012032
James.cf Linbcdf8b32021-01-14 16:44:13 +080012033 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012034 * Get the EAB contact from the EAB database.
12035 */
12036 @Override
12037 public String getContactFromEab(String contact) {
12038 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12039 enforceModifyPermission();
12040 final long identity = Binder.clearCallingIdentity();
12041 try {
12042 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12043 } finally {
12044 Binder.restoreCallingIdentity(identity);
12045 }
12046 }
12047
12048 /**
Calvin Pana1434322021-07-01 19:27:01 +080012049 * Get the EAB capability from the EAB database.
12050 */
12051 @Override
12052 public String getCapabilityFromEab(String contact) {
12053 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12054 enforceModifyPermission();
12055 final long identity = Binder.clearCallingIdentity();
12056 try {
12057 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12058 } finally {
12059 Binder.restoreCallingIdentity(identity);
12060 }
12061 }
12062
12063 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012064 * Remove the EAB contacts from the EAB database.
12065 */
12066 @Override
12067 public int removeContactFromEab(int subId, String contacts) {
12068 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12069 enforceModifyPermission();
12070 final long identity = Binder.clearCallingIdentity();
12071 try {
12072 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12073 } finally {
12074 Binder.restoreCallingIdentity(identity);
12075 }
12076 }
12077
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012078 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012079 public boolean getDeviceUceEnabled() {
12080 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12081 final long identity = Binder.clearCallingIdentity();
12082 try {
12083 return mApp.getDeviceUceEnabled();
12084 } finally {
12085 Binder.restoreCallingIdentity(identity);
12086 }
12087 }
12088
12089 @Override
12090 public void setDeviceUceEnabled(boolean isEnabled) {
12091 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12092 final long identity = Binder.clearCallingIdentity();
12093 try {
12094 mApp.setDeviceUceEnabled(isEnabled);
12095 } finally {
12096 Binder.restoreCallingIdentity(identity);
12097 }
12098 }
12099
Brad Ebinger14d467f2021-02-12 06:18:28 +000012100 /**
12101 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12102 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12103 */
12104 // Used for SHELL command only right now.
12105 @Override
12106 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12107 List<String> featureTags) {
12108 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12109 "addUceRegistrationOverrideShell");
12110 final long identity = Binder.clearCallingIdentity();
12111 try {
12112 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12113 new ArraySet<>(featureTags));
12114 } catch (ImsException e) {
12115 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12116 } finally {
12117 Binder.restoreCallingIdentity(identity);
12118 }
12119 }
12120
12121 /**
12122 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12123 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12124 */
12125 // Used for SHELL command only right now.
12126 @Override
12127 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12128 List<String> featureTags) {
12129 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12130 "removeUceRegistrationOverrideShell");
12131 final long identity = Binder.clearCallingIdentity();
12132 try {
12133 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12134 new ArraySet<>(featureTags));
12135 } catch (ImsException e) {
12136 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12137 } finally {
12138 Binder.restoreCallingIdentity(identity);
12139 }
12140 }
12141
12142 /**
12143 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12144 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12145 */
12146 // Used for SHELL command only right now.
12147 @Override
12148 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12149 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12150 "clearUceRegistrationOverrideShell");
12151 final long identity = Binder.clearCallingIdentity();
12152 try {
12153 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12154 } catch (ImsException e) {
12155 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12156 } finally {
12157 Binder.restoreCallingIdentity(identity);
12158 }
12159 }
12160
12161 /**
12162 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12163 */
12164 // Used for SHELL command only right now.
12165 @Override
12166 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12167 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12168 "getLatestRcsContactUceCapabilityShell");
12169 final long identity = Binder.clearCallingIdentity();
12170 try {
12171 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12172 } catch (ImsException e) {
12173 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12174 } finally {
12175 Binder.restoreCallingIdentity(identity);
12176 }
12177 }
12178
12179 /**
12180 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12181 * device does not have an active PUBLISH.
12182 */
12183 // Used for SHELL command only right now.
12184 @Override
12185 public String getLastUcePidfXmlShell(int subId) {
12186 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12187 final long identity = Binder.clearCallingIdentity();
12188 try {
12189 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12190 } catch (ImsException e) {
12191 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12192 } finally {
12193 Binder.restoreCallingIdentity(identity);
12194 }
12195 }
12196
James.cf Line8713a42021-04-29 16:04:26 +080012197 /**
12198 * Remove UCE requests cannot be sent to the network status.
12199 */
12200 // Used for SHELL command only right now.
12201 @Override
12202 public boolean removeUceRequestDisallowedStatus(int subId) {
12203 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12204 final long identity = Binder.clearCallingIdentity();
12205 try {
12206 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12207 } catch (ImsException e) {
12208 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12209 } finally {
12210 Binder.restoreCallingIdentity(identity);
12211 }
12212 }
12213
James.cf Lin18bb9002021-05-25 01:37:38 +080012214 /**
12215 * Remove UCE requests cannot be sent to the network status.
12216 */
12217 // Used for SHELL command only.
12218 @Override
12219 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12220 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12221 final long identity = Binder.clearCallingIdentity();
12222 try {
12223 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12224 } catch (ImsException e) {
12225 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12226 } finally {
12227 Binder.restoreCallingIdentity(identity);
12228 }
12229 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012230
James.cf Lin4b784aa2021-01-31 03:25:15 +080012231 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012232 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12233 String callingPackage) {
12234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12235 mApp, subId, "setSignalStrengthUpdateRequest");
12236
12237 final int callingUid = Binder.getCallingUid();
12238 // Verify that tha callingPackage belongs to the calling UID
12239 mApp.getSystemService(AppOpsManager.class)
12240 .checkPackage(callingUid, callingPackage);
12241
Rambo Wang3607f502021-02-01 21:51:40 -080012242 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012243
12244 final long identity = Binder.clearCallingIdentity();
12245 try {
12246 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12247 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12248
12249 if (result instanceof IllegalStateException) {
12250 throw (IllegalStateException) result;
12251 }
12252 } finally {
12253 Binder.restoreCallingIdentity(identity);
12254 }
12255 }
12256
12257 @Override
12258 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12259 String callingPackage) {
12260 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12261 mApp, subId, "clearSignalStrengthUpdateRequest");
12262
12263 final int callingUid = Binder.getCallingUid();
12264 // Verify that tha callingPackage belongs to the calling UID
12265 mApp.getSystemService(AppOpsManager.class)
12266 .checkPackage(callingUid, callingPackage);
12267
12268 final long identity = Binder.clearCallingIdentity();
12269 try {
12270 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12271 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12272
12273 if (result instanceof IllegalStateException) {
12274 throw (IllegalStateException) result;
12275 }
12276 } finally {
12277 Binder.restoreCallingIdentity(identity);
12278 }
12279 }
12280
Rambo Wang3607f502021-02-01 21:51:40 -080012281 private static void validateSignalStrengthUpdateRequest(Context context,
12282 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012283 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12284 // phone/system process do not have further restriction on request
12285 return;
12286 }
12287
12288 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012289 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012290 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012291 context.enforceCallingOrSelfPermission(
12292 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12293 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012294 }
12295
12296 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012297 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012298 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012299 || info.isEnabled()) {
12300 throw new IllegalArgumentException(
12301 "Only system can set hide fields in SignalThresholdInfo");
12302 }
12303
12304 // Thresholds length for each RAN need in range. This has been validated in
12305 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12306 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12307 final int[] thresholds = info.getThresholds();
12308 Objects.requireNonNull(thresholds);
12309 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12310 || thresholds.length
12311 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12312 throw new IllegalArgumentException(
12313 "thresholds length is out of range: " + thresholds.length);
12314 }
12315 }
12316 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012317
12318 /**
12319 * Gets the current phone capability.
12320 *
12321 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12322 * @return the PhoneCapability which describes the data connection capability of modem.
12323 * It's used to evaluate possible phone config change, for example from single
12324 * SIM device to multi-SIM device.
12325 */
12326 @Override
12327 public PhoneCapability getPhoneCapability() {
12328 enforceReadPrivilegedPermission("getPhoneCapability");
12329 final long identity = Binder.clearCallingIdentity();
12330 try {
12331 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12332 } finally {
12333 Binder.restoreCallingIdentity(identity);
12334 }
12335 }
Michele Berionne5e411512020-11-13 02:36:59 +000012336
12337 /**
12338 * Prepare TelephonyManager for an unattended reboot. The reboot is
12339 * required to be done shortly after the API is invoked.
12340 */
12341 @Override
12342 @TelephonyManager.PrepareUnattendedRebootResult
12343 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012344 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012345 enforceRebootPermission();
12346
12347 final long identity = Binder.clearCallingIdentity();
12348 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012349 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012350 } finally {
12351 Binder.restoreCallingIdentity(identity);
12352 }
12353 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012354
12355 /**
12356 * Request to get the current slicing configuration including URSP rules and
12357 * NSSAIs (configured, allowed and rejected).
12358 *
12359 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12360 */
12361 @Override
12362 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012363 TelephonyPermissions
12364 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12365 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012366
12367 final long identity = Binder.clearCallingIdentity();
12368 try {
12369 Phone phone = getDefaultPhone();
12370 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12371 } finally {
12372 Binder.restoreCallingIdentity(identity);
12373 }
12374 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012375
12376 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012377 * Check whether the given premium capability is available for purchase from the carrier.
12378 *
12379 * @param capability The premium capability to check.
12380 * @param subId The subId to check the premium capability for.
12381 *
12382 * @return Whether the given premium capability is available to purchase.
12383 */
12384 @Override
12385 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12386 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12387 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12388 log("Premium capability "
12389 + TelephonyManager.convertPremiumCapabilityToString(capability)
12390 + " is not available for purchase due to missing permissions.");
12391 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12392 + "permission READ_BASIC_PHONE_STATE.");
12393 }
12394
12395 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012396 if (phone == null) {
12397 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12398 return false;
12399 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012400 final long identity = Binder.clearCallingIdentity();
12401 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070012402 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012403 .isPremiumCapabilityAvailableForPurchase(capability);
12404 } finally {
12405 Binder.restoreCallingIdentity(identity);
12406 }
12407 }
12408
12409 /**
12410 * Purchase the given premium capability from the carrier.
12411 *
12412 * @param capability The premium capability to purchase.
12413 * @param callback The result of the purchase request.
12414 * @param subId The subId to purchase the premium capability for.
12415 */
12416 @Override
12417 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12418 log("purchasePremiumCapability: capability="
12419 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12420 + getCurrentPackageName());
12421
12422 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12423 mApp, "purchasePremiumCapability")) {
12424 log("purchasePremiumCapability "
12425 + TelephonyManager.convertPremiumCapabilityToString(capability)
12426 + " failed due to missing permissions.");
12427 throw new SecurityException("purchasePremiumCapability requires permission "
12428 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012429 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12430 mApp, "purchasePremiumCapability")) {
12431 log("purchasePremiumCapability "
12432 + TelephonyManager.convertPremiumCapabilityToString(capability)
12433 + " failed due to missing permissions.");
12434 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012435 }
12436
12437 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012438 if (phone == null) {
12439 try {
12440 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12441 callback.accept(result);
12442 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12443 } catch (RemoteException e) {
12444 String logStr = "Purchase premium capability "
12445 + TelephonyManager.convertPremiumCapabilityToString(capability)
12446 + " failed due to RemoteException handling null phone: " + e;
12447 if (DBG) log(logStr);
12448 AnomalyReporter.reportAnomaly(
12449 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12450 }
12451 return;
12452 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012453
12454 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012455 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012456 callingProcess = mApp.getPackageManager().getApplicationInfo(
12457 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012458 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012459 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012460 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012461
12462 boolean isVisible = false;
12463 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12464 if (am != null) {
12465 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12466 if (processes != null) {
12467 for (ActivityManager.RunningAppProcessInfo process : processes) {
12468 log("purchasePremiumCapability: process " + process.processName
12469 + "has importance " + process.importance);
12470 if (process.processName.equals(callingProcess) && process.importance
12471 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12472 isVisible = true;
12473 break;
12474 }
12475 }
12476 }
12477 }
12478
12479 if (!isVisible) {
12480 try {
12481 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12482 callback.accept(result);
12483 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12484 } catch (RemoteException e) {
12485 String logStr = "Purchase premium capability "
12486 + TelephonyManager.convertPremiumCapabilityToString(capability)
12487 + " failed due to RemoteException handling background application: " + e;
12488 if (DBG) log(logStr);
12489 AnomalyReporter.reportAnomaly(
12490 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12491 }
12492 return;
12493 }
12494
Sarah Chin71b3a852022-09-28 15:54:19 -070012495 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012496 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012497 }
12498
12499 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012500 * Register an IMS connection state callback
12501 */
12502 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012503 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12504 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012505 if (feature == ImsFeature.FEATURE_MMTEL) {
12506 // ImsMmTelManager
12507 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12508 TelephonyPermissions
12509 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12510 mApp, subId, "registerImsStateCallback");
12511 } else if (feature == ImsFeature.FEATURE_RCS) {
12512 // ImsRcsManager or SipDelegateManager
12513 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12514 Binder.getCallingUid(), "registerImsStateCallback",
12515 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12516 Manifest.permission.READ_PRECISE_PHONE_STATE,
12517 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12518 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12519 }
12520
12521 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12522 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12523 "IMS not available on device.");
12524 }
12525
12526 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12527 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12528 }
12529
12530 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12531 if (controller == null) {
12532 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12533 "IMS not available on device.");
12534 }
12535
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012536 if (callingPackage == null) {
12537 callingPackage = getCurrentPackageName();
12538 }
12539
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012540 final long token = Binder.clearCallingIdentity();
12541 try {
12542 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012543 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012544 } catch (ImsException e) {
12545 throw new ServiceSpecificException(e.getCode());
12546 } finally {
12547 Binder.restoreCallingIdentity(token);
12548 }
12549 }
12550
12551 /**
12552 * Unregister an IMS connection state callback
12553 */
12554 @Override
12555 public void unregisterImsStateCallback(IImsStateCallback cb) {
12556 final long token = Binder.clearCallingIdentity();
12557 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12558 if (controller == null) {
12559 return;
12560 }
12561 try {
12562 controller.unregisterImsStateCallback(cb);
12563 } finally {
12564 Binder.restoreCallingIdentity(token);
12565 }
12566 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012567
12568 /**
12569 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12570 *
12571 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
12572 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
12573 * SecurityException.
12574 * If there is current registered network this value will be same as the registered cell
12575 * identity. If the device goes out of service the previous cell identity is cached and
12576 * will be returned. If the cache age of the Cell identity is more than 24 hours
12577 * it will be cleared and null will be returned.
12578 *
12579 */
12580 @Override
12581 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12582 String callingFeatureId) {
12583 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12584 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12585 LocationAccessPolicy.checkLocationPermission(mApp,
12586 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12587 .setCallingPackage(callingPackage)
12588 .setCallingFeatureId(callingFeatureId)
12589 .setCallingPid(Binder.getCallingPid())
12590 .setCallingUid(Binder.getCallingUid())
12591 .setMethod("getLastKnownCellIdentity")
12592 .setLogAsInfo(true)
12593 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12594 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12595 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12596 .build());
12597
12598 boolean hasFinePermission =
12599 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12600 if (!hasFinePermission
12601 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12602 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012603 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012604 }
12605
12606 final long identity = Binder.clearCallingIdentity();
12607 try {
12608 Phone phone = getPhone(subId);
12609 if (phone == null) return null;
12610 ServiceStateTracker sst = phone.getServiceStateTracker();
12611 if (sst == null) return null;
12612 return sst.getLastKnownCellIdentity();
12613 } finally {
12614 Binder.restoreCallingIdentity(identity);
12615 }
12616 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012617
jimsun3b9ccac2021-10-26 15:01:23 +080012618 /**
12619 * Sets the modem service class Name that Telephony will bind to.
12620 *
12621 * @param serviceName The class name of the modem service.
12622 * @return true if the operation is succeed, otherwise false.
12623 */
12624 public boolean setModemService(String serviceName) {
12625 Log.d(LOG_TAG, "setModemService - " + serviceName);
12626 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012628 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12629 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012630 return mPhoneConfigurationManager.setModemService(serviceName);
12631 }
12632
12633 /**
12634 * Return the class name of the currently bounded modem service.
12635 *
12636 * @return the class name of the modem service.
12637 */
12638 public String getModemService() {
12639 String result;
12640 Log.d(LOG_TAG, "getModemService");
12641 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12642 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012643 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012644 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12645 "getModemService");
12646 result = mPhoneConfigurationManager.getModemService();
12647 Log.d(LOG_TAG, "result = " + result);
12648 return result;
12649 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012650
12651 @Override
12652 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12653 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12654 mApp.enforceCallingOrSelfPermission(
12655 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12656 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12657
12658 final long identity = Binder.clearCallingIdentity();
12659 try {
12660 Phone phone = getPhone(subId);
12661 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012662 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12663 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012664 phone.setVoiceServiceStateOverride(hasService);
12665 } finally {
12666 Binder.restoreCallingIdentity(identity);
12667 }
12668 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012669
12670 /**
12671 * set removable eSIM as default eUICC.
12672 *
12673 * @hide
12674 */
12675 @Override
12676 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12677 enforceModifyPermission();
12678 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12679
12680 final long identity = Binder.clearCallingIdentity();
12681 try {
12682 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12683 } finally {
12684 Binder.restoreCallingIdentity(identity);
12685 }
12686 }
12687
12688 /**
12689 * Returns whether the removable eSIM is default eUICC or not.
12690 *
12691 * @hide
12692 */
12693 @Override
12694 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12695 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12696 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12697
12698 final long identity = Binder.clearCallingIdentity();
12699 try {
12700 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12701 } finally {
12702 Binder.restoreCallingIdentity(identity);
12703 }
12704 }
12705
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012706 /**
12707 * Get the component name of the default app to direct respond-via-message intent for the
12708 * user associated with this subscription, update the cache if there is no respond-via-message
12709 * application currently configured for this user.
12710 * @return component name of the app and class to direct Respond Via Message intent to, or
12711 * {@code null} if the functionality is not supported.
12712 * @hide
12713 */
12714 @Override
12715 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12716 boolean updateIfNeeded) {
12717 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012718
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012719 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12720
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012721 UserHandle userHandle = null;
12722 final long identity = Binder.clearCallingIdentity();
12723 try {
12724 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12725 } finally {
12726 Binder.restoreCallingIdentity(identity);
12727 }
12728 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12729 updateIfNeeded, userHandle);
12730 }
Jack Yuf5badd92022-12-08 00:50:53 -080012731
12732 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012733 * Set whether the device is able to connect with null ciphering or integrity
12734 * algorithms. This is a global setting and will apply to all active subscriptions
12735 * and all new subscriptions after this.
12736 *
12737 * @param enabled when true, null cipher and integrity algorithms are allowed.
12738 * @hide
12739 */
12740 @Override
12741 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12742 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12743 enforceModifyPermission();
12744 checkForNullCipherAndIntegritySupport();
12745
12746 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12747 // for listening to these preference changes and applying them immediately.
12748 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12749 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12750 editor.apply();
12751
12752 for (Phone phone: PhoneFactory.getPhones()) {
12753 phone.handleNullCipherEnabledChange();
12754 }
12755 }
12756
12757
12758 /**
12759 * Get whether the device is able to connect with null ciphering or integrity
12760 * algorithms. Note that this retrieves the phone-global preference and not
12761 * the state of the radio.
12762 *
12763 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12764 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12765 * version for this feature.
12766 * @hide
12767 */
12768 @Override
12769 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12770 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12771 enforceReadPermission();
12772 checkForNullCipherAndIntegritySupport();
12773 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12774 }
12775
12776 private void checkForNullCipherAndIntegritySupport() {
12777 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12778 throw new UnsupportedOperationException(
12779 "Null cipher and integrity operations require HAL 2.1 or above");
12780 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012781 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12782 throw new UnsupportedOperationException(
12783 "Null cipher and integrity operations unsupported by modem");
12784 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012785 }
12786
12787 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012788 * Get the SIM state for the slot index.
12789 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12790 *
12791 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12792 */
12793 @Override
12794 @SimState
12795 public int getSimStateForSlotIndex(int slotIndex) {
12796 IccCardConstants.State simState;
12797 if (slotIndex < 0) {
12798 simState = IccCardConstants.State.UNKNOWN;
12799 } else {
12800 Phone phone = null;
12801 try {
12802 phone = PhoneFactory.getPhone(slotIndex);
12803 } catch (IllegalStateException e) {
12804 // ignore
12805 }
12806 if (phone == null) {
12807 simState = IccCardConstants.State.UNKNOWN;
12808 } else {
12809 IccCard icc = phone.getIccCard();
12810 if (icc == null) {
12811 simState = IccCardConstants.State.UNKNOWN;
12812 } else {
12813 simState = icc.getState();
12814 }
12815 }
12816 }
12817 return simState.ordinal();
12818 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012819
12820 /**
12821 * Get current cell broadcast ranges.
12822 */
12823 @Override
12824 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12825 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12826 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12827 "getCellBroadcastIdRanges");
12828 final long identity = Binder.clearCallingIdentity();
12829 try {
12830 return getPhone(subId).getCellBroadcastIdRanges();
12831 } finally {
12832 Binder.restoreCallingIdentity(identity);
12833 }
12834 }
12835
12836 /**
12837 * Set reception of cell broadcast messages with the list of the given ranges
12838 *
12839 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12840 */
12841 @Override
12842 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12843 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12844 @Nullable IIntegerConsumer callback) {
12845 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12846 "setCellBroadcastIdRanges");
12847 final long identity = Binder.clearCallingIdentity();
12848 try {
12849 Phone phone = getPhoneFromSubId(subId);
12850 if (DBG) {
12851 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12852 }
12853 phone.setCellBroadcastIdRanges(ranges, result -> {
12854 if (callback != null) {
12855 try {
12856 callback.accept(result);
12857 } catch (RemoteException e) {
12858 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12859 }
12860 }
12861 });
12862 } finally {
12863 Binder.restoreCallingIdentity(identity);
12864 }
12865 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012866
12867 /**
12868 * Returns whether the device supports the domain selection service.
12869 *
12870 * @return {@code true} if the device supports the domain selection service.
12871 */
12872 @Override
12873 public boolean isDomainSelectionSupported() {
12874 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12875 "isDomainSelectionSupported");
12876
12877 final long identity = Binder.clearCallingIdentity();
12878 try {
12879 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12880 } finally {
12881 Binder.restoreCallingIdentity(identity);
12882 }
12883 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012884
12885 /**
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012886 * Request to enable or disable the satellite modem. If the satellite modem is enabled, this
12887 * will also disable the cellular modem, and if the satellite modem is disabled, this will also
12888 * re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012889 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012890 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012891 * @param enable {@code true} to enable the satellite modem and {@code false} to disable.
12892 * @param callback The callback to get the error code of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012893 *
12894 * @throws SecurityException if the caller doesn't have the required permission.
12895 */
12896 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012897 public void requestSatelliteEnabled(
12898 int subId, boolean enable, @NonNull IIntegerConsumer callback) {
12899 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012900 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012901 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012902 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12903 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012904 }
Sarah Chin503828c2023-02-01 23:54:20 -080012905
12906 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012907 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012908 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
12909 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012910 }
12911
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012912 Phone phone = getPhoneOrDefault(validSubId, "requestSatelliteEnabled");
Sarah Chin503828c2023-02-01 23:54:20 -080012913 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012914 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
12915 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012916 }
12917
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012918 Pair<Boolean, Consumer<Integer>> arg = new Pair<>(enable, result);
12919 sendRequestAsync(CMD_SET_SATELLITE_ENABLED, arg, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080012920 }
12921
12922 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012923 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012924 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012925 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012926 * @param result The result receiver that returns whether the satellite modem is enabled
12927 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012928 *
12929 * @throws SecurityException if the caller doesn't have the required permission.
12930 */
12931 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012932 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12933 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012934 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012935 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
12936 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012937 }
Sarah Chin503828c2023-02-01 23:54:20 -080012938
12939 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012940 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012941 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
12942 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012943 }
12944
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012945 Phone phone = getPhoneOrDefault(validSubId, "requestIsSatelliteEnabled");
Sarah Chin503828c2023-02-01 23:54:20 -080012946 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012947 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12948 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012949 }
12950
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012951 sendRequest(CMD_IS_SATELLITE_ENABLED, result, subId);
Sarah Chin503828c2023-02-01 23:54:20 -080012952 }
12953
12954 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012955 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012956 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012957 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012958 * @param result The result receiver that returns whether the satellite service is supported on
12959 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012960 */
12961 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012962 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012963 synchronized (mIsSatelliteSupportedLock) {
12964 if (mIsSatelliteSupported != null) {
12965 /* We have already successfully queried the satellite modem. */
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012966 Bundle bundle = new Bundle();
12967 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, mIsSatelliteSupported);
12968 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, bundle);
12969 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012970 }
12971 }
Sarah Chin503828c2023-02-01 23:54:20 -080012972
12973 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012974 Phone phone = getPhoneOrDefault(validSubId, "requestIsSatelliteSupported");
Sarah Chin503828c2023-02-01 23:54:20 -080012975 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012976 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12977 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012978 }
12979
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012980 sendRequestAsync(CMD_IS_SATELLITE_SUPPORTED, result, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080012981 }
12982
12983 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012984 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012985 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012986 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012987 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12988 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012989 *
12990 * @throws SecurityException if the caller doesn't have required permission.
12991 */
12992 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012993 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12994 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012995 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012996 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
12997 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012998 }
Sarah Chin503828c2023-02-01 23:54:20 -080012999
13000 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013001 Phone phone = getPhoneOrDefault(validSubId, "requestSatelliteCapabilities");
Sarah Chin503828c2023-02-01 23:54:20 -080013002 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013003 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
13004 return;
Sarah Chin503828c2023-02-01 23:54:20 -080013005 }
13006
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013007 sendRequestAsync(CMD_GET_SATELLITE_CAPABILITIES, result, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080013008 }
13009
13010 /**
Sarah Chineccfbd12023-01-20 19:00:35 -080013011 * Start receiving satellite position updates.
13012 * This can be called by the pointing UI when the user starts pointing to the satellite.
13013 * Modem should continue to report the pointing input as the device or satellite moves.
13014 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013015 * @param subId The subId of the subscription to start satellite position updates for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013016 * @param errorCallback The callback to get the error code of the request.
Sarah Chineccfbd12023-01-20 19:00:35 -080013017 * @param callback The callback to notify of changes in satellite position.
Sarah Chin503828c2023-02-01 23:54:20 -080013018 *
13019 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013020 */
13021 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013022 public void startSatellitePositionUpdates(int subId, @NonNull IIntegerConsumer errorCallback,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013023 @NonNull ISatellitePositionUpdateCallback callback) {
Sarah Chinf75afa72023-02-01 01:32:19 -080013024 enforceSatelliteCommunicationPermission("startSatellitePositionUpdates");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013025 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013026 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013027 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
13028 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013029 }
Sarah Chinf75afa72023-02-01 01:32:19 -080013030
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013031 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013032 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013033 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
13034 return;
Sarah Chinf75afa72023-02-01 01:32:19 -080013035 }
13036
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013037 Phone phone = getPhoneOrDefault(validSubId, "startSatellitePositionUpdates");
Sarah Chineccfbd12023-01-20 19:00:35 -080013038 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013039 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
13040 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080013041 }
13042
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013043 SatellitePositionUpdateHandler handler =
13044 mSatellitePositionUpdateHandlers.get(validSubId);
13045 if (handler != null) {
13046 handler.addListener(callback);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013047 return;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013048 } else {
13049 handler = new SatellitePositionUpdateHandler(Looper.getMainLooper());
13050 handler.addListener(callback);
13051 mSatellitePositionUpdateHandlers.put(validSubId, handler);
13052 phone.registerForSatellitePointingInfoChanged(handler,
13053 SatellitePositionUpdateHandler.EVENT_POSITION_UPDATE, null);
13054 phone.registerForSatelliteDatagramsDelivered(handler,
13055 SatellitePositionUpdateHandler.EVENT_MESSAGE_TRANSFER_STATE_UPDATE,
13056 null);
Sarah Chineccfbd12023-01-20 19:00:35 -080013057 }
13058
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013059 sendRequestAsync(CMD_START_SATELLITE_POSITION_UPDATES,
13060 new SatellitePositionUpdateArgument(result, callback, validSubId), phone, null);
Sarah Chineccfbd12023-01-20 19:00:35 -080013061 }
13062
13063 /**
13064 * Stop receiving satellite position updates.
13065 * This can be called by the pointing UI when the user stops pointing to the satellite.
13066 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013067 * @param subId The subId of the subscription to stop satellite position updates for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013068 * @param errorCallback The callback to get the error code of the request.
13069 * @param callback The callback that was passed to {@link
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013070 * #startSatellitePositionUpdates(int, IIntegerConsumer, ISatellitePositionUpdateCallback)}
Sarah Chin503828c2023-02-01 23:54:20 -080013071 *
13072 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013073 */
13074 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013075 public void stopSatellitePositionUpdates(int subId, @NonNull IIntegerConsumer errorCallback,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013076 @NonNull ISatellitePositionUpdateCallback callback) {
Sarah Chinf75afa72023-02-01 01:32:19 -080013077 enforceSatelliteCommunicationPermission("stopSatellitePositionUpdates");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013078 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013079 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013080 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
13081 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013082 }
Sarah Chinf75afa72023-02-01 01:32:19 -080013083
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013084 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013085 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013086 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
13087 return;
Sarah Chinf75afa72023-02-01 01:32:19 -080013088 }
13089
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013090 Phone phone = getPhoneOrDefault(validSubId, "stopSatellitePositionUpdates");
Sarah Chineccfbd12023-01-20 19:00:35 -080013091 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013092 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
13093 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080013094 }
13095
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013096 SatellitePositionUpdateHandler handler = mSatellitePositionUpdateHandlers.get(validSubId);
13097 if (handler != null) {
13098 handler.removeListener(callback);
13099
13100 if (handler.hasListeners()) {
13101 /**
13102 * TODO (b/269194948): If the calling apps crash, the handler will always have some
13103 * listener. That is, we will not request modem to stop position update and
13104 * cleaning our resources. We need to monitor the calling apps and clean up the
13105 * resources when the apps die. We need to this for other satellite callbacks
13106 * as well.
13107 */
13108 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
13109 return;
13110 }
13111
13112 mSatellitePositionUpdateHandlers.remove(validSubId);
Sarah Chineccfbd12023-01-20 19:00:35 -080013113 phone.unregisterForSatellitePointingInfoChanged(handler);
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013114 phone.unregisterForSatelliteDatagramsDelivered(handler);
Sarah Chineccfbd12023-01-20 19:00:35 -080013115 }
13116
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013117 /**
13118 * Even if handler is null - which means there are not any listeners, the command to stop
13119 * satellite position updates sent to the modem might have failed. The callers might want to
13120 * retry sending the command. Thus, we always need to send this command to the modem.
13121 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013122 sendRequestAsync(CMD_STOP_SATELLITE_POSITION_UPDATES, result, phone, null);
Sarah Chineccfbd12023-01-20 19:00:35 -080013123 }
13124
13125 /**
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013126 * Request to get the maximum number of bytes per datagram that can be sent to satellite.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013127 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013128 * @param subId The subId of the subscription to get the maximum number of characters for.
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013129 * @param result The result receiver that returns the maximum number of bytes per datagram
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013130 * message on satellite if the request is successful or an error code
13131 * if the request failed.
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013132 *
13133 * @throws SecurityException if the caller doesn't have the required permission.
13134 */
13135 @Override
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013136 public void requestMaxSizePerSendingDatagram(int subId,
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013137 @NonNull ResultReceiver result) {
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013138 enforceSatelliteCommunicationPermission("requestMaxSizePerSendingDatagram");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013139 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013140 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
13141 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013142 }
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013143
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013144 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013145 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013146 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
13147 return;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013148 }
13149
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013150 Phone phone = getPhoneOrDefault(validSubId, "requestMaxSizePerSendingDatagram");
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013151 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013152 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
13153 return;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013154 }
13155
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013156 sendRequestAsync(CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG, result, phone, null);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013157 }
13158
13159 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013160 * Register the subscription with a satellite provider.
13161 * This is needed to register the subscription if the provider allows dynamic registration.
13162 *
13163 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013164 * @param token The token to be used as a unique identifier for provisioning with satellite
13165 * gateway.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013166 * @param callback The callback to get the error code of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013167 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013168 * @return The signal transport used by the caller to cancel the provision request,
13169 * or {@code null} if the request failed.
13170 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013171 * @throws SecurityException if the caller doesn't have the required permission.
13172 */
13173 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013174 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
13175 @NonNull String token, @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013176 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013177 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013178 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013179 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013180 return null;
13181 }
13182
13183 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013184 Phone phone = getPhoneOrDefault(validSubId, "provisionSatelliteService");
13185 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013186 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013187 return null;
13188 }
13189
13190 if (mSatelliteProvisionCallbacks.containsKey(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013191 result.accept(SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013192 return null;
13193 }
13194
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013195 if (isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013196 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013197 return null;
13198 }
13199
13200 sendRequestAsync(CMD_PROVISION_SATELLITE_SERVICE,
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013201 new ProvisionSatelliteServiceArgument(token, result, validSubId), phone, null);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013202
13203 ICancellationSignal cancelTransport = CancellationSignal.createTransport();
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013204 CancellationSignal.fromTransport(cancelTransport).setOnCancelListener(() -> {
13205 sendRequestAsync(CMD_DEPROVISION_SATELLITE_SERVICE,
13206 new ProvisionSatelliteServiceArgument(token, null, validSubId),
13207 phone, null);
13208 });
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013209 return cancelTransport;
13210 }
13211
13212 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013213 * Unregister the device/subscription with the satellite provider.
13214 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013215 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013216 * should report as deprovisioned.
13217 *
13218 * @param subId The subId of the subscription to be deprovisioned.
13219 * @param token The token of the device/subscription to be deprovisioned.
13220 * @param callback The callback to get the error code of the request.
13221 *
13222 * @throws SecurityException if the caller doesn't have the required permission.
13223 */
13224 @Override
13225 public void deprovisionSatelliteService(int subId,
13226 @NonNull String token, @NonNull IIntegerConsumer callback) {
13227 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
13228 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
13229 if (!isSatelliteSupported()) {
13230 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
13231 return;
13232 }
13233
13234 final int validSubId = getValidSatelliteSubId(subId);
13235 if (!isSatelliteProvisioned(validSubId)) {
13236 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
13237 return;
13238 }
13239
13240 Phone phone = getPhoneOrDefault(validSubId, "deprovisionSatelliteService");
13241 if (phone == null) {
13242 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
13243 return;
13244 }
13245
13246 sendRequestAsync(CMD_DEPROVISION_SATELLITE_SERVICE,
13247 new ProvisionSatelliteServiceArgument(token, result, validSubId), phone, null);
13248 }
13249
13250 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013251 * Register for the satellite provision state change.
13252 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013253 * @param subId The subId of the subscription to register for provision state changes.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013254 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013255 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013256 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
13257 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013258 * @throws SecurityException if the caller doesn't have the required permission.
13259 */
13260 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080013261 @SatelliteManager.SatelliteError public int registerForSatelliteProvisionStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013262 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013263 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Sarah Chindf715ec2023-02-13 13:46:24 -080013264 return registerForSatelliteProvisionStateChangedInternal(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013265 }
13266
13267 /**
13268 * Unregister for the satellite provision state change.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013269 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013270 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013271 * @param subId The subId of the subscription to unregister for provision state changes.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013272 * @param callback The callback that was passed to
13273 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013274 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013275 * @throws SecurityException if the caller doesn't have the required permission.
13276 */
13277 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013278 public void unregisterForSatelliteProvisionStateChanged(
13279 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013280 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
13281
13282 final int validSubId = getValidSatelliteSubId(subId);
13283 SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler =
13284 mSatelliteProvisionStateChangedHandlers.get(validSubId);
13285 if (satelliteProvisionStateChangedHandler != null) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013286 satelliteProvisionStateChangedHandler.removeListener(callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013287 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013288 }
13289
13290 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013291 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013292 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013293 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013294 * @param result The result receiver that returns whether the device is provisioned with a
13295 * satellite provider if the request is successful or an error code if the
13296 * request failed.
13297 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013298 * @throws SecurityException if the caller doesn't have the required permission.
13299 */
13300 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013301 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13302 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013303 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013304 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
13305 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013306 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013307
13308 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013309 Bundle bundle = new Bundle();
13310 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_PROVISIONED,
13311 isSatelliteProvisioned(validSubId));
13312 result.send(SatelliteManager.SATELLITE_ERROR_NONE, bundle);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013313 }
13314
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013315 /**
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013316 * Register for listening to satellite modem state changes.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013317 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013318 * @param subId The subId of the subscription to register for satellite modem state changes.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013319 * @param callback The callback to handle the satellite modem state change event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013320 *
13321 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
13322 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013323 * @throws SecurityException if the caller doesn't have the required permission.
13324 */
13325 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080013326 @SatelliteManager.SatelliteError public int registerForSatelliteModemStateChange(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013327 @NonNull ISatelliteStateCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013328 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChange");
13329
13330 final int validSubId = getValidSatelliteSubId(subId);
13331 Phone phone = getPhoneOrDefault(
13332 validSubId, "registerForSatelliteModemStateChange");
13333 if (phone == null) {
13334 return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
13335 }
13336
13337 SatelliteStateListenerHandler satelliteStateListenerHandler =
13338 mSatelliteStateListenerHandlers.get(validSubId);
13339 if (satelliteStateListenerHandler == null) {
13340 satelliteStateListenerHandler = new SatelliteStateListenerHandler(
13341 Looper.getMainLooper(), validSubId);
13342 phone.registerForSatelliteModemStateChange(satelliteStateListenerHandler,
13343 SatelliteStateListenerHandler.EVENT_SATELLITE_MODEM_STATE_CHANGE, null);
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013344 phone.registerForPendingDatagramCount(satelliteStateListenerHandler,
13345 SatelliteStateListenerHandler.EVENT_PENDING_DATAGRAM_COUNT, null);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013346 }
13347
13348 satelliteStateListenerHandler.addListener(callback);
13349 mSatelliteStateListenerHandlers.put(validSubId, satelliteStateListenerHandler);
13350 return SatelliteManager.SATELLITE_ERROR_NONE;
13351 }
13352
13353 /**
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013354 * Unregister from listening to satellite modem state changes.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013355 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013356 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013357 * @param subId The subId of the subscription to unregister for satellite modem state changes.
13358 * @param callback The callback that was passed to
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013359 * {@link #registerForSatelliteModemStateChange(int, ISatelliteStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013360 *
13361 * @throws SecurityException if the caller doesn't have the required permission.
13362 */
13363 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013364 public void unregisterForSatelliteModemStateChange(int subId,
13365 @NonNull ISatelliteStateCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013366 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChange");
13367
13368 final int validSubId = getValidSatelliteSubId(subId);
13369 SatelliteStateListenerHandler satelliteStateListenerHandler =
13370 mSatelliteStateListenerHandlers.get(validSubId);
13371 if (satelliteStateListenerHandler != null) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013372 satelliteStateListenerHandler.removeListener(callback);
13373 if (!satelliteStateListenerHandler.hasListeners()) {
13374 mSatelliteStateListenerHandlers.remove(validSubId);
13375
13376 Phone phone = getPhoneOrDefault(
13377 validSubId, "unregisterForSatelliteModemStateChange");
13378 if (phone == null) {
13379 loge("unregisterForSatelliteModemStateChange: phone is null");
13380 } else {
13381 phone.unregisterForSatelliteModemStateChange(satelliteStateListenerHandler);
13382 phone.unregisterForPendingDatagramCount(satelliteStateListenerHandler);
13383 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013384 }
13385 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013386 }
13387
13388 /**
13389 * Register to receive incoming datagrams over satellite.
13390 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013391 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013392 * @param datagramType datagram type indicating whether the datagram is of type
13393 * SOS_SMS or LOCATION_SHARING.
Sarah Chindf715ec2023-02-13 13:46:24 -080013394 * @param callback The callback to handle incoming datagrams over satellite.
13395 *
13396 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
13397 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013398 * @throws SecurityException if the caller doesn't have the required permission.
13399 */
13400 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080013401 @SatelliteManager.SatelliteError public int registerForSatelliteDatagram(int subId,
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013402 @SatelliteManager.DatagramType int datagramType,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013403 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013404 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013405 if (!isSatelliteSupported()) {
13406 return SatelliteManager.SATELLITE_NOT_SUPPORTED;
13407 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013408
13409 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chindf715ec2023-02-13 13:46:24 -080013410 Phone phone = getPhoneOrDefault(validSubId, "registerForSatelliteDatagram");
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013411 if (phone == null) {
13412 return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
13413 }
13414
13415 SatelliteDatagramListenerHandler satelliteDatagramListenerHandler =
13416 mSatelliteDatagramListenerHandlers.get(validSubId);
13417 if (satelliteDatagramListenerHandler == null) {
13418 satelliteDatagramListenerHandler = new SatelliteDatagramListenerHandler(
13419 Looper.getMainLooper(), validSubId);
13420 phone.registerForNewSatelliteDatagram(satelliteDatagramListenerHandler,
13421 SatelliteDatagramListenerHandler.EVENT_SATELLITE_DATAGRAMS_RECEIVED, null);
13422 }
13423
13424 satelliteDatagramListenerHandler.addListener(callback);
13425 mSatelliteDatagramListenerHandlers.put(validSubId, satelliteDatagramListenerHandler);
13426 return SatelliteManager.SATELLITE_ERROR_NONE;
13427 }
13428
13429 /**
13430 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013431 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013432 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013433 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13434 * @param callback The callback that was passed to
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013435 * {@link #registerForSatelliteDatagram(int, int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013436 *
13437 * @throws SecurityException if the caller doesn't have the required permission.
13438 */
13439 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013440 public void unregisterForSatelliteDatagram(int subId,
13441 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013442 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
13443
13444 final int validSubId = getValidSatelliteSubId(subId);
13445 SatelliteDatagramListenerHandler satelliteDatagramListenerHandler =
13446 mSatelliteDatagramListenerHandlers.get(validSubId);
13447 if (satelliteDatagramListenerHandler != null) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013448 satelliteDatagramListenerHandler.removeListener(callback);
13449
13450 if (!satelliteDatagramListenerHandler.hasListeners()) {
13451 mSatelliteDatagramListenerHandlers.remove(validSubId);
13452
13453 Phone phone = getPhoneOrDefault(validSubId, "unregisterForSatelliteDatagram");
13454 if (phone == null) {
13455 loge("unregisterForSatelliteDatagram: phone is null");
13456 } else {
13457 phone.unregisterForNewSatelliteDatagram(satelliteDatagramListenerHandler);
13458 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013459 }
13460 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013461 }
13462
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013463 /**
13464 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013465 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013466 * This method requests modem to check if there are any pending datagrams to be received over
13467 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013468 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int,
13469 * ISatelliteDatagramReceiverAck)}
Sarah Chindf715ec2023-02-13 13:46:24 -080013470 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013471 * @param subId The subId of the subscription used for receiving datagrams.
13472 * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013473 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013474 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013475 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013476 @Override
13477 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013478 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013479 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013480
13481 final int validSubId = getValidSatelliteSubId(subId);
13482 if (!isSatelliteProvisioned(validSubId)) {
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013483 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
13484 return;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013485 }
13486
13487 Phone phone = getPhoneOrDefault(validSubId, "pollPendingSatelliteDatagrams");
13488 if (phone == null) {
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013489 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
13490 return;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013491 }
13492
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013493 sendRequestAsync(CMD_POLL_PENDING_SATELLITE_DATAGRAMS, result, phone, null);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013494 }
13495
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013496 /**
13497 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013498 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013499 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13500 * input to this method. Datagram received here will be passed down to modem without any
13501 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013502 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013503 * @param subId The subId of the subscription to send satellite datagrams for.
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013504 * @param datagramId An id that uniquely identifies datagram requested to be sent.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013505 * @param datagramType datagram type indicating whether the datagram is of type
13506 * SOS_SMS or LOCATION_SHARING.
13507 * @param datagram encoded gateway datagram which is encrypted by the caller.
13508 * Datagram will be passed down to modem without any encoding or encryption.
13509 * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request.
13510 *
13511 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013512 */
13513 @Override
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013514 public void sendSatelliteDatagram(int subId, long datagramId,
13515 @SatelliteManager.DatagramType int datagramType, SatelliteDatagram datagram,
13516 @NonNull ResultReceiver result) {
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013517 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013518
13519 final int validSubId = getValidSatelliteSubId(subId);
13520 if (!isSatelliteProvisioned(validSubId)) {
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013521 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013522 return;
13523 }
13524
13525 Phone phone = getPhoneOrDefault(validSubId, "sendSatelliteDatagram");
13526 if (phone == null) {
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013527 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013528 return;
13529 }
13530
13531 // check if we need to start PointingUI.
13532
13533 sendRequestAsync(CMD_SEND_SATELLITE_DATAGRAM,
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013534 new SendSatelliteDatagramArgument(datagramId, datagramType, datagram, result),
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013535 phone, null);
13536 }
13537
Sarah Chindf715ec2023-02-13 13:46:24 -080013538 /**
13539 * Request to get whether satellite communication is allowed for the current location.
13540 *
13541 * @param subId The subId of the subscription to check whether satellite communication is
13542 * allowed for the current location for.
13543 * @param result The result receiver that returns whether satellite communication is allowed
13544 * for the current location if the request is successful or an error code
13545 * if the request failed.
13546 *
13547 * @throws SecurityException if the caller doesn't have the required permission.
13548 */
13549 @Override
13550 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
13551 @NonNull ResultReceiver result) {
13552 enforceSatelliteCommunicationPermission(
13553 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
13554 if (!isSatelliteSupported()) {
13555 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
13556 return;
13557 }
13558
13559 final int validSubId = getValidSatelliteSubId(subId);
13560 if (!isSatelliteProvisioned(validSubId)) {
13561 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
13562 return;
13563 }
13564
13565 Phone phone = getPhoneOrDefault(validSubId,
13566 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
13567 if (phone == null) {
13568 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
13569 return;
13570 }
13571
13572 sendRequest(CMD_IS_SATELLITE_COMMUNICATION_ALLOWED, result, subId);
13573 }
13574
13575 /**
Sarah Chin5f57c582023-02-14 04:16:10 -080013576 * Request to get the time after which the satellite will be visible
Sarah Chindf715ec2023-02-13 13:46:24 -080013577 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013578 * @param subId The subId to get the time after which the satellite will be visible for.
13579 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013580 * be visible if the request is successful or an error code if the request failed.
13581 *
13582 * @throws SecurityException if the caller doesn't have the required permission.
13583 */
13584 @Override
13585 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13586 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
13587 if (!isSatelliteSupported()) {
13588 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
13589 return;
13590 }
13591
13592 final int validSubId = getValidSatelliteSubId(subId);
13593 if (!isSatelliteProvisioned(validSubId)) {
13594 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
13595 return;
13596 }
13597
13598 Phone phone = getPhoneOrDefault(validSubId, "requestTimeForNextSatelliteVisibility");
13599 if (phone == null) {
13600 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
13601 return;
13602 }
13603
13604 sendRequestAsync(CMD_GET_TIME_SATELLITE_NEXT_VISIBLE, result, phone, null);
13605 }
13606
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013607 private void handleEventProvisionSatelliteServiceDone(
13608 @NonNull ProvisionSatelliteServiceArgument arg,
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013609 @SatelliteManager.SatelliteError int result) {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013610 log("handleEventProvisionSatelliteServiceDone: result="
13611 + result + ", subId=" + arg.subId);
13612
13613 Consumer<Integer> callback = mSatelliteProvisionCallbacks.remove(arg.subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013614 if (callback == null) {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013615 loge("handleEventProvisionSatelliteServiceDone: callback is null for subId="
13616 + arg.subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013617 return;
13618 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013619 callback.accept(result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013620
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013621 if (result == SatelliteManager.SATELLITE_ERROR_NONE) {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013622 setSatelliteProvisioned(arg.subId, true);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013623 }
13624
13625 /**
13626 * We need to update satellite provision status in SubscriptionController
13627 * or SatelliteController.
13628 * TODO (b/267826133) we need to do this for all subscriptions on the device.
13629 */
Sarah Chindf715ec2023-02-13 13:46:24 -080013630 registerForSatelliteProvisionStateChangedInternal(arg.subId, null);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013631 }
13632
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013633 private void handleEventDeprovisionSatelliteServiceDone(
13634 @NonNull ProvisionSatelliteServiceArgument arg,
13635 @SatelliteManager.SatelliteError int result) {
13636 if (arg == null) {
13637 loge("handleEventDeprovisionSatelliteServiceDone: arg is null");
13638 return;
13639 }
13640 log("handleEventDeprovisionSatelliteServiceDone: result="
13641 + result + ", subId=" + arg.subId);
13642
13643 if (arg.callback != null) {
13644 arg.callback.accept(result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013645 }
13646
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013647 if (result == SatelliteManager.SATELLITE_ERROR_NONE) {
13648 setSatelliteProvisioned(arg.subId, false);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013649 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013650 }
13651
13652 private Phone getPhoneOrDefault(int subId, String caller) {
13653 Phone phone = getPhone(subId);
13654 if (phone == null) {
13655 loge(caller + " called with invalid subId: " + subId
13656 + ". Retrying with default phone.");
13657 phone = getDefaultPhone();
13658 if (phone == null) {
13659 loge(caller + " failed with no phone object.");
13660 }
13661 }
13662 return phone;
13663 }
13664
13665 /**
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013666 * Check if satellite is provisioned for a subscription or the device.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013667 *
13668 * Note: this is the version without permission check for telephony internal use only. The
13669 * caller need to take care of the permission check.
13670 */
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013671 private boolean isSatelliteProvisioned(int subId) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013672 if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
13673 if (mSubscriptionController == null) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013674 loge("isSatelliteProvisioned mSubscriptionController is null");
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013675 return false;
13676 }
13677
13678 String strResult = mSubscriptionController.getSubscriptionProperty(
13679 subId, SubscriptionManager.SATELLITE_ENABLED);
13680 if (strResult != null) {
13681 int intResult = Integer.parseInt(strResult);
13682 return (intResult == 1) ? true : false;
13683 }
13684 } else {
13685 //TODO (b/267826133): check via SatelliteController
13686 }
13687 return false;
13688 }
13689
13690 /**
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013691 * Set satellite provisioned for a subscription or the device.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013692 *
13693 * The permission {@link android.Manifest.permission#MODIFY_PHONE_STATE} will be enforced by
13694 * {@link SubscriptionController} when setting satellite enabled for an active subscription.
13695 * Otherwise, {@link android.Manifest.permission#SATELLITE_COMMUNICATION} will be enforced.
13696 */
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013697 private synchronized void setSatelliteProvisioned(int subId, boolean isEnabled) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013698 if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
13699 if (mSubscriptionController == null) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013700 loge("setSatelliteProvisioned mSubscriptionController is null");
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013701 return;
13702 }
13703 mSubscriptionController.setSubscriptionProperty(
13704 subId, SubscriptionManager.SATELLITE_ENABLED, isEnabled ? "1" : "0");
13705 } else {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013706 //TODO (b/267826133): set via SatelliteController
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013707 }
13708 }
13709
13710 private int getValidSatelliteSubId(int subId) {
13711 if (mSubscriptionController == null) {
13712 loge("getValidSatelliteSubId mSubscriptionController is null. "
13713 + "Use DEFAULT_SUBSCRIPTION_ID for subId=" + subId);
13714 return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
13715 }
13716 final long identity = Binder.clearCallingIdentity();
13717 try {
13718 Context context = getDefaultPhone().getContext();
13719 if (mSubscriptionController.isActiveSubId(
13720 subId, context.getOpPackageName(), context.getAttributionTag())) {
13721 return subId;
13722 }
13723 } finally {
13724 Binder.restoreCallingIdentity(identity);
13725 }
13726 if (DBG) log("getValidSatelliteSubId: use DEFAULT_SUBSCRIPTION_ID for subId=" + subId);
13727 return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
13728 }
13729
13730 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013731 * If we have not successfully queried the satellite modem for its satellite service support,
13732 * we will retry the query one more time. Otherwise, we will return the queried result.
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013733 */
13734 private boolean isSatelliteSupported() {
13735 synchronized (mIsSatelliteSupportedLock) {
13736 if (mIsSatelliteSupported != null) {
13737 /* We have already successfully queried the satellite modem. */
13738 return mIsSatelliteSupported;
13739 }
13740 }
13741 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013742 * We have not successfully checked whether the modem supports satellite service.
13743 * Thus, we need to retry it now.
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013744 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013745 requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
13746 mSatelliteSupportedReceiver);
13747 return false;
13748 }
13749
13750 /**
13751 * Get the {@link SatelliteManager.SatelliteError} from the provided result.
Sarah Chindf715ec2023-02-13 13:46:24 -080013752 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013753 * @param ar AsyncResult used to determine the error code.
13754 * @param caller The satellite request.
13755 * @param checkResult Whether to check if the result exists.
Sarah Chindf715ec2023-02-13 13:46:24 -080013756 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013757 * @return The {@link SatelliteManager.SatelliteError} error code from the request.
13758 */
13759 @SatelliteManager.SatelliteError private int getSatelliteError(@NonNull AsyncResult ar,
13760 @NonNull String caller, boolean checkResult) {
13761 int errorCode;
13762 if (ar.exception == null) {
13763 errorCode = SatelliteManager.SATELLITE_ERROR_NONE;
13764 if (checkResult && ar.result == null) {
13765 loge(caller + ": result is null");
13766 errorCode = SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
13767 }
13768 } else {
13769 errorCode = SatelliteManager.SATELLITE_ERROR;
13770 if (ar.exception instanceof CommandException) {
Sarah Chin4beb2b72023-02-14 14:47:54 -080013771 CommandException.Error error = ((CommandException) ar.exception).getCommandError();
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013772 errorCode = RILUtils.convertToSatelliteError(error);
13773 loge(caller + " CommandException: " + ar.exception);
Sarah Chin4beb2b72023-02-14 14:47:54 -080013774 } else if (ar.exception instanceof SatelliteManager.SatelliteException) {
13775 errorCode = ((SatelliteManager.SatelliteException) ar.exception).getErrorCode();
13776 loge(caller + " SatelliteException: " + ar.exception);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013777 } else {
13778 loge(caller + " unknown exception: " + ar.exception);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013779 }
13780 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013781 log(caller + " error: " + errorCode);
13782 return errorCode;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013783 }
13784
13785 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013786 * Register for the satellite provision state change.
13787 *
13788 * @param subId The subId of the subscription associated with the satellite service.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013789 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013790 *
13791 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013792 */
Sarah Chindf715ec2023-02-13 13:46:24 -080013793 @SatelliteManager.SatelliteError private int registerForSatelliteProvisionStateChangedInternal(
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013794 int subId, @Nullable ISatelliteProvisionStateCallback callback) {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013795 if (!isSatelliteSupported()) {
Sarah Chindf715ec2023-02-13 13:46:24 -080013796 return SatelliteManager.SATELLITE_NOT_SUPPORTED;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013797 }
13798
13799 final int validSubId = getValidSatelliteSubId(subId);
13800 Phone phone = getPhoneOrDefault(validSubId, "registerForSatelliteProvisionStateChanged");
13801 if (phone == null) {
Sarah Chindf715ec2023-02-13 13:46:24 -080013802 return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013803 }
13804
13805 SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler =
13806 mSatelliteProvisionStateChangedHandlers.get(validSubId);
13807 if (satelliteProvisionStateChangedHandler == null) {
13808 satelliteProvisionStateChangedHandler = new SatelliteProvisionStateChangedHandler(
13809 Looper.getMainLooper(), validSubId);
13810 phone.registerForSatelliteProvisionStateChanged(satelliteProvisionStateChangedHandler,
13811 SatelliteProvisionStateChangedHandler.EVENT_PROVISION_STATE_CHANGED, null);
13812 }
13813
13814 if (callback != null) {
13815 satelliteProvisionStateChangedHandler.addListener(callback);
13816 }
13817 mSatelliteProvisionStateChangedHandlers.put(
13818 validSubId, satelliteProvisionStateChangedHandler);
Sarah Chindf715ec2023-02-13 13:46:24 -080013819 return SatelliteManager.SATELLITE_ERROR_NONE;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013820 }
13821
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013822 private void handleStartSatellitePositionUpdatesDone(@NonNull AsyncResult ar) {
13823 MainThreadRequest request = (MainThreadRequest) ar.userObj;
13824 SatellitePositionUpdateArgument arg = (SatellitePositionUpdateArgument) request.argument;
13825 int errorCode = getSatelliteError(
13826 ar, "handleStartSatellitePositionUpdatesDone", false);
13827 arg.errorCallback.accept(errorCode);
13828
13829 if (errorCode != SatelliteManager.SATELLITE_ERROR_NONE) {
13830 /**
13831 * We need to remove the callback from our listener list since the caller might not call
13832 * {@link #stopSatellitePositionUpdates(int, IIntegerConsumer, ISatellitePositionUpdateCallback)}
13833 * to unregister the callback in case of failure.
13834 */
13835 SatellitePositionUpdateHandler handler =
13836 mSatellitePositionUpdateHandlers.get(arg.subId);
13837 if (handler != null) {
13838 handler.removeListener(arg.callback);
13839
13840 if (!handler.hasListeners()) {
13841 mSatellitePositionUpdateHandlers.remove(arg.subId);
13842
13843 Phone phone = getPhoneFromRequest(request);
13844 if (phone == null) {
13845 loge("handleStartSatellitePositionUpdatesDone: phone is null");
13846 } else {
13847 phone.unregisterForSatellitePointingInfoChanged(handler);
13848 phone.unregisterForSatelliteDatagramsDelivered(handler);
13849 }
13850 }
13851 }
13852 }
13853 }
13854
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013855 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000013856 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
13857 *
13858 * <p>This method behaves in one of the following ways:
13859 * <ul>
13860 * <li>return true : if the calling package has the appop permission {@link
13861 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
13862 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
13863 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
13864 * Owner device identifier access check, or the calling package has carrier privileges</>
13865 * <li>throw SecurityException: if the caller does not meet any of the requirements.
13866 * </ul>
13867 */
13868 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
13869 String callingPackage, @Nullable String callingFeatureId, String message) {
13870 for (Phone phone : PhoneFactory.getPhones()) {
13871 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
13872 phone.getSubId(), callingPackage, callingFeatureId, message)) {
13873 return true;
13874 }
13875 }
13876 return false;
13877 }
arunvoddud7401012022-12-15 16:08:12 +000013878
13879 /**
Jack Yufa8ed012023-02-11 15:42:28 -080013880 * @return The subscription manager service instance.
13881 */
13882 public SubscriptionManagerService getSubscriptionManagerService() {
13883 return SubscriptionManagerService.getInstance();
13884 }
13885
13886 /**
arunvoddud7401012022-12-15 16:08:12 +000013887 * Class binds the consumer[callback] and carrierId.
13888 */
13889 private static class CallerCallbackInfo {
13890 private final Consumer<Integer> mConsumer;
13891 private final int mCarrierId;
13892
13893 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
13894 mConsumer = consumer;
13895 mCarrierId = carrierId;
13896 }
13897
13898 public Consumer<Integer> getConsumer() {
13899 return mConsumer;
13900 }
13901
13902 public int getCarrierId() {
13903 return mCarrierId;
13904 }
13905 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013906
13907 private static SatelliteDatagram[] convertToSatelliteDatagramArray(byte[][] datagrams) {
13908 // Convert 2D byte array into SatelliteDatagramArray.
13909 SatelliteDatagram[] satelliteDatagramArray =
13910 new SatelliteDatagram[datagrams.length];
13911 for (int i = 0; i < datagrams.length; i++) {
13912 satelliteDatagramArray[i] = new SatelliteDatagram(datagrams[i]);
13913 }
13914 return satelliteDatagramArray;
13915 }
Jack Yufa8ed012023-02-11 15:42:28 -080013916}