blob: 26eb8c2d877f257354df506a8dfd26cc3c70fd06 [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 Nguyen8ee49682023-02-01 11:46:09 -0800148import android.telephony.satellite.ISatelliteStateListener;
Sarah Chineccfbd12023-01-20 19:00:35 -0800149import android.telephony.satellite.PointingInfo;
Sarah Chin503828c2023-02-01 23:54:20 -0800150import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000151import android.telephony.satellite.SatelliteDatagram;
Sarah Chineccfbd12023-01-20 19:00:35 -0800152import android.telephony.satellite.SatelliteManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700153import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800154import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700155import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700156import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800157import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800158
Andrew Lee312e8172014-10-23 17:01:36 -0700159import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800160import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800161import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800162import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800163import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700165import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700166import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800167import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800168import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700169import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700170import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800171import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700172import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800173import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800174import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800175import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700176import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000177import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700178import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800179import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700180import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800181import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800182import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800183import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700184import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700185import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700186import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700188import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800189import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700190import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700191import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700192import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700193import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800194import com.android.internal.telephony.RILConstants;
Sarah Chineccfbd12023-01-20 19:00:35 -0800195import com.android.internal.telephony.RILUtils;
Daniel Bright94f43662021-03-01 14:43:40 -0800196import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700197import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000198import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700199import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700200import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800201import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800202import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800203import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700204import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000205import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800206import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700207import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800208import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700209import com.android.internal.telephony.imsphone.ImsPhone;
210import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000211import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800212import com.android.internal.telephony.metrics.TelephonyMetrics;
Jack Yu285100e2022-12-02 22:48:35 -0800213import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
214import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700215import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700216import com.android.internal.telephony.uicc.IccIoResult;
217import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800218import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700219import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800220import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700221import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000222import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800223import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000224import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800225import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000226import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700227import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700228import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800229import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800230import com.android.phone.callcomposer.CallComposerPictureManager;
231import com.android.phone.callcomposer.CallComposerPictureTransfer;
232import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700233import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700234import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000235import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700236import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800237import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700238import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700239import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800240import com.android.services.telephony.TelecomAccountRegistry;
241import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800242import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800243
Hall Liu82694d52020-12-11 18:22:04 -0800244import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700245import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800246import java.io.IOException;
247import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700248import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800250import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000251import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800252import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800253import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800254import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800255import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100256import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800257import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700258import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800259import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800260import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700261import java.util.UUID;
Sarah Chineccfbd12023-01-20 19:00:35 -0800262import java.util.concurrent.ConcurrentHashMap;
Hall Liu82694d52020-12-11 18:22:04 -0800263import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800264import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800265import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700266
267/**
268 * Implementation of the ITelephony interface.
269 */
Santos Cordon117fee72014-05-16 17:56:12 -0700270public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700271 private static final String LOG_TAG = "PhoneInterfaceManager";
272 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
273 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800274 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275
276 // Message codes used with mMainThreadHandler
277 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700278 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
279 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700280 private static final int CMD_OPEN_CHANNEL = 9;
281 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
282 private static final int CMD_CLOSE_CHANNEL = 11;
283 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800284 private static final int CMD_NV_READ_ITEM = 13;
285 private static final int EVENT_NV_READ_ITEM_DONE = 14;
286 private static final int CMD_NV_WRITE_ITEM = 15;
287 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
288 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
289 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700290 private static final int CMD_RESET_MODEM_CONFIG = 19;
291 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800292 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
293 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800294 private static final int CMD_SEND_ENVELOPE = 25;
295 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000296 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
297 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700298 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
299 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
300 private static final int CMD_EXCHANGE_SIM_IO = 31;
301 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800302 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
303 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700304 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
305 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700306 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
307 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700308 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
309 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
310 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
311 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700312 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
313 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
314 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
315 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700316 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800317 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
318 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000319 private static final int CMD_SWITCH_SLOTS = 50;
320 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700321 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
322 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
323 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
324 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
325 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
326 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
327 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
328 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700329 private static final int CMD_GET_ALL_CELL_INFO = 60;
330 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
331 private static final int CMD_GET_CELL_LOCATION = 62;
332 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700333 private static final int CMD_MODEM_REBOOT = 64;
334 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700335 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
336 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800337 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
338 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700339 private static final int CMD_GET_MODEM_STATUS = 70;
340 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700341 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
342 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700343 private static final int CMD_ERASE_MODEM_CONFIG = 74;
344 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800345 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
346 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
347 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
348 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800349 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
350 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800351 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800352 private static final int CMD_GET_CALL_FORWARDING = 83;
353 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
354 private static final int CMD_SET_CALL_FORWARDING = 85;
355 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
356 private static final int CMD_GET_CALL_WAITING = 87;
357 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
358 private static final int CMD_SET_CALL_WAITING = 89;
359 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700360 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
361 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
362 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
363 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700364 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
365 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800366 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
367 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800368 private static final int CMD_SET_DATA_THROTTLING = 99;
369 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800370 private static final int CMD_SET_SIM_POWER = 101;
371 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800372 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
373 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
374 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
375 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800376 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
377 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000378 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800379 private static final int CMD_GET_SLICING_CONFIG = 110;
380 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800381 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700382 private static final int CMD_ENABLE_VONR = 113;
383 private static final int EVENT_ENABLE_VONR_DONE = 114;
384 private static final int CMD_IS_VONR_ENABLED = 115;
385 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700386 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
387 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Sarah Chineccfbd12023-01-20 19:00:35 -0800388 private static final int CMD_START_SATELLITE_POSITION_UPDATES = 119;
389 private static final int EVENT_START_SATELLITE_POSITION_UPDATES_DONE = 120;
390 private static final int CMD_STOP_SATELLITE_POSITION_UPDATES = 121;
391 private static final int EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE = 122;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +0000392 private static final int CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG = 123;
393 private static final int EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE = 124;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800394 private static final int CMD_PROVISION_SATELLITE_SERVICE = 125;
395 private static final int EVENT_PROVISION_SATELLITE_SERVICE_DONE = 126;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -0800396 private static final int CMD_DEPROVISION_SATELLITE_SERVICE = 127;
397 private static final int EVENT_DEPROVISION_SATELLITE_SERVICE_DONE = 128;
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800398 private static final int CMD_SET_SATELLITE_ENABLED = 129;
399 private static final int EVENT_SET_SATELLITE_ENABLED_DONE = 130;
400 private static final int CMD_IS_SATELLITE_ENABLED = 131;
401 private static final int EVENT_IS_SATELLITE_ENABLED_DONE = 132;
402 private static final int CMD_IS_SATELLITE_SUPPORTED = 133;
403 private static final int EVENT_IS_SATELLITE_SUPPORTED_DONE = 134;
404 private static final int CMD_GET_SATELLITE_CAPABILITIES = 135;
405 private static final int EVENT_GET_SATELLITE_CAPABILITIES_DONE = 136;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000406 private static final int CMD_POLL_PENDING_SATELLITE_DATAGRAMS = 137;
407 private static final int EVENT_POLL_PENDING_SATELLITE_DATAGRAMS_DONE = 138;
408
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800409 // Parameters of select command.
410 private static final int SELECT_COMMAND = 0xA4;
411 private static final int SELECT_P1 = 0x04;
412 private static final int SELECT_P2 = 0;
413 private static final int SELECT_P3 = 0x10;
414
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000415 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
416 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
417
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700418 /** The singleton instance. */
419 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800420 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700421
Wink Saville3ab207e2014-11-20 13:07:20 -0800422 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800423 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800424 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700425 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800426 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700427 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800428 private MainThreadHandler mMainThreadHandler;
Jack Yue37dd262022-12-16 11:53:37 -0800429 private final SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800430 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700431 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800432 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700433
Peter Wangdafb9ac2020-01-15 14:13:38 -0800434 /** User Activity */
435 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800436 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
437
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700438 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800439
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800440 /**
441 * Map key: subId, value: callback to get error code of the provision request.
442 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800443 private final ConcurrentHashMap<Integer, Consumer<Integer>> mSatelliteProvisionCallbacks =
Sarah Chineccfbd12023-01-20 19:00:35 -0800444 new ConcurrentHashMap<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800445 /**
446 * Map key: subId, value: SatellitePositionUpdateHandler to notify registrants.
447 */
448 private final ConcurrentHashMap<IBinder, SatellitePositionUpdateHandler>
449 mSatellitePositionUpdateHandlers = new ConcurrentHashMap<>();
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800450 /**
451 * Map key: subId, value: SatelliteProvisionStateChangedHandler to notify registrants.
452 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800453 private final ConcurrentHashMap<Integer, SatelliteProvisionStateChangedHandler>
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800454 mSatelliteProvisionStateChangedHandlers = new ConcurrentHashMap<>();
455
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800456 private Boolean mIsSatelliteSupported = null;
457 private final Object mIsSatelliteSupportedLock = new Object();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800458 private final ResultReceiver mSatelliteSupportedReceiver;
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800459
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000460 /**
461 * Map key: subId, value: SatelliteStateChangeHandler to notify registrants.
462 */
463 private ConcurrentHashMap<Integer, SatelliteStateListenerHandler>
464 mSatelliteStateListenerHandlers = new ConcurrentHashMap<>();
465
466 /**
467 * Map key: subId, value: SatelliteDatagramListenerHandler to notify registrants.
468 */
469 private ConcurrentHashMap<Integer, SatelliteDatagramListenerHandler>
470 mSatelliteDatagramListenerHandlers = new ConcurrentHashMap<>();
471
Derek Tan97ebb422014-09-05 16:55:38 -0700472 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
473 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800474 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800475 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700476
Michelecea4cf22018-12-21 15:00:11 -0800477 // String to store multi SIM allowed
478 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
479
Derek Tan740e1672017-06-27 14:56:27 -0700480 // The AID of ISD-R.
481 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
482
yinxub1bed742017-04-17 11:45:04 -0700483 private NetworkScanRequestTracker mNetworkScanRequestTracker;
484
David Kelly5e06a7f2018-03-12 14:10:59 +0000485 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
486 private static final int MANUFACTURER_CODE_LENGTH = 8;
487
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800488 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800489 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800490
Sarah Chin2ec39f62022-08-31 17:03:26 -0700491 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
492 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
493
Derek Tan89e89d42014-07-08 17:00:10 -0700494 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700495 * Experiment flag to enable erase modem config on reset network, default value is false
496 */
497 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
498 "reset_network_erase_modem_config_enabled";
499
Rambo Wang0f050d82021-02-12 11:43:36 -0800500 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800501
Gary Jian76280a42022-12-07 16:18:33 +0800502 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
503
sandeepjsb6c87872021-09-27 15:34:44 +0000504 /**
505 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
506 * one ICCID active at the same time.
507 * Apps should use below API signatures if targeting SDK is T and beyond.
508 *
509 * @hide
510 */
511 @ChangeId
512 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
513 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800514
Naina Nallurid63128d2019-09-17 14:10:30 -0700515 /**
Chen Xu540470b2021-12-14 17:15:47 -0800516 * Apps targeting on Android T and beyond will get exception whenever icc close channel
517 * operation fails.
518 */
519 @ChangeId
520 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
521 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
522
523 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700524 * A request object to use for transmitting data to an ICC.
525 */
526 private static final class IccAPDUArgument {
527 public int channel, cla, command, p1, p2, p3;
528 public String data;
529
530 public IccAPDUArgument(int channel, int cla, int command,
531 int p1, int p2, int p3, String data) {
532 this.channel = channel;
533 this.cla = cla;
534 this.command = command;
535 this.p1 = p1;
536 this.p2 = p2;
537 this.p3 = p3;
538 this.data = data;
539 }
540 }
541
542 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700543 * A request object to use for transmitting data to an ICC.
544 */
545 private static final class ManualNetworkSelectionArgument {
546 public OperatorInfo operatorInfo;
547 public boolean persistSelection;
548
549 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
550 this.operatorInfo = operatorInfo;
551 this.persistSelection = persistSelection;
552 }
553 }
554
Sarah Chin71b3a852022-09-28 15:54:19 -0700555 private static final class PurchasePremiumCapabilityArgument {
556 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700557 public @NonNull IIntegerConsumer callback;
558
559 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800560 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700561 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700562 this.callback = callback;
563 }
564 }
565
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800566 private static final class ProvisionSatelliteServiceArgument {
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800567 public @NonNull String token;
568 public @NonNull Consumer<Integer> callback;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800569 public int subId;
570
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800571 ProvisionSatelliteServiceArgument(String token, Consumer<Integer> callback, int subId) {
572 this.token = token;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800573 this.callback = callback;
574 this.subId = subId;
575 }
576 }
577
Sarah Chineccfbd12023-01-20 19:00:35 -0800578 private static final class SatellitePositionUpdateHandler extends Handler {
579 public static final int EVENT_POSITION_UPDATE = 1;
580 public static final int EVENT_MESSAGE_TRANSFER_STATE_UPDATE = 2;
581
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800582 private final ISatelliteStateListener mCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800583
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800584 SatellitePositionUpdateHandler(ISatelliteStateListener callback, Looper looper) {
Sarah Chineccfbd12023-01-20 19:00:35 -0800585 super(looper);
586 mCallback = callback;
587 }
588
589 @Override
590 public void handleMessage(@NonNull Message msg) {
591 switch (msg.what) {
592 case EVENT_POSITION_UPDATE: {
593 AsyncResult ar = (AsyncResult) msg.obj;
594 PointingInfo pointingInfo = (PointingInfo) ar.result;
595 try {
596 mCallback.onSatellitePositionUpdate(pointingInfo);
597 } catch (RemoteException e) {
598 loge("EVENT_POSITION_UPDATE RemoteException: " + e);
599 }
600 break;
601 }
602 case EVENT_MESSAGE_TRANSFER_STATE_UPDATE: {
603 AsyncResult ar = (AsyncResult) msg.obj;
604 int state = (int) ar.result;
605 try {
606 mCallback.onMessageTransferStateUpdate(state);
607 } catch (RemoteException e) {
608 loge("EVENT_MESSAGE_TRANSFER_STATE_UPDATE RemoteException: " + e);
609 }
610 break;
611 }
612 default:
613 loge("SatellitePositionUpdateHandler unknown event: " + msg.what);
614 }
615 }
616 }
617
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800618 private static final class SatelliteProvisionStateChangedHandler extends Handler {
619 public static final int EVENT_PROVISION_STATE_CHANGED = 1;
620
621 private ConcurrentHashMap<IBinder, ISatelliteStateListener> mListeners;
622 private final int mSubId;
623
624 SatelliteProvisionStateChangedHandler(Looper looper, int subId) {
625 super(looper);
626 mListeners = new ConcurrentHashMap<>();
627 mSubId = subId;
628 }
629
630 public void addListener(ISatelliteStateListener listener) {
631 mListeners.put(listener.asBinder(), listener);
632 }
633
634 public boolean removeListener(ISatelliteStateListener listener) {
635 return (mListeners.remove(listener.asBinder()) != null);
636 }
637
638 @Override
639 public void handleMessage(@NonNull Message msg) {
640 switch (msg.what) {
641 case EVENT_PROVISION_STATE_CHANGED: {
642 AsyncResult ar = (AsyncResult) msg.obj;
643 boolean provisioned = (boolean) ar.userObj;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800644 log("Received EVENT_PROVISION_STATE_CHANGED for subId=" + mSubId
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800645 + ", provisioned=" + provisioned);
646 mListeners.values().forEach(listener -> {
647 try {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -0800648 listener.onSatelliteProvisionStateChanged(provisioned);
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800649 } catch (RemoteException e) {
650 log("EVENT_PROVISION_STATE_CHANGED RemoteException: " + e);
651 }
652 });
653
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800654 setSatelliteProvisioned(provisioned);
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800655 /**
656 * TODO: Take bugreport if provisioned is true and user did not initiate the
657 * provision procedure for the corresponding subscription.
658 */
659 break;
660 }
661 default:
662 loge("SatelliteProvisionStateChangedHandler unknown event: " + msg.what);
663 }
664 }
665
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800666 private void setSatelliteProvisioned(boolean isProvisioned) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800667 if (mSubId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
668 SubscriptionManager.setSubscriptionProperty(
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800669 mSubId, SubscriptionManager.SATELLITE_ENABLED, isProvisioned ? "1" : "0");
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800670 } else {
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800671 //TODO (b/267826133): set via SatelliteController.
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800672 }
673 }
674 }
675
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000676 private static final class SatelliteStateListenerHandler extends Handler {
677 public static final int EVENT_SATELLITE_MODEM_STATE_CHANGE = 1;
678 public static final int EVENT_PENDING_MESSAGE_COUNT = 2;
679
680 private ConcurrentHashMap<IBinder, ISatelliteStateListener> mListeners;
681 private final int mSubId;
682
683 SatelliteStateListenerHandler(Looper looper, int subId) {
684 super(looper);
685 mSubId = subId;
686 mListeners = new ConcurrentHashMap<>();
687 }
688
689 public void addListener(ISatelliteStateListener listener) {
690 mListeners.put(listener.asBinder(), listener);
691 }
692
693 public boolean removeListener(ISatelliteStateListener listener) {
694 return (mListeners.remove(listener.asBinder()) != null);
695 }
696
697 @Override
698 public void handleMessage(@NonNull Message msg) {
699 switch (msg.what) {
700 case EVENT_SATELLITE_MODEM_STATE_CHANGE : {
701 AsyncResult ar = (AsyncResult) msg.obj;
702 int state = (int) ar.result;
703 log("Received EVENT_SATELLITE_MODEM_STATE_CHANGE for subId=" + mSubId
704 + ", state=" + state);
705 mListeners.values().forEach(listener -> {
706 try {
707 listener.onSatelliteModemStateChange(state);
708 } catch (RemoteException e) {
709 log("EVENT_SATELLITE_MODEM_STATE_CHANGE RemoteException: " + e);
710 }
711 });
712 break;
713 }
714 case EVENT_PENDING_MESSAGE_COUNT: {
715 AsyncResult ar = (AsyncResult) msg.obj;
716 int count = (int) ar.result;
717 log("Received EVENT_PENDING_MESSAGE_COUNT for subId=" + mSubId
718 + ", count=" + count);
719 mListeners.values().forEach(listener -> {
720 try {
721 listener.onPendingMessageCount(count);
722 } catch (RemoteException e) {
723 log("EVENT_PENDING_MESSAGE_COUNT RemoteException: " + e);
724 }
725 });
726 break;
727 }
728 default:
729 loge("SatelliteStateListenerHandler unknown event: " + msg.what);
730 }
731 }
732 }
733
734 private static final class SatelliteDatagramListenerHandler extends Handler {
735 public static final int EVENT_SATELLITE_DATAGRAMS_RECEIVED = 1;
736
737 private ConcurrentHashMap<IBinder, ISatelliteStateListener> mListeners;
738 private final int mSubId;
739
740 SatelliteDatagramListenerHandler(Looper looper, int subId) {
741 super(looper);
742 mSubId = subId;
743 mListeners = new ConcurrentHashMap<>();
744 }
745
746 public void addListener(ISatelliteStateListener listener) {
747 mListeners.put(listener.asBinder(), listener);
748 }
749
750 public boolean removeListener(ISatelliteStateListener listener) {
751 return (mListeners.remove(listener.asBinder()) != null);
752 }
753
754 @Override
755 public void handleMessage(@NonNull Message msg) {
756 switch (msg.what) {
757 case EVENT_SATELLITE_DATAGRAMS_RECEIVED : {
758 AsyncResult ar = (AsyncResult) msg.obj;
759 byte[][] datagrams = (byte[][]) ar.result;
760 SatelliteDatagram[] satelliteDatagramArray =
761 convertToSatelliteDatagramArray(datagrams);
762
763 log("Received EVENT_SATELLITE_DATAGRAMS_RECEIVED for subId=" + mSubId);
764 mListeners.values().forEach(listener -> {
765 try {
766 listener.onSatelliteDatagrams(satelliteDatagramArray);
767 } catch (RemoteException e) {
768 log("EVENT_SATELLITE_DATAGRAMS_RECEIVED RemoteException: " + e);
769 }
770 });
771 break;
772 }
773 default:
774 loge("SatelliteDatagramListenerHandler unknown event: " + msg.what);
775 }
776 }
777 }
778
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700779 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700780 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
781 * request after sending. The main thread will notify the request when it is complete.
782 */
783 private static final class MainThreadRequest {
784 /** The argument to use for the request */
785 public Object argument;
786 /** The result of the request that is run on the main thread */
787 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800788 // The subscriber id that this request applies to. Defaults to
789 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
790 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700791
Nathan Harold92bed182018-10-12 18:16:49 -0700792 // In cases where subId is unavailable, the caller needs to specify the phone.
793 public Phone phone;
794
vagdeviaf9a5b92018-08-15 16:01:53 -0700795 public WorkSource workSource;
796
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700797 public MainThreadRequest(Object argument) {
798 this.argument = argument;
799 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800800
Nathan Harold92bed182018-10-12 18:16:49 -0700801 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
802 this.argument = argument;
803 if (phone != null) {
804 this.phone = phone;
805 }
806 this.workSource = workSource;
807 }
808
vagdeviaf9a5b92018-08-15 16:01:53 -0700809 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800810 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800811 if (subId != null) {
812 this.subId = subId;
813 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700814 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800815 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700816 }
817
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800818 private static final class IncomingThirdPartyCallArgs {
819 public final ComponentName component;
820 public final String callId;
821 public final String callerDisplayName;
822
823 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
824 String callerDisplayName) {
825 this.component = component;
826 this.callId = callId;
827 this.callerDisplayName = callerDisplayName;
828 }
829 }
830
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700831 /**
832 * A handler that processes messages on the main thread in the phone process. Since many
833 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
834 * inbound binder threads to the main thread in the phone process. The Binder thread
835 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
836 * on, which will be notified when the operation completes and will contain the result of the
837 * request.
838 *
839 * <p>If a MainThreadRequest object is provided in the msg.obj field,
840 * note that request.result must be set to something non-null for the calling thread to
841 * unblock.
842 */
843 private final class MainThreadHandler extends Handler {
844 @Override
845 public void handleMessage(Message msg) {
846 MainThreadRequest request;
847 Message onCompleted;
848 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000849 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700850 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800851 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700852
853 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700854 case CMD_HANDLE_USSD_REQUEST: {
855 request = (MainThreadRequest) msg.obj;
856 final Phone phone = getPhoneFromRequest(request);
857 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800858 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700859 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700860
Pengquan Menga1bb6272018-09-06 09:59:22 -0700861 if (!isUssdApiAllowed(request.subId)) {
862 // Carrier does not support use of this API, return failure.
863 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
864 UssdResponse response = new UssdResponse(ussdRequest, null);
865 Bundle returnData = new Bundle();
866 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
867 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700868
Pengquan Menga1bb6272018-09-06 09:59:22 -0700869 request.result = true;
870 notifyRequester(request);
871 return;
872 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700873
Pengquan Menga1bb6272018-09-06 09:59:22 -0700874 try {
875 request.result = phone != null
876 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
877 } catch (CallStateException cse) {
878 request.result = false;
879 }
880 // Wake up the requesting thread
881 notifyRequester(request);
882 break;
pkanwar32d516d2016-10-14 19:37:38 -0700883 }
884
Yorke Lee716f67e2015-06-17 15:39:16 -0700885 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700886 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700887 final Phone phone = getPhoneFromRequest(request);
888 request.result = phone != null ?
889 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
890 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700891 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700892 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700893 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700894 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700895
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700896 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700897 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700898 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000899 uiccPort = getUiccPortFromRequest(request);
900 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700901 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800902 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700903 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700904 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700905 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800906 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000907 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800908 iccArgument.channel, iccArgument.cla, iccArgument.command,
909 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
910 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700911 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700912 break;
913
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700914 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700915 ar = (AsyncResult) msg.obj;
916 request = (MainThreadRequest) ar.userObj;
917 if (ar.exception == null && ar.result != null) {
918 request.result = ar.result;
919 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800920 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700921 if (ar.result == null) {
922 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800923 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700924 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800925 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700926 } else {
927 loge("iccTransmitApduLogicalChannel: Unknown exception");
928 }
929 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700930 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700931 break;
932
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700933 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
934 request = (MainThreadRequest) msg.obj;
935 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000936 uiccPort = getUiccPortFromRequest(request);
937 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700938 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800939 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700940 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700941 } else {
942 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800943 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000944 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800945 iccArgument.cla, iccArgument.command, iccArgument.p1,
946 iccArgument.p2,
947 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700948 }
949 break;
950
951 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
952 ar = (AsyncResult) msg.obj;
953 request = (MainThreadRequest) ar.userObj;
954 if (ar.exception == null && ar.result != null) {
955 request.result = ar.result;
956 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800957 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700958 if (ar.result == null) {
959 loge("iccTransmitApduBasicChannel: Empty response");
960 } else if (ar.exception instanceof CommandException) {
961 loge("iccTransmitApduBasicChannel: CommandException: " +
962 ar.exception);
963 } else {
964 loge("iccTransmitApduBasicChannel: Unknown exception");
965 }
966 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700967 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700968 break;
969
970 case CMD_EXCHANGE_SIM_IO:
971 request = (MainThreadRequest) msg.obj;
972 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000973 uiccPort = getUiccPortFromRequest(request);
974 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700975 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800976 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700977 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700978 } else {
979 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
980 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000981 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700982 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
983 iccArgument.data, onCompleted);
984 }
985 break;
986
987 case EVENT_EXCHANGE_SIM_IO_DONE:
988 ar = (AsyncResult) msg.obj;
989 request = (MainThreadRequest) ar.userObj;
990 if (ar.exception == null && ar.result != null) {
991 request.result = ar.result;
992 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800993 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700994 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700995 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700996 break;
997
Derek Tan4d5e5c12014-02-04 11:54:58 -0800998 case CMD_SEND_ENVELOPE:
999 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001000 uiccPort = getUiccPortFromRequest(request);
1001 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001002 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -08001003 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001004 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001005 } else {
1006 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -08001007 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001008 }
Derek Tan4d5e5c12014-02-04 11:54:58 -08001009 break;
1010
1011 case EVENT_SEND_ENVELOPE_DONE:
1012 ar = (AsyncResult) msg.obj;
1013 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -07001014 if (ar.exception == null && ar.result != null) {
1015 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -08001016 } else {
Chen Xue9d737e2022-01-01 23:41:31 -08001017 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -07001018 if (ar.result == null) {
1019 loge("sendEnvelopeWithStatus: Empty response");
1020 } else if (ar.exception instanceof CommandException) {
1021 loge("sendEnvelopeWithStatus: CommandException: " +
1022 ar.exception);
1023 } else {
1024 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
1025 }
Derek Tan4d5e5c12014-02-04 11:54:58 -08001026 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001027 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -08001028 break;
1029
Shishir Agrawal566b7612013-10-28 14:41:00 -07001030 case CMD_OPEN_CHANNEL:
1031 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001032 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -08001033 IccLogicalChannelRequest openChannelRequest =
1034 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001035 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001036 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -08001037 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -08001038 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001039 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001040 } else {
1041 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -08001042 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
1043 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001044 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001045 break;
1046
1047 case EVENT_OPEN_CHANNEL_DONE:
1048 ar = (AsyncResult) msg.obj;
1049 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001050 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -07001051 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001052 int[] result = (int[]) ar.result;
1053 int channelId = result[0];
1054 byte[] selectResponse = null;
1055 if (result.length > 1) {
1056 selectResponse = new byte[result.length - 1];
1057 for (int i = 1; i < result.length; ++i) {
1058 selectResponse[i - 1] = (byte) result[i];
1059 }
1060 }
1061 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -08001062 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -08001063
1064 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -07001065 if (uiccPort == null) {
1066 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
1067 } else {
1068 IccLogicalChannelRequest channelRequest =
1069 (IccLogicalChannelRequest) request.argument;
1070 channelRequest.channel = channelId;
1071 uiccPort.onLogicalChannelOpened(channelRequest);
1072 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001073 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -07001074 if (ar.result == null) {
1075 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -07001076 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001077 if (ar.exception != null) {
1078 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
1079 }
1080
Shishir Agrawal527e8bf2014-08-25 08:54:56 -07001081 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -07001082 if (ar.exception instanceof CommandException) {
1083 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -08001084 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -07001085 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -07001086 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -07001087 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -07001088 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001089 }
1090 }
1091 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -08001092 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001093 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -07001094 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001095 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001096 break;
1097
1098 case CMD_CLOSE_CHANNEL:
1099 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001100 uiccPort = getUiccPortFromRequest(request);
1101 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001102 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -08001103 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001104 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -08001105 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001106 } else {
1107 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001108 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001109 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001110 break;
1111
1112 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -08001113 ar = (AsyncResult) msg.obj;
1114 request = (MainThreadRequest) ar.userObj;
1115 if (ar.exception == null) {
1116 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -08001117 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -07001118 if (uiccPort == null) {
1119 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
1120 } else {
1121 final int channelId = (Integer) request.argument;
1122 uiccPort.onLogicalChannelClosed(channelId);
1123 }
Chen Xu540470b2021-12-14 17:15:47 -08001124 } else {
1125 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -08001126 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -08001127 if (ar.exception instanceof CommandException) {
1128 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
1129 CommandException.Error error =
1130 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -08001131 if (error == CommandException.Error.INVALID_ARGUMENTS) {
1132 // should only throw exceptions from the binder threads.
1133 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -08001134 "iccCloseLogicalChannel: invalid argument ");
1135 }
1136 } else {
1137 loge("iccCloseLogicalChannel: Unknown exception");
1138 }
Chen Xua8f0dff2022-02-12 00:34:15 -08001139 request.result = (exception != null) ? exception :
1140 new IllegalStateException(
1141 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -08001142 }
1143 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001144 break;
1145
1146 case CMD_NV_READ_ITEM:
1147 request = (MainThreadRequest) msg.obj;
1148 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001149 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
1150 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -08001151 break;
1152
1153 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -07001154 ar = (AsyncResult) msg.obj;
1155 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -08001156 if (ar.exception == null && ar.result != null) {
1157 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -07001158 } else {
Jake Hambye994d462014-02-03 13:10:13 -08001159 request.result = "";
1160 if (ar.result == null) {
1161 loge("nvReadItem: Empty response");
1162 } else if (ar.exception instanceof CommandException) {
1163 loge("nvReadItem: CommandException: " +
1164 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001165 } else {
Jake Hambye994d462014-02-03 13:10:13 -08001166 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -07001167 }
1168 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001169 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001170 break;
1171
Jake Hambye994d462014-02-03 13:10:13 -08001172 case CMD_NV_WRITE_ITEM:
1173 request = (MainThreadRequest) msg.obj;
1174 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
1175 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001176 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -07001177 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -08001178 break;
1179
1180 case EVENT_NV_WRITE_ITEM_DONE:
1181 handleNullReturnEvent(msg, "nvWriteItem");
1182 break;
1183
1184 case CMD_NV_WRITE_CDMA_PRL:
1185 request = (MainThreadRequest) msg.obj;
1186 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001187 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -08001188 break;
1189
1190 case EVENT_NV_WRITE_CDMA_PRL_DONE:
1191 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
1192 break;
1193
chen xu6dac5ab2018-10-26 17:39:23 -07001194 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -08001195 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -07001196 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001197 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -08001198 break;
1199
chen xu6dac5ab2018-10-26 17:39:23 -07001200 case EVENT_RESET_MODEM_CONFIG_DONE:
1201 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -08001202 break;
1203
Sooraj Sasindran37444802020-08-11 10:40:43 -07001204 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
1205 request = (MainThreadRequest) msg.obj;
1206 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
1207 request);
1208 Phone phone = getPhoneFromRequest(request);
1209 if (phone != null) {
1210 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
1211 } else {
1212 loge("isNRDualConnectivityEnabled: No phone object");
1213 request.result = false;
1214 notifyRequester(request);
1215 }
1216 break;
1217 }
1218
1219 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
1220 ar = (AsyncResult) msg.obj;
1221 request = (MainThreadRequest) ar.userObj;
1222 if (ar.exception == null && ar.result != null) {
1223 request.result = ar.result;
1224 } else {
1225 // request.result must be set to something non-null
1226 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001227 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -07001228 request.result = ar.result;
1229 } else {
1230 request.result = false;
1231 }
1232 if (ar.result == null) {
1233 loge("isNRDualConnectivityEnabled: Empty response");
1234 } else if (ar.exception instanceof CommandException) {
1235 loge("isNRDualConnectivityEnabled: CommandException: "
1236 + ar.exception);
1237 } else {
1238 loge("isNRDualConnectivityEnabled: Unknown exception");
1239 }
1240 }
1241 notifyRequester(request);
1242 break;
1243
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001244 case CMD_IS_VONR_ENABLED: {
1245 request = (MainThreadRequest) msg.obj;
1246 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1247 request);
1248 Phone phone = getPhoneFromRequest(request);
1249 if (phone != null) {
1250 phone.isVoNrEnabled(onCompleted, request.workSource);
1251 } else {
1252 loge("isVoNrEnabled: No phone object");
1253 request.result = false;
1254 notifyRequester(request);
1255 }
1256 break;
1257 }
1258
1259 case EVENT_IS_VONR_ENABLED_DONE:
1260 ar = (AsyncResult) msg.obj;
1261 request = (MainThreadRequest) ar.userObj;
1262 if (ar.exception == null && ar.result != null) {
1263 request.result = ar.result;
1264 } else {
1265 // request.result must be set to something non-null
1266 // for the calling thread to unblock
1267 if (ar.result != null) {
1268 request.result = ar.result;
1269 } else {
1270 request.result = false;
1271 }
1272 if (ar.result == null) {
1273 loge("isVoNrEnabled: Empty response");
1274 } else if (ar.exception instanceof CommandException) {
1275 loge("isVoNrEnabled: CommandException: "
1276 + ar.exception);
1277 } else {
1278 loge("isVoNrEnabled: Unknown exception");
1279 }
1280 }
1281 notifyRequester(request);
1282 break;
1283
Sooraj Sasindran37444802020-08-11 10:40:43 -07001284 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1285 request = (MainThreadRequest) msg.obj;
1286 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1287 Phone phone = getPhoneFromRequest(request);
1288 if (phone != null) {
1289 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1290 request.workSource);
1291 } else {
1292 loge("enableNrDualConnectivity: No phone object");
1293 request.result =
1294 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1295 notifyRequester(request);
1296 }
1297 break;
1298 }
1299
1300 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1301 ar = (AsyncResult) msg.obj;
1302 request = (MainThreadRequest) ar.userObj;
1303 if (ar.exception == null) {
1304 request.result =
1305 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1306 } else {
1307 request.result =
1308 TelephonyManager
1309 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1310 if (ar.exception instanceof CommandException) {
1311 CommandException.Error error =
1312 ((CommandException) (ar.exception)).getCommandError();
1313 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1314 request.result =
1315 TelephonyManager
1316 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001317 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1318 request.result =
1319 TelephonyManager
1320 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001321 }
1322 loge("enableNrDualConnectivity" + ": CommandException: "
1323 + ar.exception);
1324 } else {
1325 loge("enableNrDualConnectivity" + ": Unknown exception");
1326 }
1327 }
1328 notifyRequester(request);
1329 break;
1330 }
1331
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001332 case CMD_ENABLE_VONR: {
1333 request = (MainThreadRequest) msg.obj;
1334 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1335 Phone phone = getPhoneFromRequest(request);
1336 if (phone != null) {
1337 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1338 request.workSource);
1339 } else {
1340 loge("setVoNrEnabled: No phone object");
1341 request.result =
1342 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1343 notifyRequester(request);
1344 }
1345 break;
1346 }
1347
1348 case EVENT_ENABLE_VONR_DONE: {
1349 ar = (AsyncResult) msg.obj;
1350 request = (MainThreadRequest) ar.userObj;
1351 if (ar.exception == null) {
1352 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1353 } else {
1354 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1355 if (ar.exception instanceof CommandException) {
1356 CommandException.Error error =
1357 ((CommandException) (ar.exception)).getCommandError();
1358 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1359 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1360 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1361 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1362 } else {
1363 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1364 }
1365 loge("setVoNrEnabled" + ": CommandException: "
1366 + ar.exception);
1367 } else {
1368 loge("setVoNrEnabled" + ": Unknown exception");
1369 }
1370 }
1371 notifyRequester(request);
1372 break;
1373 }
1374
SongFerngWang3ef3e072020-12-21 16:41:52 +08001375 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001376 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001377 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1378 request);
1379 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001380 break;
1381
SongFerngWang3ef3e072020-12-21 16:41:52 +08001382 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001383 ar = (AsyncResult) msg.obj;
1384 request = (MainThreadRequest) ar.userObj;
1385 if (ar.exception == null && ar.result != null) {
1386 request.result = ar.result; // Integer
1387 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301388 // request.result must be set to something non-null
1389 // for the calling thread to unblock
1390 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001391 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001392 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001393 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001394 loge("getAllowedNetworkTypesBitmask: CommandException: "
1395 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001396 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001397 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001398 }
1399 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001400 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001401 break;
1402
SongFerngWang3ef3e072020-12-21 16:41:52 +08001403 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001404 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001405 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1406 request);
1407 Pair<Integer, Long> reasonWithNetworkTypes =
1408 (Pair<Integer, Long>) request.argument;
1409 getPhoneFromRequest(request).setAllowedNetworkTypes(
1410 reasonWithNetworkTypes.first,
1411 reasonWithNetworkTypes.second,
1412 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001413 break;
1414
SongFerngWang3ef3e072020-12-21 16:41:52 +08001415 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1416 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001417 break;
1418
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001419 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1420 request = (MainThreadRequest)msg.obj;
1421 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001422 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001423 break;
1424
1425 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1426 ar = (AsyncResult)msg.obj;
1427 request = (MainThreadRequest)ar.userObj;
1428 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001429 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001430 break;
1431
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001432 case CMD_SET_VOICEMAIL_NUMBER:
1433 request = (MainThreadRequest) msg.obj;
1434 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1435 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001436 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1437 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001438 break;
1439
1440 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1441 handleNullReturnEvent(msg, "setVoicemailNumber");
1442 break;
1443
Stuart Scott54788802015-03-30 13:18:01 -07001444 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1445 request = (MainThreadRequest) msg.obj;
1446 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1447 request);
1448 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1449 break;
1450
1451 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1452 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1453 break;
1454
Shishir Agrawal302c8692015-06-19 13:49:39 -07001455 case CMD_PERFORM_NETWORK_SCAN:
1456 request = (MainThreadRequest) msg.obj;
1457 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1458 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1459 break;
1460
Hall Liu27d24262020-09-18 19:04:59 -07001461 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001462 request = (MainThreadRequest) msg.obj;
1463 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001464 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1465 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1466 request.argument;
1467 int callForwardingReason = args.first;
1468 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001469 break;
Hall Liu27d24262020-09-18 19:04:59 -07001470 }
1471 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001472 ar = (AsyncResult) msg.obj;
1473 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001474 TelephonyManager.CallForwardingInfoCallback callback =
1475 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1476 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001477 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001478 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001479 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1480 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1481 // Service Class is a bit mask per 3gpp 27.007. Search for
1482 // any service for voice call.
1483 if ((callForwardInfo.serviceClass
1484 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001485 callForwardingInfo = new CallForwardingInfo(
1486 callForwardInfo.status
1487 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001488 callForwardInfo.reason,
1489 callForwardInfo.number,
1490 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001491 break;
1492 }
1493 }
1494 // Didn't find a call forward info for voice call.
1495 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001496 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1497 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001498 }
Hall Liu27d24262020-09-18 19:04:59 -07001499 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001500 } else {
1501 if (ar.result == null) {
1502 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1503 }
1504 if (ar.exception != null) {
1505 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1506 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001507 int errorCode = TelephonyManager
1508 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001509 if (ar.exception instanceof CommandException) {
1510 CommandException.Error error =
1511 ((CommandException) (ar.exception)).getCommandError();
1512 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001513 errorCode = TelephonyManager
1514 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001515 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001516 errorCode = TelephonyManager
1517 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001518 }
1519 }
Hall Liu27d24262020-09-18 19:04:59 -07001520 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001521 }
Shuo Qian4a594052020-01-23 11:59:30 -08001522 break;
Hall Liu27d24262020-09-18 19:04:59 -07001523 }
Shuo Qian4a594052020-01-23 11:59:30 -08001524
Hall Liu27d24262020-09-18 19:04:59 -07001525 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001526 request = (MainThreadRequest) msg.obj;
1527 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001528 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001529 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001530 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1531 request.argument).first;
1532 request.phone.setCallForwardingOption(
1533 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001534 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001535 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001536 callForwardingInfoToSet.getReason(),
1537 callForwardingInfoToSet.getNumber(),
1538 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1539 break;
Hall Liu27d24262020-09-18 19:04:59 -07001540 }
Shuo Qian4a594052020-01-23 11:59:30 -08001541
Hall Liu27d24262020-09-18 19:04:59 -07001542 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001543 ar = (AsyncResult) msg.obj;
1544 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001545 Consumer<Integer> callback =
1546 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1547 request.argument).second;
1548 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001549 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001550 int errorCode = TelephonyManager.CallForwardingInfoCallback
1551 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001552 if (ar.exception instanceof CommandException) {
1553 CommandException.Error error =
1554 ((CommandException) (ar.exception)).getCommandError();
1555 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001556 errorCode = TelephonyManager.CallForwardingInfoCallback
1557 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001558 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001559 errorCode = TelephonyManager.CallForwardingInfoCallback
1560 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001561 }
1562 }
1563 callback.accept(errorCode);
1564 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001565 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001566 }
Shuo Qian4a594052020-01-23 11:59:30 -08001567 break;
Hall Liu27d24262020-09-18 19:04:59 -07001568 }
Shuo Qian4a594052020-01-23 11:59:30 -08001569
Hall Liu27d24262020-09-18 19:04:59 -07001570 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001571 request = (MainThreadRequest) msg.obj;
1572 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1573 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1574 break;
Hall Liu27d24262020-09-18 19:04:59 -07001575 }
Shuo Qian4a594052020-01-23 11:59:30 -08001576
Hall Liu27d24262020-09-18 19:04:59 -07001577 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001578 ar = (AsyncResult) msg.obj;
1579 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001580 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001581 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001582 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001583 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001584 // Service Class is a bit mask per 3gpp 27.007.
1585 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001586 if (callForwardResults.length > 1
1587 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001588 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001589 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001590 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1591 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001592 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001593 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001594 }
1595 } else {
1596 if (ar.result == null) {
1597 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1598 }
1599 if (ar.exception != null) {
1600 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1601 }
1602 if (ar.exception instanceof CommandException) {
1603 CommandException.Error error =
1604 ((CommandException) (ar.exception)).getCommandError();
1605 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001606 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001607 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001608 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1609 callWaitingStatus =
1610 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001611 }
1612 }
1613 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001614 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001615 break;
Hall Liu27d24262020-09-18 19:04:59 -07001616 }
Shuo Qian4a594052020-01-23 11:59:30 -08001617
Hall Liu27d24262020-09-18 19:04:59 -07001618 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001619 request = (MainThreadRequest) msg.obj;
1620 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001621 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1622 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001623 break;
Hall Liu27d24262020-09-18 19:04:59 -07001624 }
Shuo Qian4a594052020-01-23 11:59:30 -08001625
Hall Liu27d24262020-09-18 19:04:59 -07001626 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001627 ar = (AsyncResult) msg.obj;
1628 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001629 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1630 Consumer<Integer> callback =
1631 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1632 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001633 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001634 if (ar.exception instanceof CommandException) {
1635 CommandException.Error error =
1636 ((CommandException) (ar.exception)).getCommandError();
1637 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1638 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001639 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1640 callback.accept(
1641 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001642 } else {
1643 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1644 }
1645 } else {
1646 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1647 }
1648 } else {
1649 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1650 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001651 }
Shuo Qian4a594052020-01-23 11:59:30 -08001652 break;
Hall Liu27d24262020-09-18 19:04:59 -07001653 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001654 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1655 ar = (AsyncResult) msg.obj;
1656 request = (MainThreadRequest) ar.userObj;
1657 CellNetworkScanResult cellScanResult;
1658 if (ar.exception == null && ar.result != null) {
1659 cellScanResult = new CellNetworkScanResult(
1660 CellNetworkScanResult.STATUS_SUCCESS,
1661 (List<OperatorInfo>) ar.result);
1662 } else {
1663 if (ar.result == null) {
1664 loge("getCellNetworkScanResults: Empty response");
1665 }
1666 if (ar.exception != null) {
1667 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1668 }
1669 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1670 if (ar.exception instanceof CommandException) {
1671 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001672 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001673 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1674 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1675 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1676 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1677 }
1678 }
1679 cellScanResult = new CellNetworkScanResult(errorCode, null);
1680 }
1681 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001682 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001683 break;
1684
1685 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1686 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001687 ManualNetworkSelectionArgument selArg =
1688 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001689 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1690 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001691 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1692 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001693 break;
1694
1695 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001696 ar = (AsyncResult) msg.obj;
1697 request = (MainThreadRequest) ar.userObj;
1698 if (ar.exception == null) {
1699 request.result = true;
1700 } else {
1701 request.result = false;
1702 loge("setNetworkSelectionModeManual " + ar.exception);
1703 }
1704 notifyRequester(request);
1705 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001706 break;
1707
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001708 case CMD_GET_MODEM_ACTIVITY_INFO:
1709 request = (MainThreadRequest) msg.obj;
1710 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001711 if (defaultPhone != null) {
1712 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001713 } else {
1714 ResultReceiver result = (ResultReceiver) request.argument;
1715 Bundle bundle = new Bundle();
1716 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001717 new ModemActivityInfo(0, 0, 0,
1718 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001719 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001720 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001721 break;
1722
Hall Liud0f208c2020-10-14 16:54:44 -07001723 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001724 ar = (AsyncResult) msg.obj;
1725 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001726 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001727 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001728 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001729 if (mLastModemActivityInfo == null) {
1730 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1731 mLastModemActivitySpecificInfo[0] =
1732 new ActivityStatsTechSpecificInfo(
1733 0,
1734 0,
1735 new int[ModemActivityInfo.getNumTxPowerLevels()],
1736 0);
1737 mLastModemActivityInfo =
1738 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1739 }
1740
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001741 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001742 // Update the last modem activity info and the result of the request.
1743 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1744 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001745 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001746 } else {
1747 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001748 }
Kai Shi917fdc62022-11-28 14:01:02 -08001749 // This is needed to decouple ret from mLastModemActivityInfo
1750 // We don't want to return mLastModemActivityInfo which is updated
1751 // inside mergeModemActivityInfo()
1752 ret = new ModemActivityInfo(
1753 mLastModemActivityInfo.getTimestampMillis(),
1754 mLastModemActivityInfo.getSleepTimeMillis(),
1755 mLastModemActivityInfo.getIdleTimeMillis(),
1756 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001757
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001758 } else {
1759 if (ar.result == null) {
1760 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001761 error = TelephonyManager.ModemActivityInfoException
1762 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001763 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001764 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001765 error = TelephonyManager.ModemActivityInfoException
1766 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001767 } else {
1768 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001769 error = TelephonyManager.ModemActivityInfoException
1770 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001771 }
1772 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001773 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001774 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001775 bundle.putParcelable(
1776 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001777 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001778 } else {
1779 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1780 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001781 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001782 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001783 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001784 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001785
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001786 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001787 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001788 CarrierRestrictionRules argument =
1789 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001790 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001791 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001792 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001793 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001794
1795 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1796 ar = (AsyncResult) msg.obj;
1797 request = (MainThreadRequest) ar.userObj;
1798 if (ar.exception == null && ar.result != null) {
1799 request.result = ar.result;
1800 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001801 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1802 if (ar.exception instanceof CommandException) {
1803 loge("setAllowedCarriers: CommandException: " + ar.exception);
1804 CommandException.Error error =
1805 ((CommandException) (ar.exception)).getCommandError();
1806 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1807 request.result =
1808 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1809 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001810 } else {
1811 loge("setAllowedCarriers: Unknown exception");
1812 }
1813 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001814 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001815 break;
1816
1817 case CMD_GET_ALLOWED_CARRIERS:
1818 request = (MainThreadRequest) msg.obj;
1819 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001820 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001821 break;
1822
1823 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1824 ar = (AsyncResult) msg.obj;
1825 request = (MainThreadRequest) ar.userObj;
1826 if (ar.exception == null && ar.result != null) {
1827 request.result = ar.result;
1828 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001829 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001830 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001831 if (ar.result == null) {
1832 loge("getAllowedCarriers: Empty response");
1833 } else if (ar.exception instanceof CommandException) {
1834 loge("getAllowedCarriers: CommandException: " +
1835 ar.exception);
1836 } else {
1837 loge("getAllowedCarriers: Unknown exception");
1838 }
1839 }
arunvoddud7401012022-12-15 16:08:12 +00001840 if (request.argument != null) {
1841 // This is for the implementation of carrierRestrictionStatus.
1842 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1843 Consumer<Integer> callback = callbackInfo.getConsumer();
1844 int callerCarrierId = callbackInfo.getCarrierId();
1845 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1846 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1847 CarrierRestrictionRules carrierRestrictionRules =
1848 (CarrierRestrictionRules) ar.result;
1849 int carrierId = -1;
1850 try {
1851 CarrierIdentifier carrierIdentifier =
1852 carrierRestrictionRules.getAllowedCarriers().get(0);
1853 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1854 carrierIdentifier);
1855 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1856 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1857 }
1858 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1859 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1860 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001861 lockStatus = TelephonyManager
1862 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001863 }
1864 } else {
1865 Rlog.e(LOG_TAG,
1866 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1867 }
1868 callback.accept(lockStatus);
1869 } else {
1870 // This is for the implementation of getAllowedCarriers.
1871 notifyRequester(request);
1872 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001873 break;
1874
Nathan Haroldb3014052017-01-25 15:57:32 -08001875 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1876 ar = (AsyncResult) msg.obj;
1877 request = (MainThreadRequest) ar.userObj;
1878 if (ar.exception == null && ar.result != null) {
1879 request.result = ar.result;
1880 } else {
1881 request.result = new IllegalArgumentException(
1882 "Failed to retrieve Forbidden Plmns");
1883 if (ar.result == null) {
1884 loge("getForbiddenPlmns: Empty response");
1885 } else {
1886 loge("getForbiddenPlmns: Unknown exception");
1887 }
1888 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001889 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001890 break;
1891
1892 case CMD_GET_FORBIDDEN_PLMNS:
1893 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001894 uiccPort = getUiccPortFromRequest(request);
1895 if (uiccPort == null) {
1896 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001897 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001898 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001899 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001900 break;
1901 }
1902 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001903 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001904 if (uiccApp == null) {
1905 loge("getForbiddenPlmns() no app with specified type -- "
1906 + appType);
1907 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001908 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001909 break;
1910 } else {
1911 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1912 + " specified type -- " + appType);
1913 }
1914 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1915 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001916 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001917 break;
1918
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001919 case CMD_SWITCH_SLOTS:
1920 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001921 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001922 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001923 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001924 break;
1925
1926 case EVENT_SWITCH_SLOTS_DONE:
1927 ar = (AsyncResult) msg.obj;
1928 request = (MainThreadRequest) ar.userObj;
1929 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001930 notifyRequester(request);
1931 break;
1932 case CMD_GET_NETWORK_SELECTION_MODE:
1933 request = (MainThreadRequest) msg.obj;
1934 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1935 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1936 break;
1937
1938 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1939 ar = (AsyncResult) msg.obj;
1940 request = (MainThreadRequest) ar.userObj;
1941 if (ar.exception != null) {
1942 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1943 } else {
1944 int mode = ((int[]) ar.result)[0];
1945 if (mode == 0) {
1946 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1947 } else {
1948 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1949 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001950 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001951 notifyRequester(request);
1952 break;
1953 case CMD_GET_CDMA_ROAMING_MODE:
1954 request = (MainThreadRequest) msg.obj;
1955 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1956 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1957 break;
1958 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1959 ar = (AsyncResult) msg.obj;
1960 request = (MainThreadRequest) ar.userObj;
1961 if (ar.exception != null) {
1962 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1963 } else {
1964 request.result = ((int[]) ar.result)[0];
1965 }
1966 notifyRequester(request);
1967 break;
1968 case CMD_SET_CDMA_ROAMING_MODE:
1969 request = (MainThreadRequest) msg.obj;
1970 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1971 int mode = (int) request.argument;
1972 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1973 break;
1974 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1975 ar = (AsyncResult) msg.obj;
1976 request = (MainThreadRequest) ar.userObj;
1977 request.result = ar.exception == null;
1978 notifyRequester(request);
1979 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001980 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1981 request = (MainThreadRequest) msg.obj;
1982 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1983 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1984 break;
1985 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1986 ar = (AsyncResult) msg.obj;
1987 request = (MainThreadRequest) ar.userObj;
1988 if (ar.exception != null) {
1989 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1990 } else {
1991 request.result = ((int[]) ar.result)[0];
1992 }
1993 notifyRequester(request);
1994 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001995 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1996 request = (MainThreadRequest) msg.obj;
1997 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1998 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001999 getPhoneFromRequest(request).setCdmaSubscriptionMode(
2000 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07002001 break;
2002 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
2003 ar = (AsyncResult) msg.obj;
2004 request = (MainThreadRequest) ar.userObj;
2005 request.result = ar.exception == null;
2006 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00002007 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07002008 case CMD_GET_ALL_CELL_INFO:
2009 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07002010 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07002011 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07002012 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07002013 case EVENT_GET_ALL_CELL_INFO_DONE:
2014 ar = (AsyncResult) msg.obj;
2015 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07002016 // If a timeout occurs, the response will be null
2017 request.result = (ar.exception == null && ar.result != null)
2018 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07002019 synchronized (request) {
2020 request.notifyAll();
2021 }
2022 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002023 case CMD_REQUEST_CELL_INFO_UPDATE:
2024 request = (MainThreadRequest) msg.obj;
2025 request.phone.requestCellInfoUpdate(request.workSource,
2026 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
2027 break;
2028 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
2029 ar = (AsyncResult) msg.obj;
2030 request = (MainThreadRequest) ar.userObj;
2031 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
2032 try {
2033 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002034 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07002035 cb.onError(
2036 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
2037 ar.exception.getClass().getName(),
2038 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002039 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002040 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07002041 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002042 } else {
2043 // use the result as returned
2044 cb.onCellInfo((List<CellInfo>) ar.result);
2045 }
2046 } catch (RemoteException re) {
2047 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
2048 }
2049 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08002050 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07002051 request = (MainThreadRequest) msg.obj;
2052 WorkSource ws = (WorkSource) request.argument;
2053 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08002054 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07002055 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08002056 }
2057 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07002058 ar = (AsyncResult) msg.obj;
2059 request = (MainThreadRequest) ar.userObj;
2060 if (ar.exception == null) {
2061 request.result = ar.result;
2062 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08002063 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07002064 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08002065 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07002066 }
2067
2068 synchronized (request) {
2069 request.notifyAll();
2070 }
2071 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08002072 }
chen xu6dac5ab2018-10-26 17:39:23 -07002073 case CMD_MODEM_REBOOT:
2074 request = (MainThreadRequest) msg.obj;
2075 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002076 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07002077 break;
chen xu6dac5ab2018-10-26 17:39:23 -07002078 case EVENT_CMD_MODEM_REBOOT_DONE:
2079 handleNullReturnEvent(msg, "rebootModem");
2080 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002081 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002082 request = (MainThreadRequest) msg.obj;
2083 boolean enable = (boolean) request.argument;
2084 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08002085 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002086 PhoneConfigurationManager.getInstance()
2087 .enablePhone(request.phone, enable, onCompleted);
2088 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002089 }
Michele Berionne5e411512020-11-13 02:36:59 +00002090 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002091 ar = (AsyncResult) msg.obj;
2092 request = (MainThreadRequest) ar.userObj;
2093 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07002094 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08002095 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07002096 if ((boolean) request.result) {
2097 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
2098 updateModemStateMetrics();
2099 } else {
2100 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
2101 + ar.exception);
2102 }
2103 notifyRequester(request);
2104 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002105 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07002106 case CMD_GET_MODEM_STATUS:
2107 request = (MainThreadRequest) msg.obj;
2108 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
2109 PhoneConfigurationManager.getInstance()
2110 .getPhoneStatusFromModem(request.phone, onCompleted);
2111 break;
2112 case EVENT_GET_MODEM_STATUS_DONE:
2113 ar = (AsyncResult) msg.obj;
2114 request = (MainThreadRequest) ar.userObj;
2115 int id = request.phone.getPhoneId();
2116 if (ar.exception == null && ar.result != null) {
2117 request.result = ar.result;
2118 //update the cache as modem status has changed
2119 mPhoneConfigurationManager.addToPhoneStatusCache(id,
2120 (boolean) request.result);
2121 } else {
2122 // Return true if modem status cannot be retrieved. For most cases,
2123 // modem status is on. And for older version modems, GET_MODEM_STATUS
2124 // and disable modem are not supported. Modem is always on.
2125 // TODO: this should be fixed in R to support a third
2126 // status UNKNOWN b/131631629
2127 request.result = true;
2128 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
2129 + ar.exception);
2130 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002131 notifyRequester(request);
2132 break;
Hall Liu73f5d362020-01-20 13:42:00 -08002133 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
2134 request = (MainThreadRequest) msg.obj;
2135 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
2136 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
2137 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
2138 request.phone.setSystemSelectionChannels(args.first, onCompleted);
2139 break;
2140 }
2141 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
2142 ar = (AsyncResult) msg.obj;
2143 request = (MainThreadRequest) ar.userObj;
2144 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
2145 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
2146 args.second.accept(ar.exception == null);
2147 notifyRequester(request);
2148 break;
2149 }
Sarah Chin679c08a2020-11-18 13:39:35 -08002150 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
2151 request = (MainThreadRequest) msg.obj;
2152 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
2153 Phone phone = getPhoneFromRequest(request);
2154 if (phone != null) {
2155 phone.getSystemSelectionChannels(onCompleted);
2156 } else {
2157 loge("getSystemSelectionChannels: No phone object");
2158 request.result = new ArrayList<RadioAccessSpecifier>();
2159 notifyRequester(request);
2160 }
2161 break;
2162 }
2163 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
2164 ar = (AsyncResult) msg.obj;
2165 request = (MainThreadRequest) ar.userObj;
2166 if (ar.exception == null && ar.result != null) {
2167 request.result = ar.result;
2168 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08002169 request.result = new IllegalStateException(
2170 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08002171 if (ar.result == null) {
2172 loge("getSystemSelectionChannels: Empty response");
2173 } else {
2174 loge("getSystemSelectionChannels: Unknown exception");
2175 }
2176 }
2177 notifyRequester(request);
2178 break;
yincheng zhao2737e882019-09-06 17:06:54 -07002179 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
2180 ar = (AsyncResult) msg.obj;
2181 request = (MainThreadRequest) ar.userObj;
2182 if (ar.exception == null && ar.result != null) {
2183 request.result = ar.result;
2184 } else {
2185 request.result = -1;
2186 loge("Failed to set Forbidden Plmns");
2187 if (ar.result == null) {
2188 loge("setForbidenPlmns: Empty response");
2189 } else if (ar.exception != null) {
2190 loge("setForbiddenPlmns: Exception: " + ar.exception);
2191 request.result = -1;
2192 } else {
2193 loge("setForbiddenPlmns: Unknown exception");
2194 }
2195 }
2196 notifyRequester(request);
2197 break;
2198 case CMD_SET_FORBIDDEN_PLMNS:
2199 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002200 uiccPort = getUiccPortFromRequest(request);
2201 if (uiccPort == null) {
2202 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07002203 request.result = -1;
2204 notifyRequester(request);
2205 break;
2206 }
2207 Pair<Integer, List<String>> setFplmnsArgs =
2208 (Pair<Integer, List<String>>) request.argument;
2209 appType = setFplmnsArgs.first;
2210 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002211 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07002212 if (uiccApp == null) {
2213 loge("setForbiddenPlmns: no app with specified type -- " + appType);
2214 request.result = -1;
2215 loge("Failed to get UICC App");
2216 notifyRequester(request);
2217 } else {
2218 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
2219 ((SIMRecords) uiccApp.getIccRecords())
2220 .setForbiddenPlmns(onCompleted, fplmns);
2221 }
yinchengzhao4d163c02019-12-12 15:21:47 -08002222 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07002223 case CMD_ERASE_MODEM_CONFIG:
2224 request = (MainThreadRequest) msg.obj;
2225 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
2226 defaultPhone.eraseModemConfig(onCompleted);
2227 break;
2228 case EVENT_ERASE_MODEM_CONFIG_DONE:
2229 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07002230 break;
zoey chene02881a2019-12-30 16:11:23 +08002231
Kai Shif70f46f2021-03-03 13:59:46 -08002232 case CMD_ERASE_DATA_SHARED_PREFERENCES:
2233 request = (MainThreadRequest) msg.obj;
2234 request.result = defaultPhone.eraseDataInSharedPreferences();
2235 notifyRequester(request);
2236 break;
2237
zoey chene02881a2019-12-30 16:11:23 +08002238 case CMD_CHANGE_ICC_LOCK_PASSWORD:
2239 request = (MainThreadRequest) msg.obj;
2240 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
2241 Pair<String, String> changed = (Pair<String, String>) request.argument;
2242 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
2243 changed.first, changed.second, onCompleted);
2244 break;
2245 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2246 ar = (AsyncResult) msg.obj;
2247 request = (MainThreadRequest) ar.userObj;
2248 if (ar.exception == null) {
2249 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002250 // If the operation is successful, update the PIN storage
2251 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2252 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002253 UiccController.getInstance().getPinStorage()
2254 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002255 } else {
2256 request.result = msg.arg1;
2257 }
2258 notifyRequester(request);
2259 break;
2260
Michele Berionne5e411512020-11-13 02:36:59 +00002261 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002262 request = (MainThreadRequest) msg.obj;
2263 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2264 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2265 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2266 enabled.first, enabled.second, onCompleted);
2267 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002268 }
zoey chene02881a2019-12-30 16:11:23 +08002269 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2270 ar = (AsyncResult) msg.obj;
2271 request = (MainThreadRequest) ar.userObj;
2272 if (ar.exception == null) {
2273 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002274 // If the operation is successful, update the PIN storage
2275 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2276 int phoneId = getPhoneFromRequest(request).getPhoneId();
2277 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002278 UiccController.getInstance().getPinStorage()
2279 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002280 } else {
2281 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2282 }
zoey chene02881a2019-12-30 16:11:23 +08002283 } else {
2284 request.result = msg.arg1;
2285 }
Michele Berionne5e411512020-11-13 02:36:59 +00002286
2287
zoey chene02881a2019-12-30 16:11:23 +08002288 notifyRequester(request);
2289 break;
2290
Peter Wangdafb9ac2020-01-15 14:13:38 -08002291 case MSG_NOTIFY_USER_ACTIVITY:
2292 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002293 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002294 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2295 getDefaultPhone().getContext().sendBroadcastAsUser(
2296 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2297 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002298
2299 case CMD_SET_DATA_THROTTLING: {
2300 request = (MainThreadRequest) msg.obj;
2301 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2302 DataThrottlingRequest dataThrottlingRequest =
2303 (DataThrottlingRequest) request.argument;
2304 Phone phone = getPhoneFromRequest(request);
2305 if (phone != null) {
2306 phone.setDataThrottling(onCompleted,
2307 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2308 dataThrottlingRequest.getCompletionDurationMillis());
2309 } else {
2310 loge("setDataThrottling: No phone object");
2311 request.result =
2312 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2313 notifyRequester(request);
2314 }
2315
2316 break;
2317 }
2318 case EVENT_SET_DATA_THROTTLING_DONE:
2319 ar = (AsyncResult) msg.obj;
2320 request = (MainThreadRequest) ar.userObj;
2321
2322 if (ar.exception == null) {
2323 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2324 } else if (ar.exception instanceof CommandException) {
2325 loge("setDataThrottling: CommandException: " + ar.exception);
2326 CommandException.Error error =
2327 ((CommandException) (ar.exception)).getCommandError();
2328
2329 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2330 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002331 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002332 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2333 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002334 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2335 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002336 } else {
2337 request.result =
2338 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2339 }
2340 } else {
2341 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2342 }
2343 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2344 notifyRequester(request);
2345 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002346
2347 case CMD_SET_SIM_POWER: {
2348 request = (MainThreadRequest) msg.obj;
2349 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2350 request = (MainThreadRequest) msg.obj;
2351 int stateToSet =
2352 ((Pair<Integer, IIntegerConsumer>)
2353 request.argument).first;
2354 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2355 break;
2356 }
2357 case EVENT_SET_SIM_POWER_DONE: {
2358 ar = (AsyncResult) msg.obj;
2359 request = (MainThreadRequest) ar.userObj;
2360 IIntegerConsumer callback =
2361 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2362 if (ar.exception != null) {
2363 loge("setSimPower exception: " + ar.exception);
2364 int errorCode = TelephonyManager.CallForwardingInfoCallback
2365 .RESULT_ERROR_UNKNOWN;
2366 if (ar.exception instanceof CommandException) {
2367 CommandException.Error error =
2368 ((CommandException) (ar.exception)).getCommandError();
2369 if (error == CommandException.Error.SIM_ERR) {
2370 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2371 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2372 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2373 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2374 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2375 } else {
2376 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2377 }
2378 }
2379 try {
2380 callback.accept(errorCode);
2381 } catch (RemoteException e) {
2382 // Ignore if the remote process is no longer available to call back.
2383 Log.w(LOG_TAG, "setSimPower: callback not available.");
2384 }
2385 } else {
2386 try {
2387 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2388 } catch (RemoteException e) {
2389 // Ignore if the remote process is no longer available to call back.
2390 Log.w(LOG_TAG, "setSimPower: callback not available.");
2391 }
2392 }
2393 break;
2394 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002395 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2396 request = (MainThreadRequest) msg.obj;
2397
2398 final Phone phone = getPhoneFromRequest(request);
2399 if (phone == null || phone.getServiceStateTracker() == null) {
2400 request.result = new IllegalStateException("Phone or SST is null");
2401 notifyRequester(request);
2402 break;
2403 }
2404
2405 Pair<Integer, SignalStrengthUpdateRequest> pair =
2406 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2407 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2408 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002409 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002410 request.subId, pair.first /*callingUid*/,
2411 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002412 break;
2413 }
2414 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2415 ar = (AsyncResult) msg.obj;
2416 request = (MainThreadRequest) ar.userObj;
2417 // request.result will be the exception of ar if present, true otherwise.
2418 // Be cautious not to leave result null which will wait() forever
2419 request.result = ar.exception != null ? ar.exception : true;
2420 notifyRequester(request);
2421 break;
2422 }
2423 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2424 request = (MainThreadRequest) msg.obj;
2425
2426 Phone phone = getPhoneFromRequest(request);
2427 if (phone == null || phone.getServiceStateTracker() == null) {
2428 request.result = new IllegalStateException("Phone or SST is null");
2429 notifyRequester(request);
2430 break;
2431 }
2432
2433 Pair<Integer, SignalStrengthUpdateRequest> pair =
2434 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2435 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2436 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002437 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002438 request.subId, pair.first /*callingUid*/,
2439 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002440 break;
2441 }
2442 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2443 ar = (AsyncResult) msg.obj;
2444 request = (MainThreadRequest) ar.userObj;
2445 request.result = ar.exception != null ? ar.exception : true;
2446 notifyRequester(request);
2447 break;
2448 }
Jordan Liu109698e2020-11-24 14:50:34 -08002449
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002450 case CMD_GET_SLICING_CONFIG: {
2451 request = (MainThreadRequest) msg.obj;
2452 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2453 request.phone.getSlicingConfig(onCompleted);
2454 break;
2455 }
2456 case EVENT_GET_SLICING_CONFIG_DONE: {
2457 ar = (AsyncResult) msg.obj;
2458 request = (MainThreadRequest) ar.userObj;
2459 ResultReceiver result = (ResultReceiver) request.argument;
2460
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002461 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002462 Bundle bundle = new Bundle();
2463 int resultCode = 0;
2464 if (ar.exception != null) {
2465 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2466 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002467 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002468 } else if (ar.result == null) {
2469 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002470 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002471 } else {
2472 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002473 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2474 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002475 }
2476
2477 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002478 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002479 }
2480 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2481 result.send(resultCode, bundle);
2482 notifyRequester(request);
2483 break;
2484 }
2485
Sarah Chin71b3a852022-09-28 15:54:19 -07002486 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002487 request = (MainThreadRequest) msg.obj;
2488 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002489 PurchasePremiumCapabilityArgument arg =
2490 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002491 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chinb8218c22023-01-04 13:35:29 -08002492 arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002493 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002494 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002495
Sarah Chin71b3a852022-09-28 15:54:19 -07002496 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002497 ar = (AsyncResult) msg.obj;
2498 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002499 PurchasePremiumCapabilityArgument arg =
2500 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002501 try {
2502 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002503 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002504 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002505 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002506 + ", result= "
2507 + TelephonyManager.convertPurchaseResultToString(result));
2508 } catch (RemoteException e) {
2509 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002510 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002511 + " failed: " + e;
2512 if (DBG) log(logStr);
2513 AnomalyReporter.reportAnomaly(
2514 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2515 }
2516 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002517 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002518
Michele Berionne5e411512020-11-13 02:36:59 +00002519 case CMD_PREPARE_UNATTENDED_REBOOT:
2520 request = (MainThreadRequest) msg.obj;
2521 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002522 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002523 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002524 notifyRequester(request);
2525 break;
2526
Sarah Chineccfbd12023-01-20 19:00:35 -08002527 case CMD_START_SATELLITE_POSITION_UPDATES: {
2528 request = (MainThreadRequest) msg.obj;
2529 onCompleted =
2530 obtainMessage(EVENT_START_SATELLITE_POSITION_UPDATES_DONE, request);
2531 Phone phone = getPhoneFromRequest(request);
2532 if (phone != null) {
2533 phone.startSatellitePositionUpdates(onCompleted);
2534 } else {
2535 loge("startSatellitePositionUpdates: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002536 ((Consumer<Integer>) request.argument).accept(
2537 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Sarah Chineccfbd12023-01-20 19:00:35 -08002538 }
2539 break;
2540 }
2541
2542 case EVENT_START_SATELLITE_POSITION_UPDATES_DONE: {
2543 ar = (AsyncResult) msg.obj;
2544 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002545 int error = getSatelliteError(ar, "startSatellitePositionUpdates", false);
2546 ((Consumer<Integer>) request.argument).accept(error);
Sarah Chineccfbd12023-01-20 19:00:35 -08002547 break;
2548 }
2549
2550 case CMD_STOP_SATELLITE_POSITION_UPDATES: {
2551 request = (MainThreadRequest) msg.obj;
2552 onCompleted =
2553 obtainMessage(EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE, request);
2554 Phone phone = getPhoneFromRequest(request);
2555 if (phone != null) {
2556 phone.stopSatellitePositionUpdates(onCompleted);
2557 } else {
2558 loge("stopSatellitePositionUpdates: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002559 ((Consumer<Integer>) request.argument).accept(
2560 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Sarah Chineccfbd12023-01-20 19:00:35 -08002561 }
2562 break;
2563 }
2564
2565 case EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE: {
2566 ar = (AsyncResult) msg.obj;
2567 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002568 int error = getSatelliteError(ar, "stopSatellitePositionUpdates", false);
2569 ((Consumer<Integer>) request.argument).accept(error);
Sarah Chineccfbd12023-01-20 19:00:35 -08002570 break;
2571 }
2572
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002573 case CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG: {
2574 request = (MainThreadRequest) msg.obj;
2575 onCompleted = obtainMessage(EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE,
2576 request);
2577 Phone phone = getPhoneFromRequest(request);
2578 if (phone != null) {
2579 phone.getMaxCharactersPerSatelliteTextMessage(onCompleted);
2580 } else {
2581 loge("getMaxCharactersPerSatelliteTextMessage: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002582 ((ResultReceiver) request.argument).send(
2583 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002584 }
2585 break;
2586 }
2587
2588 case EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE: {
2589 ar = (AsyncResult) msg.obj;
2590 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002591 int error =
2592 getSatelliteError(ar, "getMaxCharactersPerSatelliteTextMessage", true);
2593 Bundle bundle = new Bundle();
2594 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002595 int maxCharLimit = ((int[]) ar.result)[0];
Sarah Chin503828c2023-02-01 23:54:20 -08002596 if (DBG) log("getMaxCharactersPerSatelliteTextMessage: " + maxCharLimit);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002597 bundle.putInt(SatelliteManager.KEY_MAX_CHARACTERS_PER_SATELLITE_TEXT,
2598 maxCharLimit);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002599 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002600 ((ResultReceiver) request.argument).send(error, bundle);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002601 break;
2602 }
2603
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002604 case CMD_PROVISION_SATELLITE_SERVICE: {
2605 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002606 onCompleted = obtainMessage(EVENT_PROVISION_SATELLITE_SERVICE_DONE, request);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002607 Phone phone = getPhoneFromRequest(request);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002608 ProvisionSatelliteServiceArgument argument =
2609 (ProvisionSatelliteServiceArgument) request.argument;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002610 if (phone != null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002611 handleCmdProvisionSatelliteService(argument, phone, onCompleted);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002612 } else {
2613 loge("provisionSatelliteService: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002614 argument.callback.accept(
2615 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002616 notifyRequester(request);
2617 }
2618 break;
2619 }
2620
2621 case EVENT_PROVISION_SATELLITE_SERVICE_DONE: {
2622 ar = (AsyncResult) msg.obj;
2623 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002624 int errorCode = getSatelliteError(ar, "provisionSatelliteService", false);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002625 handleEventProvisionSatelliteServiceDone(
2626 (ProvisionSatelliteServiceArgument) request.argument, errorCode);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002627 notifyRequester(request);
2628 break;
2629 }
2630
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002631 case CMD_DEPROVISION_SATELLITE_SERVICE: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002632 request = (MainThreadRequest) msg.obj;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002633 onCompleted = obtainMessage(EVENT_DEPROVISION_SATELLITE_SERVICE_DONE, request);
2634 Phone phone = getPhoneFromRequest(request);
2635 ProvisionSatelliteServiceArgument argument =
2636 (ProvisionSatelliteServiceArgument) request.argument;
2637 if (phone != null) {
2638 handleCmdDeprovisionSatelliteService(argument, phone, onCompleted);
2639 } else {
2640 loge("deprovisionSatelliteService: No phone object");
2641 if (argument.callback != null) {
2642 argument.callback.accept(
2643 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
2644 }
2645 notifyRequester(request);
2646 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002647 break;
2648 }
2649
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002650 case EVENT_DEPROVISION_SATELLITE_SERVICE_DONE: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002651 ar = (AsyncResult) msg.obj;
2652 request = (MainThreadRequest) ar.userObj;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002653 int errorCode = getSatelliteError(ar, "deprovisionSatelliteService", false);
2654 handleEventDeprovisionSatelliteServiceDone(
2655 (ProvisionSatelliteServiceArgument) request.argument, errorCode);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002656 notifyRequester(request);
2657 break;
2658 }
2659
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002660 case CMD_SET_SATELLITE_ENABLED: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002661 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002662 onCompleted = obtainMessage(EVENT_SET_SATELLITE_ENABLED_DONE, request);
2663 Pair<Boolean, Consumer<Integer>> argument =
2664 (Pair<Boolean, Consumer<Integer>>) request.argument;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002665 Phone phone = getPhoneFromRequest(request);
2666 if (phone != null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002667 boolean enable = argument.first.booleanValue();
2668 phone.setSatellitePower(onCompleted, enable);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002669 } else {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002670 loge("setSatelliteEnabled: No phone object");
2671 argument.second.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002672 notifyRequester(request);
2673 }
2674 break;
2675 }
2676
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002677 case EVENT_SET_SATELLITE_ENABLED_DONE: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002678 ar = (AsyncResult) msg.obj;
2679 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002680 Pair<Boolean, Consumer<Integer>> argument =
2681 (Pair<Boolean, Consumer<Integer>>) request.argument;
2682 int error = getSatelliteError(ar, "setSatelliteEnabled", false);
2683 argument.second.accept(error);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002684 break;
2685 }
2686
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002687 case CMD_IS_SATELLITE_ENABLED: {
Sarah Chin503828c2023-02-01 23:54:20 -08002688 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002689 onCompleted = obtainMessage(EVENT_IS_SATELLITE_ENABLED_DONE, request);
Sarah Chin503828c2023-02-01 23:54:20 -08002690 Phone phone = getPhoneFromRequest(request);
2691 if (phone != null) {
2692 phone.isSatellitePowerOn(onCompleted);
2693 } else {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002694 loge("isSatelliteEnabled: No phone object");
2695 ((ResultReceiver) request.argument).send(
2696 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002697 }
2698 break;
2699 }
2700
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002701 case EVENT_IS_SATELLITE_ENABLED_DONE: {
Sarah Chin503828c2023-02-01 23:54:20 -08002702 ar = (AsyncResult) msg.obj;
2703 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002704 int error = getSatelliteError(ar, "isSatelliteEnabled", true);
2705 Bundle bundle = new Bundle();
2706 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
2707 boolean enabled = ((int[]) ar.result)[0] == 1;
2708 if (DBG) log("isSatelliteEnabled: " + enabled);
2709 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_ENABLED, enabled);
Sarah Chin503828c2023-02-01 23:54:20 -08002710 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002711 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002712 break;
2713 }
2714
2715 case CMD_IS_SATELLITE_SUPPORTED: {
2716 request = (MainThreadRequest) msg.obj;
2717 onCompleted = obtainMessage(EVENT_IS_SATELLITE_SUPPORTED_DONE, request);
2718 Phone phone = getPhoneFromRequest(request);
2719 if (phone != null) {
2720 phone.isSatelliteSupported(onCompleted);
2721 } else {
2722 loge("isSatelliteSupported: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002723 ((ResultReceiver) request.argument).send(
2724 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002725 }
2726 break;
2727 }
2728
2729 case EVENT_IS_SATELLITE_SUPPORTED_DONE: {
2730 ar = (AsyncResult) msg.obj;
2731 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002732 int error = getSatelliteError(ar, "isSatelliteSupported", true);
2733 Bundle bundle = new Bundle();
2734 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
2735 boolean supported = ((int[]) ar.result)[0] == 1;
2736 if (DBG) log("isSatelliteSupported: " + supported);
2737 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, supported);
Thomas Nguyene77de6d2023-02-10 17:42:43 -08002738 synchronized (mIsSatelliteSupportedLock) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002739 mIsSatelliteSupported = supported;
2740 }
2741 } else {
2742 synchronized (mIsSatelliteSupportedLock) {
2743 mIsSatelliteSupported = null;
Thomas Nguyene77de6d2023-02-10 17:42:43 -08002744 }
Sarah Chin503828c2023-02-01 23:54:20 -08002745 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002746 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002747 break;
2748 }
2749
2750 case CMD_GET_SATELLITE_CAPABILITIES: {
2751 request = (MainThreadRequest) msg.obj;
2752 onCompleted = obtainMessage(EVENT_GET_SATELLITE_CAPABILITIES_DONE, request);
2753 Phone phone = getPhoneFromRequest(request);
2754 if (phone != null) {
2755 phone.getSatelliteCapabilities(onCompleted);
2756 } else {
2757 loge("getSatelliteCapabilities: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002758 ((ResultReceiver) request.argument).send(
2759 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002760 }
2761 break;
2762 }
2763
2764 case EVENT_GET_SATELLITE_CAPABILITIES_DONE: {
2765 ar = (AsyncResult) msg.obj;
2766 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002767 int error = getSatelliteError(ar, "getSatelliteCapabilities", true);
2768 Bundle bundle = new Bundle();
2769 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
Sarah Chin503828c2023-02-01 23:54:20 -08002770 SatelliteCapabilities capabilities = (SatelliteCapabilities) ar.result;
2771 if (DBG) log("getSatelliteCapabilities: " + capabilities);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002772 bundle.putParcelable(SatelliteManager.KEY_SATELLITE_CAPABILITIES,
2773 capabilities);
Sarah Chin503828c2023-02-01 23:54:20 -08002774 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002775 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002776 break;
2777 }
2778
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +00002779 case CMD_POLL_PENDING_SATELLITE_DATAGRAMS: {
2780 request = (MainThreadRequest) msg.obj;
2781 onCompleted = obtainMessage(EVENT_POLL_PENDING_SATELLITE_DATAGRAMS_DONE,
2782 request);
2783 Phone phone = getPhoneFromRequest(request);
2784 if (phone != null) {
2785 phone.pollPendingSatelliteDatagrams(onCompleted);
2786 } else {
2787 loge("pollPendingSatelliteDatagrams: No phone object");
2788 request.result = SatelliteManager
2789 .SATELLITE_INVALID_TELEPHONY_STATE;
2790 notifyRequester(request);
2791 }
2792 break;
2793 }
2794
2795 case EVENT_POLL_PENDING_SATELLITE_DATAGRAMS_DONE: {
2796 ar = (AsyncResult) msg.obj;
2797 request = (MainThreadRequest) ar.userObj;
2798 if (ar.exception != null) {
2799 request.result = SatelliteManager.SATELLITE_SERVICE_ERROR;
2800 if (ar.exception instanceof CommandException) {
2801 CommandException.Error error =
2802 ((CommandException) (ar.exception)).getCommandError();
2803 request.result = RILUtils.convertToSatelliteError(error);
2804 loge("pollPendingSatelliteDatagrams: "
2805 + "CommandException: " + ar.exception);
2806 } else {
2807 loge("pollPendingSatelliteDatagrams: "
2808 + "unknown exception:" + ar.exception);
2809 }
2810 } else if (ar.result == null) {
2811 request.result = SatelliteManager
2812 .SATELLITE_INVALID_TELEPHONY_STATE;
2813 loge("pollPendingSatelliteDatagrams: result is null");
2814 } else {
2815 request.result = SatelliteManager.SATELLITE_ERROR_NONE;
2816 }
2817 notifyRequester(request);
2818 break;
2819 }
2820
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002821 default:
2822 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2823 break;
2824 }
2825 }
Jake Hambye994d462014-02-03 13:10:13 -08002826
Pengquan Menga1bb6272018-09-06 09:59:22 -07002827 private void notifyRequester(MainThreadRequest request) {
2828 synchronized (request) {
2829 request.notifyAll();
2830 }
2831 }
2832
Jake Hambye994d462014-02-03 13:10:13 -08002833 private void handleNullReturnEvent(Message msg, String command) {
2834 AsyncResult ar = (AsyncResult) msg.obj;
2835 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2836 if (ar.exception == null) {
2837 request.result = true;
2838 } else {
2839 request.result = false;
2840 if (ar.exception instanceof CommandException) {
2841 loge(command + ": CommandException: " + ar.exception);
2842 } else {
2843 loge(command + ": Unknown exception");
2844 }
2845 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002846 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002847 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002848 }
2849
2850 /**
2851 * Posts the specified command to be executed on the main thread,
2852 * waits for the request to complete, and returns the result.
2853 * @see #sendRequestAsync
2854 */
2855 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002856 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2857 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002858 }
2859
2860 /**
2861 * Posts the specified command to be executed on the main thread,
2862 * waits for the request to complete, and returns the result.
2863 * @see #sendRequestAsync
2864 */
2865 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2866 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002867 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002868 }
2869
2870 /**
2871 * Posts the specified command to be executed on the main thread,
2872 * waits for the request to complete, and returns the result.
2873 * @see #sendRequestAsync
2874 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002875 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002876 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2877 }
2878
2879 /**
2880 * Posts the specified command to be executed on the main thread,
2881 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2882 * if not timeout or null otherwise.
2883 * @see #sendRequestAsync
2884 */
2885 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2886 long timeoutInMs) {
2887 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002888 }
2889
2890 /**
2891 * Posts the specified command to be executed on the main thread,
2892 * waits for the request to complete, and returns the result.
2893 * @see #sendRequestAsync
2894 */
Nathan Harold92bed182018-10-12 18:16:49 -07002895 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002896 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002897 }
2898
2899 /**
2900 * Posts the specified command to be executed on the main thread,
2901 * waits for the request to complete, and returns the result.
2902 * @see #sendRequestAsync
2903 */
2904 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002905 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2906 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002907 }
2908
2909 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002910 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2911 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2912 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002913 * @see #sendRequestAsync
2914 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002915 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2916 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002917 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2918 throw new RuntimeException("This method will deadlock if called from the main thread.");
2919 }
2920
Nathan Harold92bed182018-10-12 18:16:49 -07002921 MainThreadRequest request = null;
2922 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2923 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2924 } else if (phone != null) {
2925 request = new MainThreadRequest(argument, phone, workSource);
2926 } else {
2927 request = new MainThreadRequest(argument, subId, workSource);
2928 }
2929
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002930 Message msg = mMainThreadHandler.obtainMessage(command, request);
2931 msg.sendToTarget();
2932
Rambo Wang0f050d82021-02-12 11:43:36 -08002933
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002934 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002935 if (timeoutInMs >= 0) {
2936 // Wait for at least timeoutInMs before returning null request result
2937 long now = SystemClock.elapsedRealtime();
2938 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002939 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002940 try {
2941 request.wait(deadline - now);
2942 } catch (InterruptedException e) {
2943 // Do nothing, go back and check if request is completed or timeout
2944 } finally {
2945 now = SystemClock.elapsedRealtime();
2946 }
2947 }
2948 } else {
2949 // Wait for the request to complete
2950 while (request.result == null) {
2951 try {
2952 request.wait();
2953 } catch (InterruptedException e) {
2954 // Do nothing, go back and wait until the request is complete
2955 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002956 }
2957 }
2958 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002959 if (request.result == null) {
2960 Log.wtf(LOG_TAG,
2961 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2962 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002963 return request.result;
2964 }
2965
2966 /**
2967 * Asynchronous ("fire and forget") version of sendRequest():
2968 * Posts the specified command to be executed on the main thread, and
2969 * returns immediately.
2970 * @see #sendRequest
2971 */
2972 private void sendRequestAsync(int command) {
2973 mMainThreadHandler.sendEmptyMessage(command);
2974 }
2975
2976 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002977 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002978 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002979 */
2980 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002981 sendRequestAsync(command, argument, null, null);
2982 }
2983
2984 /**
2985 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2986 * @see {@link #sendRequest(int,Object)}
2987 */
2988 private void sendRequestAsync(
2989 int command, Object argument, Phone phone, WorkSource workSource) {
2990 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002991 Message msg = mMainThreadHandler.obtainMessage(command, request);
2992 msg.sendToTarget();
2993 }
2994
2995 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002996 * Initialize the singleton PhoneInterfaceManager instance.
2997 * This is only done once, at startup, from PhoneApp.onCreate().
2998 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002999 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003000 synchronized (PhoneInterfaceManager.class) {
3001 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003002 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003003 } else {
3004 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
3005 }
3006 return sInstance;
3007 }
3008 }
3009
3010 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00003011 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003012 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003013 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00003014 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07003015 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003016 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07003017 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003018 mMainThreadHandler = new MainThreadHandler();
Jack Yue37dd262022-12-16 11:53:37 -08003019 if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) {
3020 mSubscriptionController = SubscriptionController.getInstance();
3021 } else {
3022 mSubscriptionController = null;
3023 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003024 mTelephonySharedPreferences =
3025 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07003026 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07003027 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08003028 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08003029 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07003030 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003031 publish();
arunvoddud7401012022-12-15 16:08:12 +00003032 CarrierAllowListInfo.loadInstance(mApp);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08003033 mSatelliteSupportedReceiver = new ResultReceiver(mMainThreadHandler) {
3034 @Override
3035 protected void onReceiveResult(int resultCode, Bundle resultData) {
3036 if (resultCode == SatelliteManager.SATELLITE_ERROR_NONE
3037 && resultData.containsKey(SatelliteManager.KEY_SATELLITE_SUPPORTED)) {
3038 synchronized (mIsSatelliteSupportedLock) {
3039 mIsSatelliteSupported = resultData.getBoolean(
3040 SatelliteManager.KEY_SATELLITE_SUPPORTED);
3041 }
3042 } else {
3043 synchronized (mIsSatelliteSupportedLock) {
3044 mIsSatelliteSupported = null;
3045 }
3046 }
3047 }
3048 };
3049 requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
3050 mSatelliteSupportedReceiver);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003051 }
3052
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003053 @VisibleForTesting
3054 public SharedPreferences getSharedPreferences() {
3055 return mTelephonySharedPreferences;
3056 }
3057
Gil Cukierman92cc7db2023-01-06 19:25:53 +00003058 /**
3059 * Get the default phone for this device.
3060 */
3061 @VisibleForTesting
3062 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003063 Phone thePhone = getPhone(getDefaultSubscription());
3064 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
3065 }
3066
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003067 private void publish() {
3068 if (DBG) log("publish: " + this);
3069
Peter Wangc035ce42020-01-08 21:00:22 -08003070 TelephonyFrameworkInitializer
3071 .getTelephonyServiceManager()
3072 .getTelephonyServiceRegisterer()
3073 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003074 }
3075
Stuart Scott584921c2015-01-15 17:10:34 -08003076 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08003077 if (request.phone != null) {
3078 return request.phone;
3079 } else {
3080 return getPhoneFromSubId(request.subId);
3081 }
3082 }
3083
3084 private Phone getPhoneFromSubId(int subId) {
3085 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
3086 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08003087 }
3088
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00003089 /**
3090 * Get phone object associated with a subscription.
3091 * Return default phone if phone object associated with subscription is null
3092 * @param subId - subscriptionId
3093 * @return phone object associated with a subscription or default phone if null.
3094 */
3095 private Phone getPhoneFromSubIdOrDefault(int subId) {
3096 Phone phone = getPhoneFromSubId(subId);
3097 if (phone == null) {
3098 phone = getDefaultPhone();
3099 }
3100 return phone;
3101 }
3102
Rambo Wange53e07d2022-05-10 13:01:13 -07003103 @Nullable
3104 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003105 Phone phone = getPhoneFromRequest(request);
3106 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00003107 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003108 }
3109
Wink Saville36469e72014-06-11 15:17:00 -07003110 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07003111 private Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08003112 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07003113 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003114
Kai Shif70f46f2021-03-03 13:59:46 -08003115 private void sendEraseModemConfig(@NonNull Phone phone) {
3116 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
3117 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
3118 }
3119
3120 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
3121 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
3122 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07003123 }
3124
Peter Wang44b186e2020-01-13 23:33:09 -08003125 private boolean isImsAvailableOnDevice() {
3126 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
3127 if (pm == null) {
3128 // For some reason package manger is not available.. This will fail internally anyway,
3129 // so do not throw error and allow.
3130 return true;
3131 }
3132 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
3133 }
3134
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003135 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003136 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07003137 }
3138
Wink Savilleb564aae2014-10-23 10:18:09 -07003139 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003140 if (DBG) log("dial: " + number);
3141 // No permission check needed here: This is just a wrapper around the
3142 // ACTION_DIAL intent, which is available to any app since it puts up
3143 // the UI before it does anything.
3144
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003145 final long identity = Binder.clearCallingIdentity();
3146 try {
3147 String url = createTelUrl(number);
3148 if (url == null) {
3149 return;
3150 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003151
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003152 // PENDING: should we just silently fail if phone is offhook or ringing?
3153 PhoneConstants.State state = mCM.getState(subId);
3154 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
3155 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
3156 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3157 mApp.startActivity(intent);
3158 }
3159 } finally {
3160 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003161 }
3162 }
3163
3164 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003165 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07003166 }
3167
Wink Savilleb564aae2014-10-23 10:18:09 -07003168 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003169 if (DBG) log("call: " + number);
3170
3171 // This is just a wrapper around the ACTION_CALL intent, but we still
3172 // need to do a permission check since we're calling startActivity()
3173 // from the context of the phone app.
3174 enforceCallPermission();
3175
Jordan Liu1617b712019-07-10 15:06:26 -07003176 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003177 != AppOpsManager.MODE_ALLOWED) {
3178 return;
3179 }
3180
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003181 final long identity = Binder.clearCallingIdentity();
3182 try {
3183 String url = createTelUrl(number);
3184 if (url == null) {
3185 return;
3186 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003187
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003188 boolean isValid = false;
3189 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
3190 if (slist != null) {
3191 for (SubscriptionInfo subInfoRecord : slist) {
3192 if (subInfoRecord.getSubscriptionId() == subId) {
3193 isValid = true;
3194 break;
3195 }
Wink Saville3ab207e2014-11-20 13:07:20 -08003196 }
Wink Saville08874612014-08-31 19:19:58 -07003197 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003198 if (!isValid) {
3199 return;
3200 }
Wink Saville08874612014-08-31 19:19:58 -07003201
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003202 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
3203 intent.putExtra(SUBSCRIPTION_KEY, subId);
3204 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3205 mApp.startActivity(intent);
3206 } finally {
3207 Binder.restoreCallingIdentity(identity);
3208 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003209 }
3210
Wink Savilleb564aae2014-10-23 10:18:09 -07003211 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003212 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07003213 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
3214 }
3215
Wink Savilleb564aae2014-10-23 10:18:09 -07003216 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003217 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07003218 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
3219 }
3220
Wink Savilleb564aae2014-10-23 10:18:09 -07003221 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003222 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003223
3224 final long identity = Binder.clearCallingIdentity();
3225 try {
Michele Berionne5e411512020-11-13 02:36:59 +00003226 Phone phone = getPhone(subId);
3227 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003228 checkSimPin.start();
3229 return checkSimPin.unlockSim(null, pin);
3230 } finally {
3231 Binder.restoreCallingIdentity(identity);
3232 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003233 }
3234
Wink Savilleb564aae2014-10-23 10:18:09 -07003235 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003236 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003237
3238 final long identity = Binder.clearCallingIdentity();
3239 try {
Michele Berionne5e411512020-11-13 02:36:59 +00003240 Phone phone = getPhone(subId);
3241 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003242 checkSimPuk.start();
3243 return checkSimPuk.unlockSim(puk, pin);
3244 } finally {
3245 Binder.restoreCallingIdentity(identity);
3246 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003247 }
3248
3249 /**
Wink Saville9de0f752013-10-22 19:04:03 -07003250 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003251 * a synchronous one.
3252 */
3253 private static class UnlockSim extends Thread {
3254
3255 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00003256 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003257
3258 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07003259 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
3260 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003261
3262 // For replies from SimCard interface
3263 private Handler mHandler;
3264
3265 // For async handler to identify request type
3266 private static final int SUPPLY_PIN_COMPLETE = 100;
3267
Michele Berionne5e411512020-11-13 02:36:59 +00003268 UnlockSim(int phoneId, IccCard simCard) {
3269 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003270 mSimCard = simCard;
3271 }
3272
3273 @Override
3274 public void run() {
3275 Looper.prepare();
3276 synchronized (UnlockSim.this) {
3277 mHandler = new Handler() {
3278 @Override
3279 public void handleMessage(Message msg) {
3280 AsyncResult ar = (AsyncResult) msg.obj;
3281 switch (msg.what) {
3282 case SUPPLY_PIN_COMPLETE:
3283 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
3284 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07003285 mRetryCount = msg.arg1;
3286 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08003287 CommandException.Error error = null;
3288 if (ar.exception instanceof CommandException) {
3289 error = ((CommandException) (ar.exception))
3290 .getCommandError();
3291 }
3292 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07003293 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08003294 } else if (error == CommandException.Error.ABORTED) {
3295 /* When UiccCardApp dispose, handle message and return
3296 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08003297 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07003298 } else {
3299 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
3300 }
3301 } else {
3302 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
3303 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003304 mDone = true;
3305 UnlockSim.this.notifyAll();
3306 }
3307 break;
3308 }
3309 }
3310 };
3311 UnlockSim.this.notifyAll();
3312 }
3313 Looper.loop();
3314 }
3315
3316 /*
3317 * Use PIN or PUK to unlock SIM card
3318 *
3319 * If PUK is null, unlock SIM card with PIN
3320 *
3321 * If PUK is not null, unlock SIM card with PUK and set PIN code
3322 */
Wink Saville9de0f752013-10-22 19:04:03 -07003323 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003324
3325 while (mHandler == null) {
3326 try {
3327 wait();
3328 } catch (InterruptedException e) {
3329 Thread.currentThread().interrupt();
3330 }
3331 }
3332 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
3333
3334 if (puk == null) {
3335 mSimCard.supplyPin(pin, callback);
3336 } else {
3337 mSimCard.supplyPuk(puk, pin, callback);
3338 }
3339
3340 while (!mDone) {
3341 try {
3342 Log.d(LOG_TAG, "wait for done");
3343 wait();
3344 } catch (InterruptedException e) {
3345 // Restore the interrupted status
3346 Thread.currentThread().interrupt();
3347 }
3348 }
3349 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07003350 int[] resultArray = new int[2];
3351 resultArray[0] = mResult;
3352 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00003353
3354 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00003355 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00003356 }
3357
Wink Saville9de0f752013-10-22 19:04:03 -07003358 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003359 }
3360 }
3361
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003362 /**
3363 * This method has been removed due to privacy and stability concerns.
3364 */
3365 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003366 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003367 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
3368 return;
Wink Saville36469e72014-06-11 15:17:00 -07003369 }
3370
Nathan Harold1f889d82020-06-04 17:05:26 -07003371 @Override
3372 public void updateServiceLocationWithPackageName(String callingPackage) {
3373 mApp.getSystemService(AppOpsManager.class)
3374 .checkPackage(Binder.getCallingUid(), callingPackage);
3375
Nathan Haroldf096d982020-11-18 17:18:06 -08003376 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07003377 if (targetSdk > android.os.Build.VERSION_CODES.R) {
3378 // Callers targeting S have no business invoking this method.
3379 return;
3380 }
3381
3382 LocationAccessPolicy.LocationPermissionResult locationResult =
3383 LocationAccessPolicy.checkLocationPermission(mApp,
3384 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3385 .setCallingPackage(callingPackage)
3386 .setCallingFeatureId(null)
3387 .setCallingPid(Binder.getCallingPid())
3388 .setCallingUid(Binder.getCallingUid())
3389 .setMethod("updateServiceLocation")
3390 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3391 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3392 .build());
3393 // Apps that lack location permission have no business calling this method;
3394 // however, because no permission was declared in the public API, denials must
3395 // all be "soft".
3396 switch (locationResult) {
3397 case DENIED_HARD: /* fall through */
3398 case DENIED_SOFT:
3399 return;
3400 }
3401
3402 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003403 final long identity = Binder.clearCallingIdentity();
3404 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07003405 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003406 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07003407 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003408 }
3409 } finally {
3410 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003411 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003412 }
3413
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003414 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003415 @Override
3416 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003417 return isRadioOnWithFeature(callingPackage, null);
3418 }
3419
3420
3421 @Override
3422 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
3423 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
3424 callingFeatureId);
3425 }
3426
3427 @Deprecated
3428 @Override
3429 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
3430 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07003431 }
3432
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003433 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003434 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
3435 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003436 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003437 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003438 return false;
3439 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003440
3441 final long identity = Binder.clearCallingIdentity();
3442 try {
3443 return isRadioOnForSubscriber(subId);
3444 } finally {
3445 Binder.restoreCallingIdentity(identity);
3446 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003447 }
3448
3449 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003450 final long identity = Binder.clearCallingIdentity();
3451 try {
3452 final Phone phone = getPhone(subId);
3453 if (phone != null) {
3454 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
3455 } else {
3456 return false;
3457 }
3458 } finally {
3459 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003460 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003461 }
3462
3463 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003464 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003465 }
Wink Saville36469e72014-06-11 15:17:00 -07003466
Wink Savilleb564aae2014-10-23 10:18:09 -07003467 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003468 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003469
3470 final long identity = Binder.clearCallingIdentity();
3471 try {
3472 final Phone phone = getPhone(subId);
3473 if (phone != null) {
3474 phone.setRadioPower(!isRadioOnForSubscriber(subId));
3475 }
3476 } finally {
3477 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003478 }
Wink Saville36469e72014-06-11 15:17:00 -07003479 }
3480
3481 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003482 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07003483 }
3484
Wink Savilleb564aae2014-10-23 10:18:09 -07003485 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07003486 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003487
3488 final long identity = Binder.clearCallingIdentity();
3489 try {
3490 final Phone phone = getPhone(subId);
3491 if (phone == null) {
3492 return false;
3493 }
3494 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
3495 toggleRadioOnOffForSubscriber(subId);
3496 }
3497 return true;
3498 } finally {
3499 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003500 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003501 }
Wink Saville36469e72014-06-11 15:17:00 -07003502
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003503 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08003504 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003505 /*
3506 * If any of the Radios are available, it will need to be
3507 * shutdown. So return true if any Radio is available.
3508 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003509 final long identity = Binder.clearCallingIdentity();
3510 try {
3511 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3512 Phone phone = PhoneFactory.getPhone(i);
3513 if (phone != null && phone.isRadioAvailable()) return true;
3514 }
3515 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3516 return false;
3517 } finally {
3518 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003519 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003520 }
3521
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003522 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003523 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003524 enforceModifyPermission();
3525
3526 final long identity = Binder.clearCallingIdentity();
3527 try {
3528 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3529 logv("Shutting down Phone " + i);
3530 shutdownRadioUsingPhoneId(i);
3531 }
3532 } finally {
3533 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003534 }
3535 }
3536
3537 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003538 Phone phone = PhoneFactory.getPhone(phoneId);
3539 if (phone != null && phone.isRadioAvailable()) {
3540 phone.shutdownRadio();
3541 }
3542 }
3543
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003544 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003545 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003546
Ling Ma83dc5ea2023-01-12 15:06:04 -08003547 if (!turnOn) {
3548 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3549 }
3550
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003551 final long identity = Binder.clearCallingIdentity();
3552 try {
3553 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3554 if (defaultPhone != null) {
3555 defaultPhone.setRadioPower(turnOn);
3556 return true;
3557 } else {
3558 loge("There's no default phone.");
3559 return false;
3560 }
3561 } finally {
3562 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003563 }
Wink Saville36469e72014-06-11 15:17:00 -07003564 }
3565
Wink Savilleb564aae2014-10-23 10:18:09 -07003566 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003567 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003568
Ling Ma83dc5ea2023-01-12 15:06:04 -08003569 if (!turnOn) {
3570 log("setRadioPowerForSubscriber off: subId=" + subId
3571 + ",callingPackage=" + getCurrentPackageName());
3572 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003573 final long identity = Binder.clearCallingIdentity();
3574 try {
3575 final Phone phone = getPhone(subId);
3576 if (phone != null) {
3577 phone.setRadioPower(turnOn);
3578 return true;
3579 } else {
3580 return false;
3581 }
3582 } finally {
3583 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003584 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003585 }
3586
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003587 /**
3588 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3589 * no reason to power it off. When any of the voters want to power it off, it will be turned
3590 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3591 * powering it off, and these radio off votes will be cleared.
3592 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3593 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3594 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3595 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3596 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3597 * check its vote.
3598 *
3599 * @param subId The subscription ID.
3600 * @param reason The reason for powering off radio.
3601 * @return true on success and false on failure.
3602 */
3603 public boolean requestRadioPowerOffForReason(int subId,
3604 @TelephonyManager.RadioPowerReason int reason) {
3605 enforceModifyPermission();
3606
Ling Ma83dc5ea2023-01-12 15:06:04 -08003607 log("requestRadioPowerOffForReason: subId=" + subId
3608 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003609 final long identity = Binder.clearCallingIdentity();
3610 try {
3611 final Phone phone = getPhone(subId);
3612 if (phone != null) {
3613 phone.setRadioPowerForReason(false, reason);
3614 return true;
3615 } else {
3616 return false;
3617 }
3618 } finally {
3619 Binder.restoreCallingIdentity(identity);
3620 }
3621 }
3622
3623 /**
3624 * Remove the vote on powering off the radio for a reason, as requested by
3625 * {@link requestRadioPowerOffForReason}.
3626 *
3627 * @param subId The subscription ID.
3628 * @param reason The reason for powering off radio.
3629 * @return true on success and false on failure.
3630 */
3631 public boolean clearRadioPowerOffForReason(int subId,
3632 @TelephonyManager.RadioPowerReason int reason) {
3633 enforceModifyPermission();
3634
3635 final long identity = Binder.clearCallingIdentity();
3636 try {
3637 final Phone phone = getPhone(subId);
3638 if (phone != null) {
3639 phone.setRadioPowerForReason(true, reason);
3640 return true;
3641 } else {
3642 return false;
3643 }
3644 } finally {
3645 Binder.restoreCallingIdentity(identity);
3646 }
3647 }
3648
3649 /**
3650 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3651 *
3652 * @param subId The subscription ID.
3653 * @param callingPackage The package making the call.
3654 * @param callingFeatureId The feature in the package.
3655 * @return List of reasons for powering off radio.
3656 */
3657 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3658 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3659
3660 final long identity = Binder.clearCallingIdentity();
3661 List result = new ArrayList();
3662 try {
3663 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3664 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3665 return result;
3666 }
3667
3668 final Phone phone = getPhone(subId);
3669 if (phone != null) {
3670 result.addAll(phone.getRadioPowerOffReasons());
3671 }
3672 } finally {
3673 Binder.restoreCallingIdentity(identity);
3674 }
3675 return result;
3676 }
3677
Wink Saville36469e72014-06-11 15:17:00 -07003678 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003679 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003680 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003681 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003682
3683 final long identity = Binder.clearCallingIdentity();
3684 try {
Jack Yu285100e2022-12-02 22:48:35 -08003685 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003686 final Phone phone = getPhone(subId);
3687 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003688 phone.getDataSettingsManager().setDataEnabled(
3689 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003690 return true;
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
Wink Saville36469e72014-06-11 15:17:00 -07003699 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003700 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003701 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003702 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003703
3704 final long identity = Binder.clearCallingIdentity();
3705 try {
Jack Yu285100e2022-12-02 22:48:35 -08003706 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003707 final Phone phone = getPhone(subId);
3708 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003709 phone.getDataSettingsManager().setDataEnabled(
3710 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003711 return true;
3712 } else {
3713 return false;
3714 }
3715 } finally {
3716 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003717 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003718 }
3719
Sanket Padawe356d7632015-06-22 14:03:32 -07003720 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003721 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003722 final long identity = Binder.clearCallingIdentity();
3723 try {
3724 final Phone phone = getPhone(subId);
3725 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003726 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003727 } else {
3728 return false;
3729 }
3730 } finally {
3731 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003732 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003733 }
3734
3735 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003736 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003737 }
3738
pkanwarae03a6b2016-11-06 20:37:09 -08003739 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003740 enforceCallPermission();
3741
3742 final long identity = Binder.clearCallingIdentity();
3743 try {
3744 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3745 return;
3746 }
3747 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3748 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3749 } finally {
3750 Binder.restoreCallingIdentity(identity);
3751 }
pkanwar32d516d2016-10-14 19:37:38 -07003752 };
3753
Wink Savilleb564aae2014-10-23 10:18:09 -07003754 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003755 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003756
3757 final long identity = Binder.clearCallingIdentity();
3758 try {
3759 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3760 return false;
3761 }
3762 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3763 } finally {
3764 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003765 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003766 }
3767
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003768 /**
3769 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3770 * tag on getCallState Binder call.
3771 */
3772 @Deprecated
3773 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003774 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003775 if (CompatChanges.isChangeEnabled(
3776 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3777 Binder.getCallingUid())) {
3778 // Do not allow this API to be called on API version 31+, it should only be
3779 // called on old apps using this Binder call directly.
3780 throw new SecurityException("This method can only be used for applications "
3781 + "targeting API version 30 or less.");
3782 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003783 final long identity = Binder.clearCallingIdentity();
3784 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003785 Phone phone = getPhone(getDefaultSubscription());
3786 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3787 PhoneConstantConversions.convertCallState(phone.getState());
3788 } finally {
3789 Binder.restoreCallingIdentity(identity);
3790 }
3791 }
3792
3793 @Override
3794 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3795 if (CompatChanges.isChangeEnabled(
3796 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3797 Binder.getCallingUid())) {
3798 // Check READ_PHONE_STATE for API version 31+
3799 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3800 featureId, "getCallStateForSubscription")) {
3801 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3802 + "targeting API level 31+.");
3803 }
3804 }
3805 final long identity = Binder.clearCallingIdentity();
3806 try {
3807 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003808 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3809 PhoneConstantConversions.convertCallState(phone.getState());
3810 } finally {
3811 Binder.restoreCallingIdentity(identity);
3812 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003813 }
3814
Sanket Padawe356d7632015-06-22 14:03:32 -07003815 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003816 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003817 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003818 }
3819
3820 @Override
3821 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003822 final long identity = Binder.clearCallingIdentity();
3823 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003824 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003825 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003826 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003827 } else {
3828 return PhoneConstantConversions.convertDataState(
3829 PhoneConstants.DataState.DISCONNECTED);
3830 }
3831 } finally {
3832 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003833 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003834 }
3835
Sanket Padawe356d7632015-06-22 14:03:32 -07003836 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003837 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003838 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003839 }
3840
3841 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003842 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003843 final long identity = Binder.clearCallingIdentity();
3844 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003845 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003846 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003847 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003848 } else {
3849 return TelephonyManager.DATA_ACTIVITY_NONE;
3850 }
3851 } finally {
3852 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003853 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003854 }
3855
3856 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003857 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003858 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003859 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003860
3861 LocationAccessPolicy.LocationPermissionResult locationResult =
3862 LocationAccessPolicy.checkLocationPermission(mApp,
3863 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3864 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003865 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003866 .setCallingPid(Binder.getCallingPid())
3867 .setCallingUid(Binder.getCallingUid())
3868 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003869 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003870 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3871 .build());
3872 switch (locationResult) {
3873 case DENIED_HARD:
3874 throw new SecurityException("Not allowed to access cell location");
3875 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003876 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3877 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003878 }
3879
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003880 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003881 final long identity = Binder.clearCallingIdentity();
3882 try {
3883 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003884 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003885 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003886 } finally {
3887 Binder.restoreCallingIdentity(identity);
3888 }
Svetoslav64fad262015-04-14 14:35:21 -07003889 }
3890
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003891 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003892 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003893 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3894 // registered cell info, so return a NULL country instead.
3895 final long identity = Binder.clearCallingIdentity();
3896 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003897 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3898 // Get default phone in this case.
3899 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3900 }
Jack Yu285100e2022-12-02 22:48:35 -08003901 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003902 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003903 if (phone == null) return "";
3904 ServiceStateTracker sst = phone.getServiceStateTracker();
3905 if (sst == null) return "";
3906 LocaleTracker lt = sst.getLocaleTracker();
3907 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003908 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003909 } finally {
3910 Binder.restoreCallingIdentity(identity);
3911 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003912 }
3913
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003914 /**
3915 * This method was removed due to potential issues caused by performing partial
3916 * updates of service state, and lack of a credible use case.
3917 *
3918 * This has the ability to break the telephony implementation by disabling notification of
3919 * changes in device connectivity. DO NOT USE THIS!
3920 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003921 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003922 public void enableLocationUpdates() {
3923 mApp.enforceCallingOrSelfPermission(
3924 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003925 }
3926
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003927 /**
3928 * This method was removed due to potential issues caused by performing partial
3929 * updates of service state, and lack of a credible use case.
3930 *
3931 * This has the ability to break the telephony implementation by disabling notification of
3932 * changes in device connectivity. DO NOT USE THIS!
3933 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003934 @Override
3935 public void disableLocationUpdates() {
3936 mApp.enforceCallingOrSelfPermission(
3937 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003938 }
3939
3940 @Override
3941 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003942 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3943 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003944 try {
3945 mApp.getSystemService(AppOpsManager.class)
3946 .checkPackage(Binder.getCallingUid(), callingPackage);
3947 } catch (SecurityException e) {
3948 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3949 throw e;
3950 }
3951
Nathan Haroldf096d982020-11-18 17:18:06 -08003952 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003953 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3954 throw new SecurityException(
3955 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3956 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003957
Jordan Liu1617b712019-07-10 15:06:26 -07003958 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003959 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3960 return null;
3961 }
Svetoslav64fad262015-04-14 14:35:21 -07003962
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003963 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003964
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003965 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003966 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003967
Nathan Haroldf180aac2018-06-01 18:43:55 -07003968 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3969 for (CellInfo ci : info) {
3970 if (ci instanceof CellInfoGsm) {
3971 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3972 } else if (ci instanceof CellInfoWcdma) {
3973 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3974 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003975 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003976 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003977 }
3978
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003979 private List<CellInfo> getCachedCellInfo() {
3980 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3981 for (Phone phone : PhoneFactory.getPhones()) {
3982 List<CellInfo> info = phone.getAllCellInfo();
3983 if (info != null) cellInfos.addAll(info);
3984 }
3985 return cellInfos;
3986 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003987
3988 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003989 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003990 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003991 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003992
3993 LocationAccessPolicy.LocationPermissionResult locationResult =
3994 LocationAccessPolicy.checkLocationPermission(mApp,
3995 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3996 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003997 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003998 .setCallingPid(Binder.getCallingPid())
3999 .setCallingUid(Binder.getCallingUid())
4000 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08004001 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08004002 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4003 .build());
4004 switch (locationResult) {
4005 case DENIED_HARD:
4006 throw new SecurityException("Not allowed to access cell info");
4007 case DENIED_SOFT:
4008 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004009 }
4010
Nathan Haroldf096d982020-11-18 17:18:06 -08004011 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004012 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
4013 return getCachedCellInfo();
4014 }
4015
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07004016 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004017 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004018 final long identity = Binder.clearCallingIdentity();
4019 try {
4020 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
4021 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07004022 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07004023 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004024 if (info != null) cellInfos.addAll(info);
4025 }
4026 return cellInfos;
4027 } finally {
4028 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004029 }
4030 }
4031
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07004032 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004033 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
4034 String callingFeatureId) {
4035 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
4036 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004037 }
4038
4039 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004040 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
4041 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004042 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004043 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004044 }
4045
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004046 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
4047 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004048 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004049 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08004050
4051 LocationAccessPolicy.LocationPermissionResult locationResult =
4052 LocationAccessPolicy.checkLocationPermission(mApp,
4053 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4054 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004055 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004056 .setCallingPid(Binder.getCallingPid())
4057 .setCallingUid(Binder.getCallingUid())
4058 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07004059 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
4060 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08004061 .build());
4062 switch (locationResult) {
4063 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08004064 if (TelephonyPermissions
4065 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07004066 // Safetynet logging for b/154934934
4067 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
4068 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004069 throw new SecurityException("Not allowed to access cell info");
4070 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08004071 if (TelephonyPermissions
4072 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07004073 // Safetynet logging for b/154934934
4074 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
4075 }
Nathan Harold5320c422019-05-09 10:26:08 -07004076 try {
4077 cb.onCellInfo(new ArrayList<CellInfo>());
4078 } catch (RemoteException re) {
4079 // Drop without consequences
4080 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004081 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004082 }
4083
Nathan Harolda939a962019-05-09 10:13:47 -07004084
4085 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004086 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
4087
4088 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
4089 }
4090
4091 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00004092 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08004093 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004094 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004095
4096 final long identity = Binder.clearCallingIdentity();
4097 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00004098 Phone phone = getPhone(subId);
4099 if (phone == null) {
4100 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
4101 } else {
4102 phone.setCellInfoListRate(rateInMillis, workSource);
4103 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004104 } finally {
4105 Binder.restoreCallingIdentity(identity);
4106 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004107 }
4108
Shishir Agrawala9f32182016-04-12 12:00:16 -07004109 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004110 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004111 Phone phone = PhoneFactory.getPhone(slotIndex);
4112 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004113 return null;
4114 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004115 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07004116 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07004117 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004118 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004119 return null;
4120 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004121
4122 final long identity = Binder.clearCallingIdentity();
4123 try {
4124 return phone.getImei();
4125 } finally {
4126 Binder.restoreCallingIdentity(identity);
4127 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07004128 }
4129
4130 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00004131 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
4132 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
4133 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
4134 callingFeatureId, "getPrimaryImei")) {
4135 throw new SecurityException("Caller does not have permission");
4136 }
4137 final long identity = Binder.clearCallingIdentity();
4138 try {
4139 for (Phone phone : PhoneFactory.getPhones()) {
4140 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
4141 return phone.getImei();
4142 }
4143 }
4144 throw new UnsupportedOperationException("Operation not supported");
4145 } finally {
4146 Binder.restoreCallingIdentity(identity);
4147 }
4148 }
4149
4150 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00004151 public String getTypeAllocationCodeForSlot(int slotIndex) {
4152 Phone phone = PhoneFactory.getPhone(slotIndex);
4153 String tac = null;
4154 if (phone != null) {
4155 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07004156 try {
4157 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
4158 } catch (IndexOutOfBoundsException e) {
4159 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
4160 return null;
4161 }
David Kelly5e06a7f2018-03-12 14:10:59 +00004162 }
4163 return tac;
4164 }
4165
4166 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004167 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004168 try {
4169 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4170 } catch (SecurityException se) {
4171 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
4172 throw new SecurityException("Package " + callingPackage + " does not belong to "
4173 + Binder.getCallingUid());
4174 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004175 Phone phone = PhoneFactory.getPhone(slotIndex);
4176 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07004177 return null;
4178 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004179
Jeff Davidson913390f2018-02-23 17:11:49 -08004180 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07004181 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004182 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004183 return null;
4184 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004185
4186 final long identity = Binder.clearCallingIdentity();
4187 try {
4188 return phone.getMeid();
4189 } finally {
4190 Binder.restoreCallingIdentity(identity);
4191 }
Jack Yu2af8d712017-03-15 17:14:14 -07004192 }
4193
4194 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00004195 public String getManufacturerCodeForSlot(int slotIndex) {
4196 Phone phone = PhoneFactory.getPhone(slotIndex);
4197 String manufacturerCode = null;
4198 if (phone != null) {
4199 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07004200 try {
4201 manufacturerCode =
4202 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
4203 } catch (IndexOutOfBoundsException e) {
4204 Log.e(LOG_TAG, "MEID length shorter than upper index.");
4205 return null;
4206 }
David Kelly5e06a7f2018-03-12 14:10:59 +00004207 }
4208 return manufacturerCode;
4209 }
4210
4211 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004212 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
4213 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004214 Phone phone = PhoneFactory.getPhone(slotIndex);
4215 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004216 return null;
4217 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004218 int subId = phone.getSubId();
4219 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004220 mApp, subId, callingPackage, callingFeatureId,
4221 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004222 return null;
4223 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004224
4225 final long identity = Binder.clearCallingIdentity();
4226 try {
4227 return phone.getDeviceSvn();
4228 } finally {
4229 Binder.restoreCallingIdentity(identity);
4230 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07004231 }
4232
fionaxu43304da2017-11-27 22:51:16 -08004233 @Override
4234 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004235 final long identity = Binder.clearCallingIdentity();
4236 try {
4237 final Phone phone = getPhone(subId);
4238 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
4239 } finally {
4240 Binder.restoreCallingIdentity(identity);
4241 }
fionaxu43304da2017-11-27 22:51:16 -08004242 }
4243
4244 @Override
4245 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004246 final long identity = Binder.clearCallingIdentity();
4247 try {
4248 final Phone phone = getPhone(subId);
4249 return phone == null ? null : phone.getCarrierName();
4250 } finally {
4251 Binder.restoreCallingIdentity(identity);
4252 }
fionaxu43304da2017-11-27 22:51:16 -08004253 }
4254
calvinpanffe225e2018-11-01 19:43:06 +08004255 @Override
chen xu0026ca62019-03-06 15:28:50 -08004256 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08004257 final long identity = Binder.clearCallingIdentity();
4258 try {
4259 final Phone phone = getPhone(subId);
4260 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08004261 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08004262 } finally {
4263 Binder.restoreCallingIdentity(identity);
4264 }
4265 }
4266
4267 @Override
chen xu0026ca62019-03-06 15:28:50 -08004268 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08004269 final long identity = Binder.clearCallingIdentity();
4270 try {
4271 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08004272 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08004273 } finally {
4274 Binder.restoreCallingIdentity(identity);
4275 }
4276 }
4277
chen xu651eec72018-11-11 19:03:44 -08004278 @Override
chen xu864e11c2018-12-06 22:10:03 -08004279 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
4280 if (!isSubscriptionMccMnc) {
4281 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
4282 }
chen xu651eec72018-11-11 19:03:44 -08004283 final Phone phone = PhoneFactory.getPhone(slotIndex);
4284 if (phone == null) {
4285 return TelephonyManager.UNKNOWN_CARRIER_ID;
4286 }
4287 final long identity = Binder.clearCallingIdentity();
4288 try {
4289 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
4290 } finally {
4291 Binder.restoreCallingIdentity(identity);
4292 }
4293 }
4294
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004295 //
4296 // Internal helper methods.
4297 //
4298
Sanket Padaweee13a9b2016-03-08 17:30:28 -08004299 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07004300 * Make sure the caller is the calling package itself
4301 *
4302 * @throws SecurityException if the caller is not the calling package
4303 */
4304 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
4305 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07004306 PackageManager pm = mApp.getBaseContext().createContextAsUser(
4307 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07004308 try {
Grace Jiadbefca02021-04-26 15:13:31 -07004309 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07004310 } catch (PackageManager.NameNotFoundException e) {
4311 // packageUid is -1
4312 }
4313 if (packageUid != callingUid) {
4314 throw new SecurityException(message + ": Package " + callingPackage
4315 + " does not belong to " + callingUid);
4316 }
4317 }
4318
4319 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004320 * Make sure the caller has the MODIFY_PHONE_STATE permission.
4321 *
4322 * @throws SecurityException if the caller does not have the required permission
4323 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004324 @VisibleForTesting
4325 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004326 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
4327 }
4328
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004329 /**
arunvoddud7401012022-12-15 16:08:12 +00004330 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004331 *
4332 * @throws SecurityException if the caller does not have the required permission
4333 */
4334 @VisibleForTesting
4335 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00004336 enforceReadPermission(null);
4337 }
4338
4339 /**
4340 * Make sure the caller has the READ_PHONE_STATE permissions.
4341 *
4342 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
4343 */
4344 @VisibleForTesting
4345 public void enforceReadPermission(String msg) {
4346 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004347 }
4348
Shuo Qian3b6ee772019-11-13 17:43:31 -08004349 private void enforceActiveEmergencySessionPermission() {
4350 mApp.enforceCallingOrSelfPermission(
4351 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
4352 }
4353
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004354 /**
4355 * Make sure the caller has the CALL_PHONE permission.
4356 *
4357 * @throws SecurityException if the caller does not have the required permission
4358 */
4359 private void enforceCallPermission() {
4360 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
4361 }
4362
paulhu5a773602019-08-23 19:17:33 +08004363 private void enforceSettingsPermission() {
4364 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004365 }
4366
Michele Berionne5e411512020-11-13 02:36:59 +00004367 private void enforceRebootPermission() {
4368 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
4369 }
4370
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00004371 /**
4372 * Make sure the caller has SATELLITE_COMMUNICATION permission.
4373 * @param message - log message to print.
4374 * @throws SecurityException if the caller does not have the required permission
4375 */
4376 private void enforceSatelliteCommunicationPermission(String message) {
4377 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
4378 }
4379
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004380 private String createTelUrl(String number) {
4381 if (TextUtils.isEmpty(number)) {
4382 return null;
4383 }
4384
Jake Hambye994d462014-02-03 13:10:13 -08004385 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004386 }
4387
Ihab Awadf9e92732013-12-05 18:02:52 -08004388 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08004389 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004390 }
4391
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07004392 private static void logv(String msg) {
4393 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
4394 }
4395
Ihab Awadf9e92732013-12-05 18:02:52 -08004396 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004397 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
4398 }
4399
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004400 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004401 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07004402 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07004403 }
4404
Sanket Padawe356d7632015-06-22 14:03:32 -07004405 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004406 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004407 final long identity = Binder.clearCallingIdentity();
4408 try {
4409 final Phone phone = PhoneFactory.getPhone(slotIndex);
4410 if (phone == null) {
4411 return PhoneConstants.PHONE_TYPE_NONE;
4412 } else {
4413 return phone.getPhoneType();
4414 }
4415 } finally {
4416 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004417 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004418 }
4419
4420 /**
4421 * Returns the CDMA ERI icon index to display
4422 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004423 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004424 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
4425 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4426 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004427 }
4428
Sanket Padawe356d7632015-06-22 14:03:32 -07004429 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004430 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4431 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004432 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004433 mApp, subId, callingPackage, callingFeatureId,
4434 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004435 return -1;
4436 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004437
4438 final long identity = Binder.clearCallingIdentity();
4439 try {
4440 final Phone phone = getPhone(subId);
4441 if (phone != null) {
4442 return phone.getCdmaEriIconIndex();
4443 } else {
4444 return -1;
4445 }
4446 } finally {
4447 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004448 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004449 }
4450
4451 /**
4452 * Returns the CDMA ERI icon mode,
4453 * 0 - ON
4454 * 1 - FLASHING
4455 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004456 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004457 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4458 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4459 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004460 }
4461
Sanket Padawe356d7632015-06-22 14:03:32 -07004462 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004463 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4464 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004465 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004466 mApp, subId, callingPackage, callingFeatureId,
4467 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004468 return -1;
4469 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004470
4471 final long identity = Binder.clearCallingIdentity();
4472 try {
4473 final Phone phone = getPhone(subId);
4474 if (phone != null) {
4475 return phone.getCdmaEriIconMode();
4476 } else {
4477 return -1;
4478 }
4479 } finally {
4480 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004481 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004482 }
4483
4484 /**
4485 * Returns the CDMA ERI text,
4486 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004487 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004488 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4489 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4490 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004491 }
4492
Sanket Padawe356d7632015-06-22 14:03:32 -07004493 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004494 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4495 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004496 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004497 mApp, subId, callingPackage, callingFeatureId,
4498 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004499 return null;
4500 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004501
4502 final long identity = Binder.clearCallingIdentity();
4503 try {
4504 final Phone phone = getPhone(subId);
4505 if (phone != null) {
4506 return phone.getCdmaEriText();
4507 } else {
4508 return null;
4509 }
4510 } finally {
4511 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004512 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004513 }
4514
4515 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004516 * Returns the CDMA MDN.
4517 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004518 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004519 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004520 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4521 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004522
4523 final long identity = Binder.clearCallingIdentity();
4524 try {
4525 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004526 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004527 return phone.getLine1Number();
4528 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004529 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004530 return null;
4531 }
4532 } finally {
4533 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004534 }
4535 }
4536
4537 /**
4538 * Returns the CDMA MIN.
4539 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004540 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004541 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004542 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4543 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004544
4545 final long identity = Binder.clearCallingIdentity();
4546 try {
4547 final Phone phone = getPhone(subId);
4548 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4549 return phone.getCdmaMin();
4550 } else {
4551 return null;
4552 }
4553 } finally {
4554 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004555 }
4556 }
4557
Hall Liud892bec2018-11-30 14:51:45 -08004558 @Override
4559 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4560 INumberVerificationCallback callback, String callingPackage) {
4561 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4562 != PERMISSION_GRANTED) {
4563 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4564 }
4565 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4566
4567 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4568 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004569 throw new SecurityException("Calling package must be configured in the device config: "
4570 + "calling package: " + callingPackage
4571 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004572 }
4573
4574 if (range == null) {
4575 throw new NullPointerException("Range must be non-null");
4576 }
4577
4578 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004579 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004580
4581 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4582 }
4583
Junda Liuca05d5d2014-08-14 22:36:34 -07004584 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004585 * Returns true if CDMA provisioning needs to run.
4586 */
4587 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004588 final long identity = Binder.clearCallingIdentity();
4589 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004590 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004591 } finally {
4592 Binder.restoreCallingIdentity(identity);
4593 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004594 }
4595
4596 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004597 * Sets the voice mail number of a given subId.
4598 */
4599 @Override
4600 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004601 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4602 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004603
4604 final long identity = Binder.clearCallingIdentity();
4605 try {
4606 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4607 new Pair<String, String>(alphaTag, number), new Integer(subId));
4608 return success;
4609 } finally {
4610 Binder.restoreCallingIdentity(identity);
4611 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004612 }
4613
Ta-wei Yen87c49842016-05-13 21:19:52 -07004614 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004615 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4616 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004617 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4618 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004619 if (!TextUtils.equals(callingPackage, systemDialer)) {
4620 throw new SecurityException("caller must be system dialer");
4621 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004622
4623 final long identity = Binder.clearCallingIdentity();
4624 try {
4625 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4626 if (phoneAccountHandle == null) {
4627 return null;
4628 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004629 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004630 } finally {
4631 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004632 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004633 }
4634
4635 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004636 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4637 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004638 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004639 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004640 mApp, subId, callingPackage, callingFeatureId,
4641 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004642 return null;
4643 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004644
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004645 final long identity = Binder.clearCallingIdentity();
4646 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004647 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004648 } finally {
4649 Binder.restoreCallingIdentity(identity);
4650 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004651 }
4652
4653 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004654 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4655 VisualVoicemailSmsFilterSettings settings) {
4656 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004657
4658 final long identity = Binder.clearCallingIdentity();
4659 try {
4660 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004661 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004662 } finally {
4663 Binder.restoreCallingIdentity(identity);
4664 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004665 }
4666
4667 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004668 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4669 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004670
4671 final long identity = Binder.clearCallingIdentity();
4672 try {
4673 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004674 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004675 } finally {
4676 Binder.restoreCallingIdentity(identity);
4677 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004678 }
4679
4680 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004681 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4682 String callingPackage, int subId) {
4683 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004684
4685 final long identity = Binder.clearCallingIdentity();
4686 try {
4687 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004688 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004689 } finally {
4690 Binder.restoreCallingIdentity(identity);
4691 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004692 }
4693
4694 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004695 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004696 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004697
4698 final long identity = Binder.clearCallingIdentity();
4699 try {
4700 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004701 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004702 } finally {
4703 Binder.restoreCallingIdentity(identity);
4704 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004705 }
4706
4707 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004708 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4709 String callingAttributionTag, int subId, String number, int port, String text,
4710 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004711 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004712 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004713 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004714 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004715 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4716 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004717 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004718
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004719 /**
fionaxu0152e512016-11-14 13:36:14 -08004720 * Sets the voice activation state of a given subId.
4721 */
4722 @Override
4723 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004724 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4725 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004726
4727 final long identity = Binder.clearCallingIdentity();
4728 try {
4729 final Phone phone = getPhone(subId);
4730 if (phone != null) {
4731 phone.setVoiceActivationState(activationState);
4732 } else {
4733 loge("setVoiceActivationState fails with invalid subId: " + subId);
4734 }
4735 } finally {
4736 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004737 }
4738 }
4739
4740 /**
4741 * Sets the data activation state of a given subId.
4742 */
4743 @Override
4744 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004745 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4746 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004747
4748 final long identity = Binder.clearCallingIdentity();
4749 try {
4750 final Phone phone = getPhone(subId);
4751 if (phone != null) {
4752 phone.setDataActivationState(activationState);
4753 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004754 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004755 }
4756 } finally {
4757 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004758 }
4759 }
4760
4761 /**
4762 * Returns the voice activation state of a given subId.
4763 */
4764 @Override
4765 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004766 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004767
fionaxu0152e512016-11-14 13:36:14 -08004768 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004769 final long identity = Binder.clearCallingIdentity();
4770 try {
4771 if (phone != null) {
4772 return phone.getVoiceActivationState();
4773 } else {
4774 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4775 }
4776 } finally {
4777 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004778 }
4779 }
4780
4781 /**
4782 * Returns the data activation state of a given subId.
4783 */
4784 @Override
4785 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004786 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004787
fionaxu0152e512016-11-14 13:36:14 -08004788 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004789 final long identity = Binder.clearCallingIdentity();
4790 try {
4791 if (phone != null) {
4792 return phone.getDataActivationState();
4793 } else {
4794 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4795 }
4796 } finally {
4797 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004798 }
4799 }
4800
4801 /**
Wink Saville36469e72014-06-11 15:17:00 -07004802 * Returns the unread count of voicemails for a subId
4803 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004804 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004805 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4806 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004807 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004808 mApp, subId, callingPackage, callingFeatureId,
4809 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004810 return 0;
4811 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004812 final long identity = Binder.clearCallingIdentity();
4813 try {
4814 final Phone phone = getPhone(subId);
4815 if (phone != null) {
4816 return phone.getVoiceMessageCount();
4817 } else {
4818 return 0;
4819 }
4820 } finally {
4821 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004822 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004823 }
4824
4825 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004826 * returns true, if the device is in a state where both voice and data
4827 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004828 */
4829 @Override
4830 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004831 final long identity = Binder.clearCallingIdentity();
4832 try {
4833 final Phone phone = getPhone(subId);
4834 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4835 } finally {
4836 Binder.restoreCallingIdentity(identity);
4837 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004838 }
4839
4840 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004841 * Send the dialer code if called from the current default dialer or the caller has
4842 * carrier privilege.
4843 * @param inputCode The dialer code to send
4844 */
4845 @Override
4846 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004847 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004848 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004849 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4850 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004851 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004852 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004853 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004854 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004855
4856 final long identity = Binder.clearCallingIdentity();
4857 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004858 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004859 } finally {
4860 Binder.restoreCallingIdentity(identity);
4861 }
fionaxu235cc5e2017-03-06 22:25:57 -08004862 }
4863
Pengquan Menga1bb6272018-09-06 09:59:22 -07004864 @Override
4865 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004866 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004867 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4868 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08004869 final long identity = Binder.clearCallingIdentity();
4870 try {
4871 if (!isActiveSubscription(subId)) {
4872 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4873 }
4874 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4875 } finally {
4876 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004877 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004878 }
4879
Brad Ebinger35c841c2018-10-01 10:40:55 -07004880 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004881 public boolean isInEmergencySmsMode() {
4882 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4883 final long identity = Binder.clearCallingIdentity();
4884 try {
4885 for (Phone phone : PhoneFactory.getPhones()) {
4886 if (phone.isInEmergencySmsMode()) {
4887 return true;
4888 }
4889 }
4890 } finally {
4891 Binder.restoreCallingIdentity(identity);
4892 }
4893 return false;
4894 }
4895
shilu366312e2019-12-17 09:28:10 -08004896 /**
4897 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4898 * @param subId The subscription to use to check the configuration.
4899 * @param c The callback that will be used to send the result.
4900 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004901 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004902 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4903 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004904 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004905 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004906
4907 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4908 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4909 "IMS not available on device.");
4910 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004911 final long token = Binder.clearCallingIdentity();
4912 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004913 int slotId = getSlotIndexOrException(subId);
4914 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004915
4916 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4917 if (controller != null) {
4918 ImsManager imsManager = controller.getImsManager(subId);
4919 if (imsManager != null) {
4920 imsManager.addRegistrationCallbackForSubscription(c, subId);
4921 } else {
4922 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4923 }
4924 } else {
4925 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4926 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004927 } catch (ImsException e) {
4928 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004929 } finally {
4930 Binder.restoreCallingIdentity(token);
4931 }
4932 }
4933
shilu366312e2019-12-17 09:28:10 -08004934 /**
4935 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4936 * @param subId The subscription to use to check the configuration.
4937 * @param c The callback that will be used to send the result.
4938 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004939 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004940 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004941 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004942 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004943 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4944 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4945 }
Meng Wangafbc5852019-09-19 17:37:13 -07004946 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004947
Meng Wangafbc5852019-09-19 17:37:13 -07004948 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004949 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4950 if (controller != null) {
4951 ImsManager imsManager = controller.getImsManager(subId);
4952 if (imsManager != null) {
4953 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4954 } else {
4955 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4956 + "is inactive, ignoring unregister.");
4957 // If the ImsManager is not valid, just return, since the callback
4958 // will already have been removed internally.
4959 }
4960 }
Meng Wangafbc5852019-09-19 17:37:13 -07004961 } finally {
4962 Binder.restoreCallingIdentity(token);
4963 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004964 }
4965
Brad Ebingera34a6c22019-10-22 17:36:18 -07004966 /**
4967 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4968 */
4969 @Override
4970 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4971 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4972 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4973 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4974 "IMS not available on device.");
4975 }
4976 final long token = Binder.clearCallingIdentity();
4977 try {
4978 Phone phone = getPhone(subId);
4979 if (phone == null) {
4980 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4981 + subId + "'");
4982 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4983 }
4984 phone.getImsRegistrationState(regState -> {
4985 try {
4986 consumer.accept((regState == null)
4987 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4988 } catch (RemoteException e) {
4989 // Ignore if the remote process is no longer available to call back.
4990 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4991 }
4992 });
4993 } finally {
4994 Binder.restoreCallingIdentity(token);
4995 }
4996 }
4997
4998 /**
4999 * Get the transport type for the IMS service registration state.
5000 */
5001 @Override
5002 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07005003 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005004 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07005005 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5006 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5007 "IMS not available on device.");
5008 }
5009 final long token = Binder.clearCallingIdentity();
5010 try {
5011 Phone phone = getPhone(subId);
5012 if (phone == null) {
5013 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
5014 + subId + "'");
5015 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5016 }
5017 phone.getImsRegistrationTech(regTech -> {
5018 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
5019 int regTechConverted = (regTech == null)
5020 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
5021 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
5022 regTechConverted);
5023 try {
5024 consumer.accept(regTechConverted);
5025 } catch (RemoteException e) {
5026 // Ignore if the remote process is no longer available to call back.
5027 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
5028 }
5029 });
5030 } finally {
5031 Binder.restoreCallingIdentity(token);
5032 }
5033 }
5034
shilu366312e2019-12-17 09:28:10 -08005035 /**
5036 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5037 * @param subId The subscription to use to check the configuration.
5038 * @param c The callback that will be used to send the result.
5039 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005040 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005041 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
5042 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07005043 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005044 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00005045 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5046 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5047 "IMS not available on device.");
5048 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07005049 final long token = Binder.clearCallingIdentity();
5050 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005051 int slotId = getSlotIndexOrException(subId);
5052 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005053
5054 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5055 if (controller != null) {
5056 ImsManager imsManager = controller.getImsManager(subId);
5057 if (imsManager != null) {
5058 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
5059 } else {
5060 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5061 }
5062 } else {
5063 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5064 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005065 } catch (ImsException e) {
5066 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005067 } finally {
5068 Binder.restoreCallingIdentity(token);
5069 }
5070 }
5071
shilu366312e2019-12-17 09:28:10 -08005072 /**
5073 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5074 * @param subId The subscription to use to check the configuration.
5075 * @param c The callback that will be used to send the result.
5076 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005077 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005078 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07005079 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005080 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005081 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5082 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5083 }
Meng Wangafbc5852019-09-19 17:37:13 -07005084
5085 final long token = Binder.clearCallingIdentity();
5086 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005087 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5088 if (controller != null) {
5089 ImsManager imsManager = controller.getImsManager(subId);
5090 if (imsManager != null) {
5091 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
5092 } else {
5093 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
5094 + " is inactive, ignoring unregister.");
5095 // If the ImsManager is not valid, just return, since the callback
5096 // will already have been removed internally.
5097 }
5098 }
Meng Wangafbc5852019-09-19 17:37:13 -07005099 } finally {
5100 Binder.restoreCallingIdentity(token);
5101 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07005102 }
5103
5104 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005105 public boolean isCapable(int subId, int capability, int regTech) {
5106 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005107 final long token = Binder.clearCallingIdentity();
5108 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005109 int slotId = getSlotIndexOrException(subId);
5110 verifyImsMmTelConfiguredOrThrow(slotId);
5111 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
5112 } catch (com.android.ims.ImsException e) {
5113 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
5114 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005115 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08005116 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
5117 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07005118 } finally {
5119 Binder.restoreCallingIdentity(token);
5120 }
5121 }
5122
5123 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005124 public boolean isAvailable(int subId, int capability, int regTech) {
5125 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005126 final long token = Binder.clearCallingIdentity();
5127 try {
5128 Phone phone = getPhone(subId);
5129 if (phone == null) return false;
5130 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07005131 } catch (com.android.ims.ImsException e) {
5132 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
5133 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07005134 } finally {
5135 Binder.restoreCallingIdentity(token);
5136 }
5137 }
5138
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005139 /**
5140 * Determines if the MmTel feature capability is supported by the carrier configuration for this
5141 * subscription.
5142 * @param subId The subscription to use to check the configuration.
5143 * @param callback The callback that will be used to send the result.
5144 * @param capability The MmTelFeature capability that will be used to send the result.
5145 * @param transportType The transport type of the MmTelFeature capability.
5146 */
5147 @Override
5148 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
5149 int transportType) {
5150 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00005151 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5152 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5153 "IMS not available on device.");
5154 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005155 final long token = Binder.clearCallingIdentity();
5156 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005157 int slotId = getSlotIndex(subId);
5158 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5159 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
5160 + subId + "'");
5161 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5162 }
5163 verifyImsMmTelConfiguredOrThrow(slotId);
5164 ImsManager.getInstance(mApp, slotId).isSupported(capability,
5165 transportType, aBoolean -> {
5166 try {
5167 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
5168 } catch (RemoteException e) {
5169 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
5170 + "running. Ignore");
5171 }
5172 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005173 } catch (ImsException e) {
5174 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005175 } finally {
5176 Binder.restoreCallingIdentity(token);
5177 }
5178 }
5179
shilu366312e2019-12-17 09:28:10 -08005180 /**
5181 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5182 * @param subId The subscription to use to check the configuration.
5183 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005184 @Override
5185 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005186 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005187 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08005188
Brad Ebinger35c841c2018-10-01 10:40:55 -07005189 final long token = Binder.clearCallingIdentity();
5190 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005191 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005192 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005193 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005194 } catch (ImsException e) {
5195 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005196 } finally {
5197 Binder.restoreCallingIdentity(token);
5198 }
5199 }
5200
5201 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005202 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005203 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005204 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005205 final long identity = Binder.clearCallingIdentity();
5206 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005207 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005208 // This setting doesn't require an active ImsService connection, so do not verify. The
5209 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005210 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005211 } catch (ImsException e) {
5212 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005213 } finally {
5214 Binder.restoreCallingIdentity(identity);
5215 }
5216 }
5217
shilu366312e2019-12-17 09:28:10 -08005218 /**
5219 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5220 * @param subId The subscription to use to check the configuration.
5221 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005222 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005223 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005224 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005225 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005226 final long identity = Binder.clearCallingIdentity();
5227 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005228 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005229 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005230 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005231 } catch (ImsException e) {
5232 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005233 } finally {
5234 Binder.restoreCallingIdentity(identity);
5235 }
5236 }
5237
5238 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005239 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005240 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005241 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005242 final long identity = Binder.clearCallingIdentity();
5243 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005244 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005245 // This setting doesn't require an active ImsService connection, so do not verify. The
5246 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005247 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005248 } catch (ImsException e) {
5249 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005250 } finally {
5251 Binder.restoreCallingIdentity(identity);
5252 }
5253 }
5254
shilu366312e2019-12-17 09:28:10 -08005255 /**
5256 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5257 * @param subId The subscription to use to check the configuration.
5258 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005259 @Override
5260 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005261 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005262 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005263 final long identity = Binder.clearCallingIdentity();
5264 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005265 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005266 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005267 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005268 } catch (ImsException e) {
5269 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005270 } finally {
5271 Binder.restoreCallingIdentity(identity);
5272 }
5273 }
5274
5275 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005276 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005277 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005278 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005279 final long identity = Binder.clearCallingIdentity();
5280 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005281 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005282 // This setting doesn't require an active ImsService connection, so do not verify. The
5283 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005284 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005285 } catch (ImsException e) {
5286 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005287 } finally {
5288 Binder.restoreCallingIdentity(identity);
5289 }
5290 }
5291
shilu366312e2019-12-17 09:28:10 -08005292 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005293 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5294 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5295 * @param subId The subscription to use to check the configuration.
5296 */
5297 @Override
5298 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005299 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005300 mApp, subId, "isCrossSimCallingEnabledByUser");
5301 final long identity = Binder.clearCallingIdentity();
5302 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005303 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005304 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005305 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005306 } catch (ImsException e) {
5307 throw new ServiceSpecificException(e.getCode());
5308 } finally {
5309 Binder.restoreCallingIdentity(identity);
5310 }
5311 }
5312
5313 /**
5314 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5315 * Requires MODIFY_PHONE_STATE permission.
5316 * @param subId The subscription to use to check the configuration.
5317 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5318 * false otherwise
5319 */
5320 @Override
5321 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5323 "setCrossSimCallingEnabled");
5324 final long identity = Binder.clearCallingIdentity();
5325 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005326 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005327 // This setting doesn't require an active ImsService connection, so do not verify. The
5328 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005329 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005330 } catch (ImsException e) {
5331 throw new ServiceSpecificException(e.getCode());
5332 } finally {
5333 Binder.restoreCallingIdentity(identity);
5334 }
5335 }
5336
5337 /**
shilu366312e2019-12-17 09:28:10 -08005338 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5339 * @param subId The subscription to use to check the configuration.
5340 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005341 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005342
Brad Ebinger35c841c2018-10-01 10:40:55 -07005343 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005344 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005345 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005346 final long identity = Binder.clearCallingIdentity();
5347 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005348 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005349 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005350 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005351 } catch (ImsException e) {
5352 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005353 } finally {
5354 Binder.restoreCallingIdentity(identity);
5355 }
5356 }
5357
5358 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005359 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005361 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005362 final long identity = Binder.clearCallingIdentity();
5363 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005364 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005365 // This setting doesn't require an active ImsService connection, so do not verify. The
5366 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005367 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005368 } catch (ImsException e) {
5369 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005370 } finally {
5371 Binder.restoreCallingIdentity(identity);
5372 }
5373 }
5374
5375 @Override
5376 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5378 "setVoWiFiNonPersistent");
5379 final long identity = Binder.clearCallingIdentity();
5380 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005381 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005382 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005383 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005384 } catch (ImsException e) {
5385 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005386 } finally {
5387 Binder.restoreCallingIdentity(identity);
5388 }
5389 }
5390
shilu366312e2019-12-17 09:28:10 -08005391 /**
5392 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5393 * @param subId The subscription to use to check the configuration.
5394 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005395 @Override
5396 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005397 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005398 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005399 final long identity = Binder.clearCallingIdentity();
5400 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005401 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005402 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005403 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005404 } catch (ImsException e) {
5405 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005406 } finally {
5407 Binder.restoreCallingIdentity(identity);
5408 }
5409 }
5410
5411 @Override
5412 public void setVoWiFiModeSetting(int subId, int mode) {
5413 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5414 "setVoWiFiModeSetting");
5415 final long identity = Binder.clearCallingIdentity();
5416 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005417 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005418 // This setting doesn't require an active ImsService connection, so do not verify. The
5419 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005420 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005421 } catch (ImsException e) {
5422 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005423 } finally {
5424 Binder.restoreCallingIdentity(identity);
5425 }
5426 }
5427
5428 @Override
5429 public int getVoWiFiRoamingModeSetting(int subId) {
5430 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
5431 final long identity = Binder.clearCallingIdentity();
5432 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005433 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005434 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005435 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005436 } catch (ImsException e) {
5437 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005438 } finally {
5439 Binder.restoreCallingIdentity(identity);
5440 }
5441 }
5442
5443 @Override
5444 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5446 "setVoWiFiRoamingModeSetting");
5447 final long identity = Binder.clearCallingIdentity();
5448 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005449 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005450 // This setting doesn't require an active ImsService connection, so do not verify. The
5451 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005452 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005453 } catch (ImsException e) {
5454 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005455 } finally {
5456 Binder.restoreCallingIdentity(identity);
5457 }
5458 }
5459
5460 @Override
5461 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5462 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5463 "setRttCapabilityEnabled");
5464 final long identity = Binder.clearCallingIdentity();
5465 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005466 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005467 // This setting doesn't require an active ImsService connection, so do not verify. The
5468 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005469 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005470 } catch (ImsException e) {
5471 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005472 } finally {
5473 Binder.restoreCallingIdentity(identity);
5474 }
5475 }
5476
shilu366312e2019-12-17 09:28:10 -08005477 /**
5478 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5479 * @param subId The subscription to use to check the configuration.
5480 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005481 @Override
5482 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005483 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005484 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005485 final long identity = Binder.clearCallingIdentity();
5486 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005487 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005488 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005489 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005490 } catch (ImsException e) {
5491 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005492 } finally {
5493 Binder.restoreCallingIdentity(identity);
5494 }
5495 }
5496
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005497 @Override
5498 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5499 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005500
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005501 final long identity = Binder.clearCallingIdentity();
5502 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005503 if (!isImsAvailableOnDevice()) {
5504 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5505 "IMS not available on device.");
5506 }
5507 int slotId = getSlotIndexOrException(subId);
5508 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005509
5510 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5511 if (controller != null) {
5512 ImsManager imsManager = controller.getImsManager(subId);
5513 if (imsManager != null) {
5514 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5515 } else {
5516 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5517 }
5518 } else {
5519 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5520 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005521 } catch (ImsException e) {
5522 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005523 } finally {
5524 Binder.restoreCallingIdentity(identity);
5525 }
5526 }
5527
5528 @Override
5529 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5530 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005531
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005532 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005533 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5534 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5535 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005536 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005537 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5538 if (controller != null) {
5539 ImsManager imsManager = controller.getImsManager(subId);
5540 if (imsManager != null) {
5541 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5542 } else {
5543 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5544 + " is inactive, ignoring unregister.");
5545 // If the ImsManager is not valid, just return, since the callback will already
5546 // have been removed internally.
5547 }
5548 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005549 } finally {
5550 Binder.restoreCallingIdentity(identity);
5551 }
5552 }
5553
joonhunshincffb7fc2021-11-28 07:32:01 +00005554 @Override
5555 public void registerFeatureProvisioningChangedCallback(int subId,
5556 IFeatureProvisioningCallback callback) {
5557 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5558 mApp, subId, "registerFeatureProvisioningChangedCallback");
5559
5560 final long identity = Binder.clearCallingIdentity();
5561 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5562 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5563 }
5564
joonhunshin91bc1952022-04-29 08:47:15 +00005565 try {
5566 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5567 if (controller == null) {
5568 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5569 "Device does not support IMS");
5570 }
5571 controller.addFeatureProvisioningChangedCallback(subId, callback);
5572 } finally {
5573 Binder.restoreCallingIdentity(identity);
5574 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005575 }
5576
5577 @Override
5578 public void unregisterFeatureProvisioningChangedCallback(int subId,
5579 IFeatureProvisioningCallback callback) {
5580 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5581 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5582
5583 final long identity = Binder.clearCallingIdentity();
5584 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5585 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5586 }
5587
joonhunshin91bc1952022-04-29 08:47:15 +00005588 try {
5589 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5590 if (controller == null) {
5591 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5592 return;
5593 }
5594 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5595 } finally {
5596 Binder.restoreCallingIdentity(identity);
5597 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005598 }
allenwtsu99c623b2020-01-03 18:24:23 +08005599
5600 private void checkModifyPhoneStatePermission(int subId, String message) {
5601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5602 message);
5603 }
5604
allenwtsu99c623b2020-01-03 18:24:23 +08005605 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005606 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005607 boolean isProvisioned) {
5608 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5609
5610 final long identity = Binder.clearCallingIdentity();
5611 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005612 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5613 if (controller == null) {
5614 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5615 return;
5616 }
5617 controller.setRcsProvisioningStatusForCapability(
5618 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005619 } finally {
5620 Binder.restoreCallingIdentity(identity);
5621 }
allenwtsu99c623b2020-01-03 18:24:23 +08005622 }
5623
5624
5625 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005626 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5627 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5628 mApp, subId, "getRcsProvisioningStatusForCapability");
5629
allenwtsu99c623b2020-01-03 18:24:23 +08005630 final long identity = Binder.clearCallingIdentity();
5631 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005632 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5633 if (controller == null) {
5634 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5635
5636 // device does not support IMS, this method will return true always.
5637 return true;
5638 }
5639 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005640 } finally {
5641 Binder.restoreCallingIdentity(identity);
5642 }
5643 }
5644
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005645 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005646 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5647 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005648 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005649
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005650 final long identity = Binder.clearCallingIdentity();
5651 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005652 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5653 if (controller == null) {
5654 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5655 return;
5656 }
5657 controller.setImsProvisioningStatusForCapability(
5658 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005659 } finally {
5660 Binder.restoreCallingIdentity(identity);
5661 }
5662 }
5663
5664 @Override
5665 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005666 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5667 mApp, subId, "getProvisioningStatusForCapability");
5668
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005669 final long identity = Binder.clearCallingIdentity();
5670 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005671 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5672 if (controller == null) {
5673 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005674
joonhunshin91bc1952022-04-29 08:47:15 +00005675 // device does not support IMS, this method will return true always.
5676 return true;
5677 }
5678 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005679 } finally {
5680 Binder.restoreCallingIdentity(identity);
5681 }
5682 }
5683
5684 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005685 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5686 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5687 mApp, subId, "isProvisioningRequiredForCapability");
5688
5689 final long identity = Binder.clearCallingIdentity();
5690 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005691 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5692 if (controller == null) {
5693 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5694
5695 // device does not support IMS, this method will return false
5696 return false;
5697 }
5698 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005699 } finally {
5700 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005701 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005702 }
5703
5704 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005705 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5706 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5707 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005708
joonhunshincffb7fc2021-11-28 07:32:01 +00005709 final long identity = Binder.clearCallingIdentity();
5710 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005711 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5712 if (controller == null) {
5713 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5714
5715 // device does not support IMS, this method will return false
5716 return false;
5717 }
5718 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005719 } finally {
5720 Binder.restoreCallingIdentity(identity);
5721 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005722 }
5723
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005724 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005725 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005726 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5727 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5728 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005729 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5730 mApp, subId, "getImsProvisioningInt");
5731
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005732 final long identity = Binder.clearCallingIdentity();
5733 try {
5734 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005735 int slotId = getSlotIndex(subId);
5736 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5737 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5738 + subId + "' for key:" + key);
5739 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5740 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005741
joonhunshin91bc1952022-04-29 08:47:15 +00005742 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5743 if (controller == null) {
5744 loge("getImsProvisioningInt: Device does not support IMS");
5745
5746 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5747 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5748 }
5749 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005750 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5751 return retVal;
5752 }
5753
calvinpanb5a34062021-02-08 19:59:36 +08005754 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005755 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005756 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5757 + subId + "' for key:" + key);
5758 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005759 } finally {
5760 Binder.restoreCallingIdentity(identity);
5761 }
5762 }
5763
5764 @Override
5765 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005766 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5767 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5768 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005769 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5770 mApp, subId, "getImsProvisioningString");
5771
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005772 final long identity = Binder.clearCallingIdentity();
5773 try {
5774 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005775 int slotId = getSlotIndex(subId);
5776 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5777 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5778 + subId + "' for key:" + key);
5779 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5780 }
calvinpanb5a34062021-02-08 19:59:36 +08005781 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005782 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005783 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5784 + subId + "' for key:" + key);
5785 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005786 } finally {
5787 Binder.restoreCallingIdentity(identity);
5788 }
5789 }
5790
5791 @Override
5792 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005793 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5794 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5795 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5797 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005798
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005799 final long identity = Binder.clearCallingIdentity();
5800 try {
5801 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005802 int slotId = getSlotIndex(subId);
5803 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5804 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5805 + subId + "' for key:" + key);
5806 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5807 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005808
joonhunshin91bc1952022-04-29 08:47:15 +00005809 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5810 if (controller == null) {
5811 loge("setImsProvisioningInt: Device does not support IMS");
5812
5813 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5814 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5815 }
5816 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005817 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5818 return retVal;
5819 }
5820
calvinpanb5a34062021-02-08 19:59:36 +08005821 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5822 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005823 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005824 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005825 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005826 } finally {
5827 Binder.restoreCallingIdentity(identity);
5828 }
5829 }
5830
5831 @Override
5832 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005833 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5834 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5835 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5837 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005838 final long identity = Binder.clearCallingIdentity();
5839 try {
5840 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005841 int slotId = getSlotIndex(subId);
5842 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5843 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5844 + subId + "' for key:" + key);
5845 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5846 }
calvinpanb5a34062021-02-08 19:59:36 +08005847 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5848 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005849 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005850 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005851 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005852 } finally {
5853 Binder.restoreCallingIdentity(identity);
5854 }
5855 }
5856
Brad Ebinger919631e2021-06-02 17:46:35 -07005857 /**
5858 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5859 * for the given slot ID or no ImsResolver instance has been created.
5860 * @param slotId The slot ID that the IMS service is created for.
5861 * @throws ImsException If there is no ImsService configured for this slot.
5862 */
5863 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5864 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5865 ImsFeature.FEATURE_MMTEL)) {
5866 throw new ImsException("This subscription does not support MMTEL over IMS",
5867 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5868 }
5869 }
5870
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005871 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005872 int slotId = SubscriptionManager.getSlotIndex(subId);
5873 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005874 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5875 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005876 }
5877 return slotId;
5878 }
5879
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005880 private int getSlotIndex(int subId) {
5881 int slotId = SubscriptionManager.getSlotIndex(subId);
5882 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5883 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5884 }
5885 return slotId;
5886 }
5887
Wink Saville36469e72014-06-11 15:17:00 -07005888 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005889 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005890 */
5891 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005892 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5893 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005894 try {
5895 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5896 } catch (SecurityException se) {
5897 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5898 throw new SecurityException("Package " + callingPackage + " does not belong to "
5899 + Binder.getCallingUid());
5900 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005901 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005902 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005903 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005904 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005905 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005906 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005907 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005908 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5909 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005910
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005911 final long identity = Binder.clearCallingIdentity();
5912 try {
5913 final Phone phone = getPhone(subId);
5914 if (phone != null) {
5915 return phone.getServiceState().getDataNetworkType();
5916 } else {
5917 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5918 }
5919 } finally {
5920 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005921 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005922 }
5923
5924 /**
5925 * Returns the data network type
5926 */
5927 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005928 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005929 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005930 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005931 }
5932
5933 /**
5934 * Returns the data network type for a subId
5935 */
5936 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005937 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5938 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005939 String functionName = "getDataNetworkTypeForSubscriber";
5940 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5941 mApp, functionName)) {
5942 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5943 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5944 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5945 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005946 }
5947
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005948 final long identity = Binder.clearCallingIdentity();
5949 try {
5950 final Phone phone = getPhone(subId);
5951 if (phone != null) {
5952 return phone.getServiceState().getDataNetworkType();
5953 } else {
5954 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5955 }
5956 } finally {
5957 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005958 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005959 }
5960
5961 /**
Wink Saville36469e72014-06-11 15:17:00 -07005962 * Returns the Voice network type for a subId
5963 */
5964 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005965 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5966 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005967 String functionName = "getVoiceNetworkTypeForSubscriber";
5968 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5969 mApp, functionName)) {
5970 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5971 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5972 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5973 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005974 }
5975
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005976 final long identity = Binder.clearCallingIdentity();
5977 try {
5978 final Phone phone = getPhone(subId);
5979 if (phone != null) {
5980 return phone.getServiceState().getVoiceNetworkType();
5981 } else {
5982 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5983 }
5984 } finally {
5985 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005986 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005987 }
5988
5989 /**
5990 * @return true if a ICC card is present
5991 */
5992 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005993 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005994 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005995 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005996 }
5997
5998 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005999 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07006000 */
Sanket Padawe356d7632015-06-22 14:03:32 -07006001 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006002 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003 final long identity = Binder.clearCallingIdentity();
6004 try {
6005 final Phone phone = PhoneFactory.getPhone(slotIndex);
6006 if (phone != null) {
6007 return phone.getIccCard().hasIccCard();
6008 } else {
6009 return false;
6010 }
6011 } finally {
6012 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08006013 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006014 }
6015
6016 /**
6017 * Return if the current radio is LTE on CDMA. This
6018 * is a tri-state return value as for a period of time
6019 * the mode may be unknown.
6020 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006021 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006022 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08006023 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006024 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006025 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006026 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
6027 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
6028 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07006029 }
6030
Sanket Padawe356d7632015-06-22 14:03:32 -07006031 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006032 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
6033 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08006034 try {
6035 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
6036 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006037 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
6038 }
6039
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006040 final long identity = Binder.clearCallingIdentity();
6041 try {
6042 final Phone phone = getPhone(subId);
6043 if (phone == null) {
6044 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
6045 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07006046 return TelephonyProperties.lte_on_cdma_device()
6047 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006048 }
6049 } finally {
6050 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006051 }
Wink Saville36469e72014-06-11 15:17:00 -07006052 }
6053
Wink Saville36469e72014-06-11 15:17:00 -07006054 /**
6055 * {@hide}
6056 * Returns Default subId, 0 in the case of single standby.
6057 */
Wink Savilleb564aae2014-10-23 10:18:09 -07006058 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08006059 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07006060 }
6061
Shishir Agrawala9f32182016-04-12 12:00:16 -07006062 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08006063 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07006064 }
6065
Wink Savilleb564aae2014-10-23 10:18:09 -07006066 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08006067 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006068 }
Ihab Awadf2177b72013-11-25 13:33:23 -08006069
Pengquan Menge92a50d2018-09-21 15:54:48 -07006070 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08006071 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08006072 return getSubscriptionManagerService().isActiveSubId(subId,
Jack Yu285100e2022-12-02 22:48:35 -08006073 mApp.getOpPackageName(), mApp.getFeatureId());
6074 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07006075 return mSubscriptionController.isActiveSubId(subId);
6076 }
6077
Ihab Awadf2177b72013-11-25 13:33:23 -08006078 /**
6079 * @see android.telephony.TelephonyManager.WifiCallingChoices
6080 */
6081 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006082 final long identity = Binder.clearCallingIdentity();
6083 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006084 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006085 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
6086 getWhenToMakeWifiCallsDefaultPreference());
6087 } finally {
6088 Binder.restoreCallingIdentity(identity);
6089 }
Ihab Awadf2177b72013-11-25 13:33:23 -08006090 }
6091
6092 /**
6093 * @see android.telephony.TelephonyManager.WifiCallingChoices
6094 */
6095 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006096 final long identity = Binder.clearCallingIdentity();
6097 try {
6098 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006099 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006100 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
6101 } finally {
6102 Binder.restoreCallingIdentity(identity);
6103 }
Ihab Awadf9e92732013-12-05 18:02:52 -08006104 }
6105
Sailesh Nepald1e68152013-12-12 19:08:02 -08006106 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07006107 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08006108 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08006109 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08006110
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006111 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
6112 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
6113 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08006114 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006115 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006116 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08006117 }
6118 return PhoneFactory.getPhone(phoneId);
6119 }
6120
Shishir Agrawal566b7612013-10-28 14:41:00 -07006121 @Override
Derek Tan740e1672017-06-27 14:56:27 -07006122 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08006123 @NonNull IccLogicalChannelRequest request) {
6124 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6125 /*message=*/ "iccOpenLogicalChannel");
6126
6127 if (DBG) log("iccOpenLogicalChannel: request=" + request);
6128 // Verify that the callingPackage in the request belongs to the calling UID
6129 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
6130
6131 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006132 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006133
Rambo Wanga1782702021-11-10 20:15:19 -08006134 private Phone getPhoneFromValidIccLogicalChannelRequest(
6135 @NonNull IccLogicalChannelRequest request, String message) {
6136 Phone phone;
6137 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
6138 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6139 mApp, request.subId, message);
6140 phone = getPhoneFromSubId(request.subId);
6141 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6142 enforceModifyPermission();
6143 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
6144 } else {
6145 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08006146 }
Rambo Wanga1782702021-11-10 20:15:19 -08006147 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08006148 }
6149
6150 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08006151 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006152 final long identity = Binder.clearCallingIdentity();
6153 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006154 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006155 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006156 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6157 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08006158 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
6159 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006160 loge("The calling package is not allowed to access ISD-R.");
6161 throw new SecurityException(
6162 "The calling package is not allowed to access ISD-R.");
6163 }
Derek Tan740e1672017-06-27 14:56:27 -07006164 }
Derek Tan740e1672017-06-27 14:56:27 -07006165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006166 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006167 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6168 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006169 return response;
6170 } finally {
6171 Binder.restoreCallingIdentity(identity);
6172 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006173 }
6174
6175 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006176 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
6177 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6178 /*message=*/"iccCloseLogicalChannel");
6179
6180 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6181
6182 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006183 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006184
Rambo Wanga1782702021-11-10 20:15:19 -08006185 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6186 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006187 // before this feature is enabled, this API should only return false if
6188 // the operation fails instead of throwing runtime exception for
6189 // backward-compatibility.
6190 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6191 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006192 final long identity = Binder.clearCallingIdentity();
6193 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006194 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006195 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006196 }
Chen Xue9d737e2022-01-01 23:41:31 -08006197 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006198 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006199 Boolean success = false;
6200 if (result instanceof RuntimeException) {
6201 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006202 if (shouldThrowExceptionOnFailure) {
6203 throw (RuntimeException) result;
6204 } else {
6205 return false;
6206 }
Chen Xue9d737e2022-01-01 23:41:31 -08006207 } else if (result instanceof Boolean) {
6208 success = (Boolean) result;
6209 } else {
6210 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6211 }
Rambo Wanga1782702021-11-10 20:15:19 -08006212 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006213 return success;
6214 } finally {
6215 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006216 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006217 }
6218
6219 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006220 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006221 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006222 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6223 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08006224 if (DBG) {
6225 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6226 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6227 + p3 + " data=" + data);
6228 }
6229 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6230 command, p1, p2, p3, data);
6231 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006232
Jordan Liu4c733742019-02-28 12:03:40 -08006233 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006234 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006235 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006236 enforceModifyPermission();
6237 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006238 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006239 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6240 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006241 }
6242 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006243 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6244 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006245 }
6246
6247 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6248 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006249 final long identity = Binder.clearCallingIdentity();
6250 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006251 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006252 return "";
6253 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006254
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006255 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006256 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6257 null /* workSource */);
6258 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006259
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006260 // Append the returned status code to the end of the response payload.
6261 String s = Integer.toHexString(
6262 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6263 if (response.payload != null) {
6264 s = IccUtils.bytesToHexString(response.payload) + s;
6265 }
6266 return s;
6267 } finally {
6268 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006269 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006270 }
Jake Hambye994d462014-02-03 13:10:13 -08006271
Evan Charltonc66da362014-05-16 14:06:40 -07006272 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006273 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6274 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006275 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6276 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006277 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08006278 if (DBG) {
6279 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6280 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6281 }
6282 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6283 cla, command, p1, p2, p3, data);
6284 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006285
Jordan Liu4c733742019-02-28 12:03:40 -08006286 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006287 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006288 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006289 enforceModifyPermission();
6290 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6291 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006292 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006293 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6294 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006295 }
6296
6297 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006298 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6299 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006300 }
6301
6302 // open APDU basic channel assuming the caller has sufficient permissions
6303 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6304 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006305 final long identity = Binder.clearCallingIdentity();
6306 try {
6307 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6308 && TextUtils.equals(ISDR_AID, data)) {
6309 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006310 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6311 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006312 if (bestComponent == null
6313 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6314 loge("The calling package is not allowed to select ISD-R.");
6315 throw new SecurityException(
6316 "The calling package is not allowed to select ISD-R.");
6317 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006318 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006319
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006320 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006321 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6322 null /* workSource */);
6323 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006324
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006325 // Append the returned status code to the end of the response payload.
6326 String s = Integer.toHexString(
6327 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6328 if (response.payload != null) {
6329 s = IccUtils.bytesToHexString(response.payload) + s;
6330 }
6331 return s;
6332 } finally {
6333 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006334 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006335 }
6336
6337 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006338 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006339 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6341 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006342
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006343 final long identity = Binder.clearCallingIdentity();
6344 try {
6345 if (DBG) {
6346 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6347 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6348 }
6349
6350 IccIoResult response =
6351 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6352 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6353 subId);
6354
6355 if (DBG) {
6356 log("Exchange SIM_IO [R]" + response);
6357 }
6358
6359 byte[] result = null;
6360 int length = 2;
6361 if (response.payload != null) {
6362 length = 2 + response.payload.length;
6363 result = new byte[length];
6364 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6365 } else {
6366 result = new byte[length];
6367 }
6368
6369 result[length - 1] = (byte) response.sw2;
6370 result[length - 2] = (byte) response.sw1;
6371 return result;
6372 } finally {
6373 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006374 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006375 }
6376
Nathan Haroldb3014052017-01-25 15:57:32 -08006377 /**
6378 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6379 * on a particular subscription
6380 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006381 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6382 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006383 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006384 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006385 return null;
6386 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006387
6388 final long identity = Binder.clearCallingIdentity();
6389 try {
6390 if (appType != TelephonyManager.APPTYPE_USIM
6391 && appType != TelephonyManager.APPTYPE_SIM) {
6392 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6393 return null;
6394 }
6395 Object response = sendRequest(
6396 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6397 if (response instanceof String[]) {
6398 return (String[]) response;
6399 }
yincheng zhao2737e882019-09-06 17:06:54 -07006400 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006401 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006402 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006403 } finally {
6404 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006405 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006406 }
6407
yincheng zhao2737e882019-09-06 17:06:54 -07006408 /**
6409 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6410 * subscription.
6411 *
6412 * @param subId the id of the subscription.
6413 * @param appType the uicc app type, must be USIM or SIM.
6414 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6415 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006416 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006417 * @return number of fplmns that is successfully written to the SIM.
6418 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006419 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6420 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6422 mApp, subId, "setForbiddenPlmns");
6423
yincheng zhao2737e882019-09-06 17:06:54 -07006424 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6425 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6426 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6427 }
6428 if (fplmns == null) {
6429 throw new IllegalArgumentException("Fplmn List provided is null");
6430 }
6431 for (String fplmn : fplmns) {
6432 if (!CellIdentity.isValidPlmn(fplmn)) {
6433 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6434 }
6435 }
6436 final long identity = Binder.clearCallingIdentity();
6437 try {
6438 Object response = sendRequest(
6439 CMD_SET_FORBIDDEN_PLMNS,
6440 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6441 subId);
6442 return (int) response;
6443 } finally {
6444 Binder.restoreCallingIdentity(identity);
6445 }
6446 }
6447
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006448 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006449 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006450 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6451 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006452
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006453 final long identity = Binder.clearCallingIdentity();
6454 try {
6455 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6456 if (response.payload == null) {
6457 return "";
6458 }
Evan Charltonc66da362014-05-16 14:06:40 -07006459
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006460 // Append the returned status code to the end of the response payload.
6461 String s = Integer.toHexString(
6462 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6463 s = IccUtils.bytesToHexString(response.payload) + s;
6464 return s;
6465 } finally {
6466 Binder.restoreCallingIdentity(identity);
6467 }
Evan Charltonc66da362014-05-16 14:06:40 -07006468 }
6469
Jake Hambye994d462014-02-03 13:10:13 -08006470 /**
6471 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6472 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6473 *
6474 * @param itemID the ID of the item to read
6475 * @return the NV item as a String, or null on error.
6476 */
6477 @Override
6478 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006479 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006480 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6481 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006482
6483 final long identity = Binder.clearCallingIdentity();
6484 try {
6485 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006486 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006487 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6488 return value;
6489 } finally {
6490 Binder.restoreCallingIdentity(identity);
6491 }
Jake Hambye994d462014-02-03 13:10:13 -08006492 }
6493
6494 /**
6495 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6496 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6497 *
6498 * @param itemID the ID of the item to read
6499 * @param itemValue the value to write, as a String
6500 * @return true on success; false on any failure
6501 */
6502 @Override
6503 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006504 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006505 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6506 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006507
6508 final long identity = Binder.clearCallingIdentity();
6509 try {
6510 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6511 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006512 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006513 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6514 return success;
6515 } finally {
6516 Binder.restoreCallingIdentity(identity);
6517 }
Jake Hambye994d462014-02-03 13:10:13 -08006518 }
6519
6520 /**
6521 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6522 * Used for device configuration by some CDMA operators.
6523 *
6524 * @param preferredRoamingList byte array containing the new PRL
6525 * @return true on success; false on any failure
6526 */
6527 @Override
6528 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6530 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006531
6532 final long identity = Binder.clearCallingIdentity();
6533 try {
6534 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6535 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6536 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6537 return success;
6538 } finally {
6539 Binder.restoreCallingIdentity(identity);
6540 }
Jake Hambye994d462014-02-03 13:10:13 -08006541 }
6542
6543 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006544 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006545 * Used for device configuration by some CDMA operators.
6546 *
chen xu6dac5ab2018-10-26 17:39:23 -07006547 * @param slotIndex - device slot.
6548 *
Jake Hambye994d462014-02-03 13:10:13 -08006549 * @return true on success; false on any failure
6550 */
6551 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006552 public boolean resetModemConfig(int slotIndex) {
6553 Phone phone = PhoneFactory.getPhone(slotIndex);
6554 if (phone != null) {
6555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6556 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006557
chen xu6dac5ab2018-10-26 17:39:23 -07006558 final long identity = Binder.clearCallingIdentity();
6559 try {
6560 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6561 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6562 return success;
6563 } finally {
6564 Binder.restoreCallingIdentity(identity);
6565 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006566 }
chen xu6dac5ab2018-10-26 17:39:23 -07006567 return false;
6568 }
6569
6570 /**
6571 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6572 *
6573 * @param slotIndex - device slot.
6574 *
6575 * @return true on success; false on any failure
6576 */
6577 @Override
6578 public boolean rebootModem(int slotIndex) {
6579 Phone phone = PhoneFactory.getPhone(slotIndex);
6580 if (phone != null) {
6581 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6582 mApp, phone.getSubId(), "rebootModem");
6583
6584 final long identity = Binder.clearCallingIdentity();
6585 try {
6586 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6587 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6588 return success;
6589 } finally {
6590 Binder.restoreCallingIdentity(identity);
6591 }
6592 }
6593 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006594 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006595
Brad Ebinger51f743a2017-01-23 13:50:20 -08006596 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006597 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6598 * {@link #disableIms(int)}.
6599 * @param slotIndex device slot.
6600 */
6601 public void resetIms(int slotIndex) {
6602 enforceModifyPermission();
6603
6604 final long identity = Binder.clearCallingIdentity();
6605 try {
6606 if (mImsResolver == null) {
6607 // may happen if the does not support IMS.
6608 return;
6609 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006610 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006611 } finally {
6612 Binder.restoreCallingIdentity(identity);
6613 }
6614 }
6615
6616 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006617 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6618 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006619 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006620 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006621 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006622
6623 final long identity = Binder.clearCallingIdentity();
6624 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006625 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006626 // may happen if the device does not support IMS.
6627 return;
6628 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006629 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006630 } finally {
6631 Binder.restoreCallingIdentity(identity);
6632 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006633 }
6634
6635 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006636 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6637 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006638 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006639 public void disableIms(int slotId) {
6640 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006641
6642 final long identity = Binder.clearCallingIdentity();
6643 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006644 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006645 // may happen if the device does not support IMS.
6646 return;
6647 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006648 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006649 } finally {
6650 Binder.restoreCallingIdentity(identity);
6651 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006652 }
6653
6654 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006655 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6656 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006657 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006658 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006659 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006660 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006661
6662 final long identity = Binder.clearCallingIdentity();
6663 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006664 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006665 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6666 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006667 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006668 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006669 } finally {
6670 Binder.restoreCallingIdentity(identity);
6671 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006672 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006673 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006674 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6675 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006676 @Override
6677 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006678 enforceModifyPermission();
6679
6680 final long identity = Binder.clearCallingIdentity();
6681 try {
6682 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006683 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006684 } finally {
6685 Binder.restoreCallingIdentity(identity);
6686 }
6687 }
6688
6689 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006690 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006691 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006692 */
6693 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6694 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006695
6696 final long identity = Binder.clearCallingIdentity();
6697 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006698 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006699 // may happen if the device does not support IMS.
6700 return null;
6701 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006702 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006703 } finally {
6704 Binder.restoreCallingIdentity(identity);
6705 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006706 }
6707
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006708 /**
6709 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006710 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006711 */
6712 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6713 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006714
6715 final long identity = Binder.clearCallingIdentity();
6716 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006717 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006718 // may happen if the device does not support IMS.
6719 return null;
6720 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006721 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006722 } finally {
6723 Binder.restoreCallingIdentity(identity);
6724 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006725 }
6726
Brad Ebinger884c07b2018-02-15 16:17:40 -08006727 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006728 * Sets the ImsService Package Name that Telephony will bind to.
6729 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006730 * @param slotIndex the slot ID that the ImsService should bind for.
6731 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006732 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006733 * @param featureTypes An integer array of feature types associated with a packageName.
6734 * @param packageName The name of the package that the current configuration will be replaced
6735 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006736 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006737 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006738 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6739 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006740 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006741 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006742 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006743
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006744 final long identity = Binder.clearCallingIdentity();
6745 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006746 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006747 // may happen if the device does not support IMS.
6748 return false;
6749 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006750 Map<Integer, String> featureConfig = new HashMap<>();
6751 for (int featureType : featureTypes) {
6752 featureConfig.put(featureType, packageName);
6753 }
6754 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6755 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006756 } finally {
6757 Binder.restoreCallingIdentity(identity);
6758 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006759 }
6760
6761 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006762 * Clears any carrier ImsService overrides for the slot index specified that were previously
6763 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6764 *
6765 * This should only be used for testing.
6766 *
6767 * @param slotIndex the slot ID that the ImsService should bind for.
6768 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6769 */
6770 @Override
6771 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006772 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6773 "clearCarrierImsServiceOverride");
6774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006775 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006776
6777 final long identity = Binder.clearCallingIdentity();
6778 try {
6779 if (mImsResolver == null) {
6780 // may happen if the device does not support IMS.
6781 return false;
6782 }
6783 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6784 } finally {
6785 Binder.restoreCallingIdentity(identity);
6786 }
6787 }
6788
6789 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006790 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006791 *
6792 * @param slotId The slot that the ImsService is associated with.
6793 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6794 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006795 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006796 * @return the package name of the ImsService configuration.
6797 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006798 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6799 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006800 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006801 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6802 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006803
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006804 final long identity = Binder.clearCallingIdentity();
6805 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006806 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006807 // may happen if the device does not support IMS.
6808 return "";
6809 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006810 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006811 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6812 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006813 } finally {
6814 Binder.restoreCallingIdentity(identity);
6815 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006816 }
6817
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006818 /**
6819 * Get the MmTelFeature state associated with the requested subscription id.
6820 * @param subId The subscription that the MmTelFeature is associated with.
6821 * @param callback A callback with an integer containing the
6822 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6823 */
6824 @Override
6825 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6826 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006827 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6828 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6829 "IMS not available on device.");
6830 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006831 final long token = Binder.clearCallingIdentity();
6832 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006833 int slotId = getSlotIndex(subId);
6834 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6835 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6836 + subId + "'");
6837 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6838 }
6839 verifyImsMmTelConfiguredOrThrow(slotId);
6840 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6841 try {
6842 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6843 } catch (RemoteException e) {
6844 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6845 + "Ignore");
6846 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006847 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006848 } catch (ImsException e) {
6849 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006850 } finally {
6851 Binder.restoreCallingIdentity(token);
6852 }
6853 }
6854
Daniel Brightbb5840b2021-01-12 15:48:18 -08006855 /**
6856 * Sets the ims registration state on all valid {@link Phone}s.
6857 */
6858 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006859 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006860
6861 final long identity = Binder.clearCallingIdentity();
6862 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006863 // NOTE: Before S, this method only set the default phone.
6864 for (final Phone phone : PhoneFactory.getPhones()) {
6865 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6866 phone.setImsRegistrationState(registered);
6867 }
6868 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006869 } finally {
6870 Binder.restoreCallingIdentity(identity);
6871 }
Wink Saville36469e72014-06-11 15:17:00 -07006872 }
6873
6874 /**
Stuart Scott54788802015-03-30 13:18:01 -07006875 * Set the network selection mode to automatic.
6876 *
6877 */
6878 @Override
6879 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006880 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6881 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006882
6883 final long identity = Binder.clearCallingIdentity();
6884 try {
shilufc958392020-01-20 11:36:01 -08006885 if (!isActiveSubscription(subId)) {
6886 return;
6887 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006888 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006889 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6890 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006891 } finally {
6892 Binder.restoreCallingIdentity(identity);
6893 }
Stuart Scott54788802015-03-30 13:18:01 -07006894 }
6895
Jack Yud10cdd42020-09-28 20:28:01 -07006896 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006897 * Ask the radio to connect to the input network and change selection mode to manual.
6898 *
6899 * @param subId the id of the subscription.
6900 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6901 * the operator to attach to.
6902 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6903 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6904 * normal network selection next time.
6905 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006906 */
6907 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006908 public boolean setNetworkSelectionModeManual(
6909 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006910 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6911 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006912
Jack Yu285100e2022-12-02 22:48:35 -08006913 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006914 if (!isActiveSubscription(subId)) {
6915 return false;
6916 }
6917
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006918 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006919 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006920 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006921 if (DBG) {
6922 log("setNetworkSelectionModeManual: subId: " + subId
6923 + " operator: " + operatorInfo);
6924 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006925 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6926 } finally {
6927 Binder.restoreCallingIdentity(identity);
6928 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006929 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006930 /**
shilu84f6e8b2019-12-19 13:58:01 -08006931 * Get the manual network selection
6932 *
6933 * @param subId the id of the subscription.
6934 *
6935 * @return the previously saved user selected PLMN
6936 */
6937 @Override
6938 public String getManualNetworkSelectionPlmn(int subId) {
6939 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006940 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6941 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006942
6943 final long identity = Binder.clearCallingIdentity();
6944 try {
6945 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006946 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006947 }
6948
6949 final Phone phone = getPhone(subId);
6950 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006951 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006952 }
6953 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6954 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006955 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006956 } finally {
6957 Binder.restoreCallingIdentity(identity);
6958 }
6959 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006960
6961 /**
6962 * Scans for available networks.
6963 */
6964 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006965 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6966 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006967 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6968 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006969 LocationAccessPolicy.LocationPermissionResult locationResult =
6970 LocationAccessPolicy.checkLocationPermission(mApp,
6971 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6972 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006973 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006974 .setCallingPid(Binder.getCallingPid())
6975 .setCallingUid(Binder.getCallingUid())
6976 .setMethod("getCellNetworkScanResults")
6977 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006978 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6979 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006980 .build());
6981 switch (locationResult) {
6982 case DENIED_HARD:
6983 throw new SecurityException("Not allowed to access scan results -- location");
6984 case DENIED_SOFT:
6985 return null;
6986 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006987
Pengquan Menga1bb6272018-09-06 09:59:22 -07006988 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006989 try {
6990 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006991 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006992 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006993 } finally {
6994 Binder.restoreCallingIdentity(identity);
6995 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006996 }
6997
6998 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006999 * Get the call forwarding info, given the call forwarding reason.
7000 */
7001 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007002 public void getCallForwarding(int subId, int callForwardingReason,
7003 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007004 enforceReadPrivilegedPermission("getCallForwarding");
7005 long identity = Binder.clearCallingIdentity();
7006 try {
7007 if (DBG) {
7008 log("getCallForwarding: subId " + subId
7009 + " callForwardingReason" + callForwardingReason);
7010 }
Hall Liu27d24262020-09-18 19:04:59 -07007011
7012 Phone phone = getPhone(subId);
7013 if (phone == null) {
7014 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07007015 callback.onError(
7016 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07007017 } catch (RemoteException e) {
7018 // ignore
7019 }
7020 return;
7021 }
7022
7023 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
7024 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
7025 @Override
7026 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
7027 try {
7028 callback.onCallForwardingInfoAvailable(info);
7029 } catch (RemoteException e) {
7030 // ignore
7031 }
7032 }
7033
7034 @Override
7035 public void onError(int error) {
7036 try {
7037 callback.onError(error);
7038 } catch (RemoteException e) {
7039 // ignore
7040 }
7041 }
7042 });
7043 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08007044 } finally {
7045 Binder.restoreCallingIdentity(identity);
7046 }
7047 }
7048
7049 /**
7050 * Sets the voice call forwarding info including status (enable/disable), call forwarding
7051 * reason, the number to forward, and the timeout before the forwarding is attempted.
7052 */
7053 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007054 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
7055 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007056 enforceModifyPermission();
7057 long identity = Binder.clearCallingIdentity();
7058 try {
7059 if (DBG) {
7060 log("setCallForwarding: subId " + subId
7061 + " callForwardingInfo" + callForwardingInfo);
7062 }
Hall Liu27d24262020-09-18 19:04:59 -07007063
7064 Phone phone = getPhone(subId);
7065 if (phone == null) {
7066 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07007067 callback.accept(
7068 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07007069 } catch (RemoteException e) {
7070 // ignore
7071 }
7072 return;
7073 }
7074
7075 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
7076 FunctionalUtils.ignoreRemoteException(callback::accept));
7077
7078 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08007079 } finally {
7080 Binder.restoreCallingIdentity(identity);
7081 }
7082 }
7083
7084 /**
Hall Liu27d24262020-09-18 19:04:59 -07007085 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007086 */
7087 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007088 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08007089 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08007090 long identity = Binder.clearCallingIdentity();
7091 try {
Hall Liu27d24262020-09-18 19:04:59 -07007092 Phone phone = getPhone(subId);
7093 if (phone == null) {
7094 try {
7095 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7096 } catch (RemoteException e) {
7097 // ignore
7098 }
7099 return;
7100 }
SongFerngWang0e767992021-03-31 22:08:45 +08007101 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7102 PersistableBundle c = configManager.getConfigForSubId(subId);
7103 boolean requireUssd = c.getBoolean(
7104 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007105
Shuo Qian4a594052020-01-23 11:59:30 -08007106 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007107 if (requireUssd) {
7108 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7109 getSubscriptionCarrierId(subId));
7110 String newUssdCommand = "";
7111 try {
7112 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007113 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007114 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7115 } catch (NullPointerException e) {
7116 loge("Failed to generate USSD number" + e);
7117 }
7118 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7119 mMainThreadHandler, callback, carrierXmlParser,
7120 CarrierXmlParser.SsEntry.SSAction.QUERY);
7121 final String ussdCommand = newUssdCommand;
7122 Executors.newSingleThreadExecutor().execute(() -> {
7123 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7124 });
7125 } else {
7126 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7127 callback::accept);
7128 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7129 }
Shuo Qian4a594052020-01-23 11:59:30 -08007130 } finally {
7131 Binder.restoreCallingIdentity(identity);
7132 }
7133 }
7134
7135 /**
Hall Liu27d24262020-09-18 19:04:59 -07007136 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007137 */
7138 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007139 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007140 enforceModifyPermission();
7141 long identity = Binder.clearCallingIdentity();
7142 try {
Hall Liu27d24262020-09-18 19:04:59 -07007143 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7144
7145 Phone phone = getPhone(subId);
7146 if (phone == null) {
7147 try {
7148 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7149 } catch (RemoteException e) {
7150 // ignore
7151 }
7152 return;
7153 }
7154
SongFerngWang0e767992021-03-31 22:08:45 +08007155 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7156 PersistableBundle c = configManager.getConfigForSubId(subId);
7157 boolean requireUssd = c.getBoolean(
7158 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007159
SongFerngWang0e767992021-03-31 22:08:45 +08007160 if (DBG) log("getCallWaitingStatus: subId " + subId);
7161 if (requireUssd) {
7162 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7163 getSubscriptionCarrierId(subId));
7164 CarrierXmlParser.SsEntry.SSAction ssAction =
7165 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7166 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7167 String newUssdCommand = "";
7168 try {
7169 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007170 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007171 .makeCommand(ssAction, null);
7172 } catch (NullPointerException e) {
7173 loge("Failed to generate USSD number" + e);
7174 }
7175 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7176 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7177 final String ussdCommand = newUssdCommand;
7178 Executors.newSingleThreadExecutor().execute(() -> {
7179 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7180 });
7181 } else {
7182 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7183 FunctionalUtils.ignoreRemoteException(callback::accept));
7184
7185 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7186 }
Shuo Qian4a594052020-01-23 11:59:30 -08007187 } finally {
7188 Binder.restoreCallingIdentity(identity);
7189 }
7190 }
7191
7192 /**
yinxub1bed742017-04-17 11:45:04 -07007193 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007194 *
yinxub1bed742017-04-17 11:45:04 -07007195 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007196 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7197 * location related information which will be sent if the caller already possess
7198 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007199 * @param request contains the radio access networks with bands/channels to scan
7200 * @param messenger callback messenger for scan results or errors
7201 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007202 * @return the id of the requested scan which can be used to stop the scan.
7203 */
7204 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007205 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7206 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007207 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7209 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007210 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007211 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7212 if (!renounceFineLocationAccess) {
7213 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007214 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7215 .setCallingPackage(callingPackage)
7216 .setCallingFeatureId(callingFeatureId)
7217 .setCallingPid(Binder.getCallingPid())
7218 .setCallingUid(Binder.getCallingUid())
7219 .setMethod("requestNetworkScan")
7220 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7221 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7222 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7223 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007224 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007225 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007226 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7227 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007228 if (e != null) {
7229 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7230 throw e;
7231 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007232 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007233 return TelephonyScanManager.INVALID_SCAN_ID;
7234 }
7235 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007236 }
Hall Liu912dfd32019-04-25 14:02:26 -07007237 int callingUid = Binder.getCallingUid();
7238 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007239 final long identity = Binder.clearCallingIdentity();
7240 try {
7241 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007242 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007243 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007244 } finally {
7245 Binder.restoreCallingIdentity(identity);
7246 }
yinxu504e1392017-04-12 16:03:22 -07007247 }
7248
Hall Liub2ac8ef2019-02-28 15:56:23 -08007249 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007250 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007251 boolean hasCarrierPriv;
7252 final long identity = Binder.clearCallingIdentity();
7253 try {
7254 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7255 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7256 } finally {
7257 Binder.restoreCallingIdentity(identity);
7258 }
Hall Liu558027f2019-05-15 19:14:05 -07007259 boolean hasNetworkScanPermission =
7260 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007261 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007262
7263 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7264 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7265 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007266 }
7267
7268 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7269 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007270 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7271 return new SecurityException("Specific channels must not be"
7272 + " scanned without location access.");
7273 }
7274 }
7275 }
7276
Hall Liub2ac8ef2019-02-28 15:56:23 -08007277 return null;
7278 }
7279
yinxu504e1392017-04-12 16:03:22 -07007280 /**
7281 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007282 *
7283 * @param subId id of the subscription
7284 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007285 */
7286 @Override
7287 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007288 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7289 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007290
Hall Liu912dfd32019-04-25 14:02:26 -07007291 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007292 final long identity = Binder.clearCallingIdentity();
7293 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007294 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007295 } finally {
7296 Binder.restoreCallingIdentity(identity);
7297 }
yinxu504e1392017-04-12 16:03:22 -07007298 }
7299
7300 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007301 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007302 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007303 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007304 */
7305 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007306 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007307 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007308 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007309 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007310
7311 final long identity = Binder.clearCallingIdentity();
7312 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007313 if (DBG) log("getAllowedNetworkTypesBitmask");
7314 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7315 int networkTypesBitmask = (result != null ? result[0] : -1);
7316 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7317 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007318 } finally {
7319 Binder.restoreCallingIdentity(identity);
7320 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007321 }
7322
7323 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007324 * Get the allowed network types for certain reason.
7325 *
7326 * @param subId the id of the subscription.
7327 * @param reason the reason the allowed network type change is taking place
7328 * @return the allowed network types.
7329 */
7330 @Override
7331 public long getAllowedNetworkTypesForReason(int subId,
7332 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007333 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007334 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007335 final long identity = Binder.clearCallingIdentity();
7336 try {
7337 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
7338 } finally {
7339 Binder.restoreCallingIdentity(identity);
7340 }
7341 }
7342
7343 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007344 * Enable/Disable E-UTRA-NR Dual Connectivity
7345 * @param subId subscription id of the sim card
7346 * @param nrDualConnectivityState expected NR dual connectivity state
7347 * This can be passed following states
7348 * <ol>
7349 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7350 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7351 * <li>Disable NR dual connectivity and force secondary cell to be released
7352 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7353 * </ol>
7354 * @return operation result.
7355 */
7356 @Override
7357 public int setNrDualConnectivityState(int subId,
7358 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7360 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007361 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007362 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7363 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7364 }
7365
Sooraj Sasindran37444802020-08-11 10:40:43 -07007366 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7367 final long identity = Binder.clearCallingIdentity();
7368 try {
7369 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7370 nrDualConnectivityState, subId,
7371 workSource);
7372 if (DBG) log("enableNRDualConnectivity result: " + result);
7373 return result;
7374 } finally {
7375 Binder.restoreCallingIdentity(identity);
7376 }
7377 }
7378
7379 /**
7380 * Is E-UTRA-NR Dual Connectivity enabled
7381 * @return true if dual connectivity is enabled else false
7382 */
7383 @Override
7384 public boolean isNrDualConnectivityEnabled(int subId) {
7385 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007386 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007387 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007388 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007389 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7390 return false;
7391 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007392 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7393 final long identity = Binder.clearCallingIdentity();
7394 try {
7395 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7396 null, subId, workSource);
7397 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7398 return isEnabled;
7399 } finally {
7400 Binder.restoreCallingIdentity(identity);
7401 }
7402 }
7403
7404 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007405 * Set the allowed network types of the device and
7406 * provide the reason triggering the allowed network change.
7407 *
7408 * @param subId the id of the subscription.
7409 * @param reason the reason the allowed network type change is taking place
7410 * @param allowedNetworkTypes the allowed network types.
7411 * @return true on success; false on any failure.
7412 */
7413 @Override
7414 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007415 @TelephonyManager.AllowedNetworkTypesReason int reason,
7416 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7418 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007419 // If the caller only has carrier privileges, then they should not be able to override
7420 // any network types which were set for security reasons.
7421 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7422 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007423 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007424 throw new SecurityException(
7425 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007426 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007427 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08007428 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007429 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007430 return false;
7431 }
7432 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7433 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007434 return false;
7435 }
7436
Jack Yu5b494332023-01-23 18:18:04 +00007437 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7438 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007439
Jack Yue37dd262022-12-16 11:53:37 -08007440 Phone phone = getPhone(subId);
7441 if (phone == null) {
7442 return false;
7443 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007444
Jack Yue37dd262022-12-16 11:53:37 -08007445 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007446 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007447 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007448 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007449
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007450 final long identity = Binder.clearCallingIdentity();
7451 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007452 Boolean success = (Boolean) sendRequest(
7453 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7454 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7455
7456 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7457 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007458 } finally {
7459 Binder.restoreCallingIdentity(identity);
7460 }
7461 }
7462
7463 /**
Miaoa84611c2019-03-15 09:21:10 +08007464 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007465 *
Miaoa84611c2019-03-15 09:21:10 +08007466 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007467 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007468 * @hide
7469 */
7470 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007471 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007472 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007473 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007474 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007475 try {
Miaoa84611c2019-03-15 09:21:10 +08007476 if (phone != null) {
7477 return phone.hasMatchedTetherApnSetting();
7478 } else {
7479 return false;
7480 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007481 } finally {
7482 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007483 }
Junda Liu475951f2014-11-07 16:45:03 -08007484 }
7485
7486 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007487 * Get the user enabled state of Mobile Data.
7488 *
7489 * TODO: remove and use isUserDataEnabled.
7490 * This can't be removed now because some vendor codes
7491 * calls through ITelephony directly while they should
7492 * use TelephonyManager.
7493 *
7494 * @return true on enabled
7495 */
7496 @Override
7497 public boolean getDataEnabled(int subId) {
7498 return isUserDataEnabled(subId);
7499 }
7500
7501 /**
7502 * Get whether mobile data is enabled per user setting.
7503 *
7504 * There are other factors deciding whether mobile data is actually enabled, but they are
7505 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007506 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007507 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7508 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007509 *
7510 * @return {@code true} if data is enabled else {@code false}
7511 */
7512 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007513 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007514 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007515 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007516 try {
7517 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7518 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007519 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007520 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7521 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007522 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007523 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007524 mApp, subId, functionName);
7525
Robert Greenwalt646120a2014-05-23 11:54:03 -07007526 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007527
7528 final long identity = Binder.clearCallingIdentity();
7529 try {
Jack Yu285100e2022-12-02 22:48:35 -08007530 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007531 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7532 Phone phone = PhoneFactory.getPhone(phoneId);
7533 if (phone != null) {
7534 boolean retVal = phone.isUserDataEnabled();
7535 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7536 return retVal;
7537 } else {
7538 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7539 return false;
7540 }
7541 } finally {
7542 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007543 }
7544 }
7545
7546 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007547 * Checks if the device is capable of mobile data by considering whether whether the
7548 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7549 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007550 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007551 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007552 */
7553 @Override
7554 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007555 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007556 try {
7557 try {
7558 mApp.enforceCallingOrSelfPermission(
7559 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007560 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007561 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007562 try {
7563 mApp.enforceCallingOrSelfPermission(
7564 android.Manifest.permission.READ_PHONE_STATE,
7565 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007566 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007567 mApp.enforceCallingOrSelfPermission(
7568 permission.READ_BASIC_PHONE_STATE, functionName);
7569 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007570 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007571 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007572 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007573 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007574
7575 final long identity = Binder.clearCallingIdentity();
7576 try {
Jack Yu285100e2022-12-02 22:48:35 -08007577 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007578 Phone phone = PhoneFactory.getPhone(phoneId);
7579 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007580 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007581 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007582 return retVal;
7583 } else {
7584 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7585 return false;
7586 }
7587 } finally {
7588 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007589 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007590 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007591
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007592 /**
7593 * Check if data is enabled for a specific reason
7594 * @param subId Subscription index
7595 * @param reason the reason the data enable change is taking place
7596 * @return {@code true} if the overall data is enabled; {@code false} if not.
7597 */
7598 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007599 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007600 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007601 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007602 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007603 try {
7604 mApp.enforceCallingOrSelfPermission(
7605 android.Manifest.permission.ACCESS_NETWORK_STATE,
7606 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007607 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007608 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7609 functionName);
7610 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007611 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007612 try {
7613 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007614 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007615 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007616 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007617 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007618 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007619 }
7620
7621
7622 final long identity = Binder.clearCallingIdentity();
7623 try {
Jack Yu285100e2022-12-02 22:48:35 -08007624 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007625 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007626 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007627 + " reason=" + reason);
7628 }
7629 Phone phone = PhoneFactory.getPhone(phoneId);
7630 if (phone != null) {
7631 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007632 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007633 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007634 return retVal;
7635 } else {
7636 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007637 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007638 + subId + " retVal=false");
7639 }
7640 return false;
7641 }
7642 } finally {
7643 Binder.restoreCallingIdentity(identity);
7644 }
7645 }
7646
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007647 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007648 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007649 // No permission needed; this only lets the caller inspect their own status.
7650 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007651 }
Junda Liu29340342014-07-10 15:23:27 -07007652
7653 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007654 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007655 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007656 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7657 }
7658
7659 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7660 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007661 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007662 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007663 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7664 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007665 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7666 if (cpt == null) {
7667 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007668 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7669 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007670 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007671 }
7672
7673 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007674 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007675 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007676 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007677 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007678 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007679 Phone phone = getPhone(subId);
7680 if (phone == null) {
7681 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7682 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7683 }
7684 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7685 if (cpt == null) {
7686 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007687 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7688 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007689 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007690 }
7691
7692 @Override
7693 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007694 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007695 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7696 }
7697
7698 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007699 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007700 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007701 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007702 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007703 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7704 Phone phone = PhoneFactory.getPhone(phoneId);
7705 if (phone == null) {
7706 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007707 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007708 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7709 if (cpt == null) {
7710 continue;
7711 }
7712 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007713 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7714 break;
7715 }
7716 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007717 return result;
Junda Liu29340342014-07-10 15:23:27 -07007718 }
Derek Tan89e89d42014-07-08 17:00:10 -07007719
7720 @Override
Junda Liue64de782015-04-16 17:19:16 -07007721 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007722 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007723 Phone phone = PhoneFactory.getPhone(phoneId);
7724 if (phone == null) {
7725 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007726 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007727 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7728 if (cpt == null) {
7729 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007730 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007731 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007732 }
7733
Amith Yamasani6e118872016-02-19 12:53:51 -08007734 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007735 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007736 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007737 Phone phone = PhoneFactory.getPhone(phoneId);
7738 if (phone == null) {
7739 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007740 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007741 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7742 if (cpt == null) {
7743 return Collections.emptyList();
7744 }
7745 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007746 }
7747
chen xuf7e9fe82019-05-09 19:31:02 -07007748 @Override
7749 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007750 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007751 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007752 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007753 try {
7754 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7755 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7756 }
7757 } finally {
7758 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007759 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007760 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007761 }
7762
Rambo Wang6812ffb2022-03-15 16:54:17 -07007763 @Override
7764 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7765 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7766
7767 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7768 if (phone == null) {
7769 return null;
7770 }
7771 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7772 if (cpt == null) {
7773 return null;
7774 }
7775 return cpt.getCarrierServicePackageName();
7776 }
7777
Wink Savilleb564aae2014-10-23 10:18:09 -07007778 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007779 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007780 UiccPort port = phone == null ? null : phone.getUiccPort();
7781 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007782 return null;
7783 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007784 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007785 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007786 return null;
7787 }
7788 return iccId;
7789 }
7790
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007791 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007792 public void setCallComposerStatus(int subId, int status) {
7793 enforceModifyPermission();
7794
7795 final long identity = Binder.clearCallingIdentity();
7796 try {
7797 Phone phone = getPhone(subId);
7798 if (phone != null) {
7799 Phone defaultPhone = phone.getImsPhone();
7800 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7801 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7802 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007803 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7804 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007805 }
7806 }
Shuo Qian284ae752020-12-22 19:10:14 -08007807 } catch (ImsException e) {
7808 throw new ServiceSpecificException(e.getCode());
7809 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007810 Binder.restoreCallingIdentity(identity);
7811 }
7812 }
7813
7814 @Override
7815 public int getCallComposerStatus(int subId) {
7816 enforceReadPrivilegedPermission("getCallComposerStatus");
7817
7818 final long identity = Binder.clearCallingIdentity();
7819 try {
7820 Phone phone = getPhone(subId);
7821 if (phone != null) {
7822 Phone defaultPhone = phone.getImsPhone();
7823 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7824 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7825 return imsPhone.getCallComposerStatus();
7826 }
7827 }
7828 } finally {
7829 Binder.restoreCallingIdentity(identity);
7830 }
7831 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7832 }
7833
7834 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007835 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7836 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007837 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007838 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007839
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007840 final long identity = Binder.clearCallingIdentity();
7841 try {
7842 final String iccId = getIccId(subId);
7843 final Phone phone = getPhone(subId);
7844 if (phone == null) {
7845 return false;
7846 }
7847 final String subscriberId = phone.getSubscriberId();
7848
7849 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007850 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007851 + subscriberId + " to " + number);
7852 }
7853
7854 if (TextUtils.isEmpty(iccId)) {
7855 return false;
7856 }
7857
7858 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7859
7860 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7861 if (alphaTag == null) {
7862 editor.remove(alphaTagPrefKey);
7863 } else {
7864 editor.putString(alphaTagPrefKey, alphaTag);
7865 }
7866
7867 // Record both the line number and IMSI for this ICCID, since we need to
7868 // track all merged IMSIs based on line number
7869 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7870 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7871 if (number == null) {
7872 editor.remove(numberPrefKey);
7873 editor.remove(subscriberPrefKey);
7874 } else {
7875 editor.putString(numberPrefKey, number);
7876 editor.putString(subscriberPrefKey, subscriberId);
7877 }
7878
7879 editor.commit();
7880 return true;
7881 } finally {
7882 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007883 }
Derek Tan7226c842014-07-02 17:42:23 -07007884 }
7885
7886 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007887 public String getLine1NumberForDisplay(int subId, String callingPackage,
7888 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007889 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007890 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007891 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007892 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007893 return null;
7894 }
Derek Tan97ebb422014-09-05 16:55:38 -07007895
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007896 final long identity = Binder.clearCallingIdentity();
7897 try {
7898 String iccId = getIccId(subId);
7899 if (iccId != null) {
7900 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7901 if (DBG_MERGE) {
7902 log("getLine1NumberForDisplay returning "
7903 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7904 }
7905 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007906 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007907 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7908 return null;
7909 } finally {
7910 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007911 }
Derek Tan7226c842014-07-02 17:42:23 -07007912 }
7913
7914 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007915 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7916 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007917 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007918 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007919 return null;
7920 }
Derek Tan97ebb422014-09-05 16:55:38 -07007921
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007922 final long identity = Binder.clearCallingIdentity();
7923 try {
7924 String iccId = getIccId(subId);
7925 if (iccId != null) {
7926 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7927 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7928 }
7929 return null;
7930 } finally {
7931 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007932 }
Derek Tan7226c842014-07-02 17:42:23 -07007933 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007934
7935 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007936 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7937 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007938 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7939 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007940 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007941 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007942 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007943 return null;
7944 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007945
Jordan Liub49b04b2019-05-06 14:45:15 -07007946 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7947 // the process, where TelephonyManager was instantiated.
7948 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007949 final long identity = Binder.clearCallingIdentity();
7950 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007951 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007952 final TelephonyManager tele = TelephonyManager.from(context);
7953 final SubscriptionManager sub = SubscriptionManager.from(context);
7954
7955 // Figure out what subscribers are currently active
7956 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007957
Jordan Liub49b04b2019-05-06 14:45:15 -07007958 // Only consider subs which match the current subId
7959 // This logic can be simplified. See b/131189269 for progress.
7960 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007961 activeSubscriberIds.add(tele.getSubscriberId(subId));
7962 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007963
7964 // First pass, find a number override for an active subscriber
7965 String mergeNumber = null;
7966 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7967 for (String key : prefs.keySet()) {
7968 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7969 final String subscriberId = (String) prefs.get(key);
7970 if (activeSubscriberIds.contains(subscriberId)) {
7971 final String iccId = key.substring(
7972 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7973 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7974 mergeNumber = (String) prefs.get(numberKey);
7975 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007976 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007977 + " for active subscriber " + subscriberId);
7978 }
7979 if (!TextUtils.isEmpty(mergeNumber)) {
7980 break;
7981 }
7982 }
7983 }
7984 }
7985
7986 // Shortcut when no active merged subscribers
7987 if (TextUtils.isEmpty(mergeNumber)) {
7988 return null;
7989 }
7990
7991 // Second pass, find all subscribers under that line override
7992 final ArraySet<String> result = new ArraySet<>();
7993 for (String key : prefs.keySet()) {
7994 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7995 final String number = (String) prefs.get(key);
7996 if (mergeNumber.equals(number)) {
7997 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7998 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7999 final String subscriberId = (String) prefs.get(subscriberKey);
8000 if (!TextUtils.isEmpty(subscriberId)) {
8001 result.add(subscriberId);
8002 }
8003 }
8004 }
8005 }
8006
8007 final String[] resultArray = result.toArray(new String[result.size()]);
8008 Arrays.sort(resultArray);
8009 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008010 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008011 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
8012 }
8013 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008014 } finally {
8015 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08008016 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008017 }
8018
8019 @Override
zoey chen38003472019-12-13 17:16:31 +08008020 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
8021 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07008022
8023 final long identity = Binder.clearCallingIdentity();
8024 try {
8025 final TelephonyManager telephonyManager = mApp.getSystemService(
8026 TelephonyManager.class);
8027 String subscriberId = telephonyManager.getSubscriberId(subId);
8028 if (subscriberId == null) {
8029 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008030 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008031 + subId);
8032 }
8033 return null;
8034 }
8035
Jack Yu285100e2022-12-02 22:48:35 -08008036 ParcelUuid groupUuid;
8037 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008038 final SubscriptionInfo info = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08008039 .getSubscriptionInfo(subId);
8040 groupUuid = info.getGroupUuid();
8041 } else {
8042 final SubscriptionInfo info = mSubscriptionController
8043 .getSubscriptionInfo(subId);
8044 groupUuid = info.getGroupUuid();
8045 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07008046 // If it doesn't belong to any group, return just subscriberId of itself.
8047 if (groupUuid == null) {
8048 return new String[]{subscriberId};
8049 }
8050
8051 // Get all subscriberIds from the group.
8052 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08008053 List<SubscriptionInfo> groupInfos;
8054 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008055 groupInfos = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08008056 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8057 mApp.getAttributionTag());
8058 } else {
8059 groupInfos = mSubscriptionController
8060 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8061 mApp.getAttributionTag());
8062 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07008063 for (SubscriptionInfo subInfo : groupInfos) {
8064 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8065 if (subscriberId != null) {
8066 mergedSubscriberIds.add(subscriberId);
8067 }
8068 }
8069
8070 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8071 } finally {
8072 Binder.restoreCallingIdentity(identity);
8073
8074 }
8075 }
8076
8077 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008078 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008079 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008080 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008081
8082 final long identity = Binder.clearCallingIdentity();
8083 try {
8084 final Phone phone = getPhone(subId);
8085 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8086 } finally {
8087 Binder.restoreCallingIdentity(identity);
8088 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008089 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008090
8091 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008092 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008093 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8094 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008095 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8096 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008097
8098 final long identity = Binder.clearCallingIdentity();
8099 try {
8100 final Phone phone = getPhone(subId);
8101 if (phone == null) {
8102 return false;
8103 }
8104 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8105 cdmaNonRoamingList);
8106 } finally {
8107 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008108 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008109 }
8110
8111 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00008112 @Deprecated
8113 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
8114 enforceModifyPermission();
8115
8116 int returnValue = 0;
8117 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07008118 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00008119 if(result.exception == null) {
8120 if (result.result != null) {
8121 byte[] responseData = (byte[])(result.result);
8122 if(responseData.length > oemResp.length) {
8123 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
8124 responseData.length + "bytes. Buffer Size is " +
8125 oemResp.length + "bytes.");
8126 }
8127 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
8128 returnValue = responseData.length;
8129 }
8130 } else {
8131 CommandException ex = (CommandException) result.exception;
8132 returnValue = ex.getCommandError().ordinal();
8133 if(returnValue > 0) returnValue *= -1;
8134 }
8135 } catch (RuntimeException e) {
8136 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
8137 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
8138 if(returnValue > 0) returnValue *= -1;
8139 }
8140
8141 return returnValue;
8142 }
8143
8144 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008145 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008146 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07008147 try {
8148 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008149 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008150 mApp, phone.getSubId(), "getRadioAccessFamily");
8151 } catch (SecurityException e) {
8152 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8153 throw e;
8154 }
chen xub97461a2018-10-26 14:17:57 -07008155 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008156 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07008157 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08008158 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008159 final long identity = Binder.clearCallingIdentity();
8160 try {
chen xub97461a2018-10-26 14:17:57 -07008161 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008162 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07008163 mApp, phone.getSubId(), "getRadioAccessFamily");
8164 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008165 } finally {
8166 Binder.restoreCallingIdentity(identity);
8167 }
chen xub97461a2018-10-26 14:17:57 -07008168 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008169 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008170
8171 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008172 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008173 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008174 try {
8175 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8176 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008177 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008178 }
8179 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008180 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008181 }
8182 RoleManager rm = mApp.getSystemService(RoleManager.class);
8183 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8184 if (!dialerRoleHolders.contains(callingPackage)) {
8185 throw new SecurityException("App must be the dialer role holder to"
8186 + " upload a call composer pic");
8187 }
8188
8189 Executors.newSingleThreadExecutor().execute(() -> {
8190 ByteArrayOutputStream output = new ByteArrayOutputStream(
8191 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8192 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8193 boolean readUntilEnd = false;
8194 int totalBytesRead = 0;
8195 byte[] buffer = new byte[16 * 1024];
8196 while (true) {
8197 int numRead;
8198 try {
8199 numRead = input.read(buffer);
8200 } catch (IOException e) {
8201 try {
8202 fd.checkError();
8203 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8204 null);
8205 } catch (IOException e1) {
8206 // This means that the other side closed explicitly with an error. If this
8207 // happens, log and ignore.
8208 loge("Remote end of call composer picture pipe closed: " + e1);
8209 }
8210 break;
8211 }
8212 if (numRead == -1) {
8213 readUntilEnd = true;
8214 break;
8215 }
8216 totalBytesRead += numRead;
8217 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8218 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8219 try {
8220 input.close();
8221 } catch (IOException e) {
8222 // ignore
8223 }
8224 break;
8225 }
8226 output.write(buffer, 0, numRead);
8227 }
8228 // Generally, the remote end will close the file descriptors. The only case where we
8229 // close is above, where the picture size is too big.
8230
8231 try {
8232 fd.checkError();
8233 } catch (IOException e) {
8234 loge("Remote end for call composer closed with an error: " + e);
8235 return;
8236 }
8237
Hall Liuaa4211e2021-01-20 15:43:39 -08008238 if (!readUntilEnd) {
8239 loge("Did not finish reading entire image; aborting");
8240 return;
8241 }
Hall Liu82694d52020-12-11 18:22:04 -08008242
Hall Liuaa4211e2021-01-20 15:43:39 -08008243 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8244 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8245 new CallComposerPictureTransfer.Factory() {},
8246 imageData,
8247 (result) -> {
8248 if (result.first != null) {
8249 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8250 Bundle outputResult = new Bundle();
8251 outputResult.putParcelable(
8252 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8253 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8254 outputResult);
8255 } else {
8256 callback.send(result.second, null);
8257 }
8258 }
8259 );
Hall Liu82694d52020-12-11 18:22:04 -08008260 });
8261 }
8262
8263 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008264 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008265 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008266 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008267
8268 final long identity = Binder.clearCallingIdentity();
8269 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008270 ImsManager.getInstance(defaultPhone.getContext(),
8271 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008272 } finally {
8273 Binder.restoreCallingIdentity(identity);
8274 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008275 }
8276
8277 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008278 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008279 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008280 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8281 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008282 return false;
8283 }
Svet Ganovb320e182015-04-16 12:30:10 -07008284
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008285 final long identity = Binder.clearCallingIdentity();
8286 try {
8287 // Check the user preference and the system-level IMS setting. Even if the user has
8288 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8289 // In the long run, we may instead need to check if there exists a connection service
8290 // which can support video calling.
8291 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008292 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008293 return imsManager.isVtEnabledByPlatform()
8294 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8295 && imsManager.isVtEnabledByUser();
8296 } finally {
8297 Binder.restoreCallingIdentity(identity);
8298 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008299 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008300
Andrew Leea1239f22015-03-02 17:44:07 -08008301 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008302 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8303 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008304 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008305 mApp, subId, callingPackage, callingFeatureId,
8306 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008307 return false;
8308 }
8309
8310 final long identity = Binder.clearCallingIdentity();
8311 try {
8312 CarrierConfigManager configManager =
8313 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008314 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008315 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8316 } finally {
8317 Binder.restoreCallingIdentity(identity);
8318 }
Andrew Leea1239f22015-03-02 17:44:07 -08008319 }
8320
8321 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008322 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008323 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008324 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008325 return false;
8326 }
8327
8328 final long identity = Binder.clearCallingIdentity();
8329 try {
8330 CarrierConfigManager configManager =
8331 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008332 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008333 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8334 } finally {
8335 Binder.restoreCallingIdentity(identity);
8336 }
Andrew Leea1239f22015-03-02 17:44:07 -08008337 }
8338
Andrew Lee9431b832015-03-09 18:46:45 -07008339 @Override
8340 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008341 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008342 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008343 }
8344
8345 @Override
8346 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008347 final long identity = Binder.clearCallingIdentity();
8348 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008349 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008350 } finally {
8351 Binder.restoreCallingIdentity(identity);
8352 }
Andrew Lee9431b832015-03-09 18:46:45 -07008353 }
8354
Hall Liuf6668912018-10-31 17:05:23 -07008355 /**
8356 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8357 * support for the feature and device firmware support.
8358 *
8359 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8360 */
8361 @Override
8362 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008363 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008364 final Phone phone = getPhone(subscriptionId);
8365 if (phone == null) {
8366 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8367 return false;
8368 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008369 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008370 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008371 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
8372 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008373 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008374 return isCarrierSupported && isDeviceSupported;
8375 } finally {
8376 Binder.restoreCallingIdentity(identity);
8377 }
Hall Liu98187582018-01-22 19:15:32 -08008378 }
8379
Hall Liuf6668912018-10-31 17:05:23 -07008380 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008381 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8382 * RTT setting, will return true if the device and carrier both support RTT.
8383 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008384 */
8385 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008386 final long identity = Binder.clearCallingIdentity();
8387 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00008388 boolean isRttSupported = isRttSupported(subscriptionId);
8389 boolean isUserRttSettingOn = Settings.Secure.getInt(
8390 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8391 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8392 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8393 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008394 } finally {
8395 Binder.restoreCallingIdentity(identity);
8396 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008397 }
8398
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008399 @Deprecated
8400 @Override
8401 public String getDeviceId(String callingPackage) {
8402 return getDeviceIdWithFeature(callingPackage, null);
8403 }
8404
Sanket Padawe7310cc72015-01-14 09:53:20 -08008405 /**
8406 * Returns the unique device ID of phone, for example, the IMEI for
8407 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8408 *
8409 * <p>Requires Permission:
8410 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8411 */
8412 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008413 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008414 try {
8415 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8416 } catch (SecurityException se) {
8417 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8418 throw new SecurityException("Package " + callingPackage + " does not belong to "
8419 + Binder.getCallingUid());
8420 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008421 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008422 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008423 return null;
8424 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008425 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008426 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008427 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008428 return null;
8429 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008430
8431 final long identity = Binder.clearCallingIdentity();
8432 try {
8433 return phone.getDeviceId();
8434 } finally {
8435 Binder.restoreCallingIdentity(identity);
8436 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008437 }
8438
Ping Sunc67b7c22016-03-02 19:16:45 +08008439 /**
8440 * {@hide}
8441 * Returns the IMS Registration Status on a particular subid
8442 *
8443 * @param subId
8444 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008445 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008446 Phone phone = getPhone(subId);
8447 if (phone != null) {
8448 return phone.isImsRegistered();
8449 } else {
8450 return false;
8451 }
8452 }
8453
Santos Cordon7a1885b2015-02-03 11:15:19 -08008454 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008455 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008456 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008457 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008458 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008459 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8460 }
8461 final long identity = Binder.clearCallingIdentity();
8462 try {
8463 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8464 } finally {
8465 Binder.restoreCallingIdentity(identity);
8466 }
8467 }
8468
8469 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008470 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008471 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008472 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008473 mApp,
8474 subscriptionId,
8475 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8476 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07008477 final long identity = Binder.clearCallingIdentity();
8478 try {
8479 Phone phone = getPhone(subscriptionId);
8480 if (phone == null) {
8481 return null;
8482 }
8483 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8484 } finally {
8485 Binder.restoreCallingIdentity(identity);
8486 }
8487 }
8488
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008489 /**
8490 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008491 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008492 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008493 final long identity = Binder.clearCallingIdentity();
8494 try {
8495 Phone phone = getPhone(subId);
8496 if (phone != null) {
8497 return phone.isWifiCallingEnabled();
8498 } else {
8499 return false;
8500 }
8501 } finally {
8502 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008503 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008504 }
8505
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008506 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008507 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008508 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008509 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008510 final long identity = Binder.clearCallingIdentity();
8511 try {
8512 Phone phone = getPhone(subId);
8513 if (phone != null) {
8514 return phone.isVideoEnabled();
8515 } else {
8516 return false;
8517 }
8518 } finally {
8519 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008520 }
8521 }
8522
8523 /**
8524 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8525 * defined in {@link ImsRegistrationImplBase}.
8526 */
8527 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008528 final long identity = Binder.clearCallingIdentity();
8529 try {
8530 Phone phone = getPhone(subId);
8531 if (phone != null) {
8532 return phone.getImsRegistrationTech();
8533 } else {
8534 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8535 }
8536 } finally {
8537 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008538 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008539 }
8540
Stuart Scott8eef64f2015-04-08 15:13:54 -07008541 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008542 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008543 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07008544 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8545 return;
8546 }
Kai Shif70f46f2021-03-03 13:59:46 -08008547 Phone defaultPhone = getDefaultPhone();
8548 if (defaultPhone != null) {
8549 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8550 mApp, getDefaultPhone().getSubId(), "factoryReset");
8551 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008552 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008553
Svet Ganovcc087f82015-05-12 20:35:54 -07008554 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008555 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8556 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008557 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008558 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008559 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008560 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008561 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008562 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08008563 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008564 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008565 // There has been issues when Sms raw table somehow stores orphan
8566 // fragments. They lead to garbled message when new fragments come
8567 // in and combined with those stale ones. In case this happens again,
8568 // user can reset all network settings which will clean up this table.
8569 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008570 // Clean up IMS settings as well here.
8571 int slotId = getSlotIndex(subId);
8572 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8573 ImsManager.getInstance(mApp, slotId).factoryReset();
8574 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008575
Kai Shif70f46f2021-03-03 13:59:46 -08008576 if (defaultPhone == null) {
8577 return;
8578 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008579 // Erase modem config if erase modem on network setting is enabled.
8580 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8581 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8582 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008583 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008584 }
Kai Shif70f46f2021-03-03 13:59:46 -08008585
8586 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008587 } finally {
8588 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008589 }
8590 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008591
SongFerngWangfd89b102021-05-27 22:44:54 +08008592 @VisibleForTesting
8593 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8594 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8595 return;
8596 }
8597 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8598 RILConstants.PREFERRED_NETWORK_MODE);
8599 SubscriptionManager.setSubscriptionProperty(subId,
8600 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8601 "user=" + defaultNetworkType);
8602 phone.loadAllowedNetworksFromSubscriptionDatabase();
8603 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8604 defaultNetworkType, null);
8605 }
8606
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008607 private void cleanUpSmsRawTable(Context context) {
8608 ContentResolver resolver = context.getContentResolver();
8609 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8610 resolver.delete(uri, null, null);
8611 }
8612
Narayan Kamath1c496c22015-04-16 14:40:19 +01008613 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008614 public String getSimLocaleForSubscriber(int subId) {
8615 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
8616 final Phone phone = getPhone(subId);
8617 if (phone == null) {
8618 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008619 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008620 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008621 final long identity = Binder.clearCallingIdentity();
8622 try {
Jack Yu285100e2022-12-02 22:48:35 -08008623 SubscriptionInfo info;
8624 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008625 info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
Jack Yu285100e2022-12-02 22:48:35 -08008626 phone.getContext().getOpPackageName(),
8627 phone.getContext().getAttributionTag());
8628 if (info == null) {
8629 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8630 return null;
8631 }
8632 } else {
8633 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
8634 phone.getContext().getOpPackageName(),
8635 phone.getContext().getAttributionTag());
8636 if (info == null) {
8637 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8638 return null;
8639 }
chen xu6291c472019-02-04 12:55:53 -08008640 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008641 // Try and fetch the locale from the carrier properties or from the SIM language
8642 // preferences (EF-PL and EF-LI)...
8643 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008644 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008645 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8646 if (localeFromDefaultSim != null) {
8647 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8648 if (DBG) log("Using locale from subId: " + subId + " locale: "
8649 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008650 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008651 } else {
8652 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008653 }
8654 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008655
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008656 // The SIM language preferences only store a language (e.g. fr = French), not an
8657 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8658 // the SIM and carrier preferences does not include a country we add the country
8659 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008660 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008661 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008662 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008663 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008664 }
8665
8666 if (DBG) log("No locale found - returning null");
8667 return null;
8668 } finally {
8669 Binder.restoreCallingIdentity(identity);
8670 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008671 }
8672
tom hsu0b59d292022-09-29 23:49:21 +08008673 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008674 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008675 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008676 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008677 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008678 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8679 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008680 Locale.forLanguageTag(localeTag).getCountry())) {
8681 return localeTag;
8682 }
8683 }
8684 return inputLocale.toLanguageTag();
8685 }
8686
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008687 /**
8688 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8689 */
8690 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08008691 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008692 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Jack Yu285100e2022-12-02 22:48:35 -08008693 mApp.getOpPackageName(), mApp.getAttributionTag());
8694 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008695 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08008696 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008697 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008698
Gary Jian3aa9a762022-01-24 16:41:19 +08008699 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8700 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008701
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008702 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008703 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8704 * representing the state of the modem.
8705 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008706 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8707 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008708 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008709 */
8710 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008711 public void requestModemActivityInfo(ResultReceiver result) {
8712 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008713 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008714
8715 final long identity = Binder.clearCallingIdentity();
8716 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008717 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008718 } finally {
8719 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008720 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008721 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008722
Gary Jian76280a42022-12-07 16:18:33 +08008723 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008724 // less than total activity duration.
8725 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8726 if (info == null) {
8727 return false;
8728 }
8729 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008730 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008731 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8732
Hall Liu49656c02020-10-09 19:00:11 -07008733 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8734
Siddharth Rayb8114062018-06-17 15:02:38 -07008735 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008736 && (info.getSleepTimeMillis() <= activityDurationMs)
8737 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008738 }
8739
Gary Jian3aa9a762022-01-24 16:41:19 +08008740 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8741 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8742 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8743 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8744
8745 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8746 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8747 }
8748
8749 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8750 mLastModemActivityInfo.setReceiveTimeMillis(
8751 rat,
8752 freq,
8753 info.getReceiveTimeMillis(rat, freq)
8754 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8755 }
8756
8757 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8758 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8759 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8760 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8761
8762 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8763 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8764 }
8765 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8766 mLastModemActivityInfo.setReceiveTimeMillis(
8767 rat,
8768 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8769 }
8770
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008771 /**
8772 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8773 * @param info recent ModemActivityInfo
8774 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008775 private void mergeModemActivityInfo(ModemActivityInfo info) {
8776 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008777 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008778 boolean matched;
8779 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8780 matched = false;
8781 int rat = info.getSpecificInfoRat(i);
8782 int freq = info.getSpecificInfoFrequencyRange(i);
8783 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8784 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8785 //if it already exists
8786 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8787 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8788 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8789 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8790 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8791 updateLastModemActivityInfo(info, rat, freq);
8792 matched = true;
8793 }
8794 } else {
8795 updateLastModemActivityInfo(info, rat);
8796 matched = true;
8797 }
8798 }
8799 }
8800
8801 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008802 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008803 new ActivityStatsTechSpecificInfo(
8804 rat,
8805 freq,
8806 info.getTransmitTimeMillis(rat, freq),
8807 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008808 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008809 }
8810 }
8811 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8812 mLastModemActivitySpecificInfo =
8813 new ActivityStatsTechSpecificInfo[merged.size()];
8814 merged.toArray(mLastModemActivitySpecificInfo);
8815
8816 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8817 mLastModemActivityInfo.setSleepTimeMillis(
8818 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008819 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008820 mLastModemActivityInfo.setIdleTimeMillis(
8821 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008822 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008823
8824 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008825 new ModemActivityInfo(
8826 mLastModemActivityInfo.getTimestampMillis(),
8827 mLastModemActivityInfo.getSleepTimeMillis(),
8828 mLastModemActivityInfo.getIdleTimeMillis(),
8829 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008830 }
8831
8832 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8833 ActivityStatsTechSpecificInfo[] info) {
8834 int infoSize = info.length;
8835 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8836 for (int i = 0; i < infoSize; i++) {
8837 ret[i] = new ActivityStatsTechSpecificInfo(
8838 info[i].getRat(), info[i].getFrequencyRange(),
8839 info[i].getTransmitTimeMillis(),
8840 (int) info[i].getReceiveTimeMillis());
8841 }
8842 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008843 }
8844
Jack Yu85bd38a2015-11-09 11:34:32 -08008845 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008846 * Returns the service state information on specified subscription.
8847 */
8848 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008849 public ServiceState getServiceStateForSubscriber(int subId,
8850 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8851 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008852 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008853 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008854 return null;
8855 }
8856
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008857 boolean hasFinePermission = false;
8858 boolean hasCoarsePermission = false;
8859 if (!renounceFineLocationAccess) {
8860 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8861 LocationAccessPolicy.checkLocationPermission(mApp,
8862 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8863 .setCallingPackage(callingPackage)
8864 .setCallingFeatureId(callingFeatureId)
8865 .setCallingPid(Binder.getCallingPid())
8866 .setCallingUid(Binder.getCallingUid())
8867 .setMethod("getServiceStateForSubscriber")
8868 .setLogAsInfo(true)
8869 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8870 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8871 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8872 .build());
8873 hasFinePermission =
8874 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8875 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008876
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008877 if (!renounceCoarseLocationAccess) {
8878 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8879 LocationAccessPolicy.checkLocationPermission(mApp,
8880 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8881 .setCallingPackage(callingPackage)
8882 .setCallingFeatureId(callingFeatureId)
8883 .setCallingPid(Binder.getCallingPid())
8884 .setCallingUid(Binder.getCallingUid())
8885 .setMethod("getServiceStateForSubscriber")
8886 .setLogAsInfo(true)
8887 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8888 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8889 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8890 .build());
8891 hasCoarsePermission =
8892 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8893 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008894
Jack Yu479f40e2020-10-27 21:29:25 -07008895 final Phone phone = getPhone(subId);
8896 if (phone == null) {
8897 return null;
8898 }
8899
Jordan Liu0f2bc442020-11-18 16:47:37 -08008900 final long identity = Binder.clearCallingIdentity();
8901
Jack Yu479f40e2020-10-27 21:29:25 -07008902 boolean isCallingPackageDataService = phone.getDataServicePackages()
8903 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008904 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008905 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008906 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008907 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08008908 .getSubscriptionInfoInternal(subId);
8909 if (subInfo == null || !subInfo.isActive()) {
8910 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8911 + "subId=" + subId);
8912 return null;
8913 }
8914 } else {
8915 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8916 callingFeatureId)) {
8917 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8918 + "subId=" + subId);
8919 return null;
8920 }
Jordan Liuc437b192020-08-17 10:59:12 -07008921 }
8922
Hall Liuf19c44f2018-11-27 14:38:17 -08008923 ServiceState ss = phone.getServiceState();
8924
8925 // Scrub out the location info in ServiceState depending on what level of access
8926 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008927 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008928 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8929 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008930 } finally {
8931 Binder.restoreCallingIdentity(identity);
8932 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008933 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008934
8935 /**
8936 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8937 *
8938 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8939 * voicemail ringtone.
8940 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8941 * PhoneAccount.
8942 */
8943 @Override
8944 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008945 final long identity = Binder.clearCallingIdentity();
8946 try {
8947 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8948 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008949 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008950 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008952 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8953 } finally {
8954 Binder.restoreCallingIdentity(identity);
8955 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008956 }
8957
8958 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008959 * Sets the per-account voicemail ringtone.
8960 *
8961 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8962 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8963 *
8964 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8965 * voicemail ringtone.
8966 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8967 * PhoneAccount.
8968 */
8969 @Override
8970 public void setVoicemailRingtoneUri(String callingPackage,
8971 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008972 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008973 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008974 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8975 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8977 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8978 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008979 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008980
8981 final long identity = Binder.clearCallingIdentity();
8982 try {
8983 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8984 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008985 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008986 }
8987 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8988 } finally {
8989 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008990 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008991 }
8992
8993 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008994 * Returns whether vibration is set for voicemail notification in Phone settings.
8995 *
8996 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8997 * voicemail vibration setting.
8998 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8999 */
9000 @Override
9001 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009002 final long identity = Binder.clearCallingIdentity();
9003 try {
9004 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9005 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009006 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009007 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009008
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009009 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
9010 } finally {
9011 Binder.restoreCallingIdentity(identity);
9012 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009013 }
9014
Youhan Wange64578a2016-05-02 15:32:42 -07009015 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009016 * Sets the per-account voicemail vibration.
9017 *
9018 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9019 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9020 *
9021 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9022 * voicemail vibration setting.
9023 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9024 * specific PhoneAccount.
9025 */
9026 @Override
9027 public void setVoicemailVibrationEnabled(String callingPackage,
9028 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009029 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009030 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009031 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9032 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009033 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9034 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9035 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009036 }
9037
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009038 final long identity = Binder.clearCallingIdentity();
9039 try {
9040 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9041 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009042 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009043 }
9044 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9045 } finally {
9046 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009047 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009048 }
9049
9050 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009051 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9052 *
9053 * @throws SecurityException if the caller does not have the required permission
9054 */
arunvoddud7401012022-12-15 16:08:12 +00009055 @VisibleForTesting
9056 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009057 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009058 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009059 }
9060
9061 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009062 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9063 * permission.
9064 *
9065 * @throws SecurityException if the caller does not have the required permission
9066 */
9067 private void enforceSendSmsPermission() {
9068 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9069 }
9070
9071 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009072 * Make sure either called from same process as self (phone) or IPC caller has interact across
9073 * users permission.
9074 *
9075 * @throws SecurityException if the caller does not have the required permission
9076 */
9077 private void enforceInteractAcrossUsersPermission(String message) {
9078 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9079 }
9080
9081 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009082 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009083 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009084 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009085 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009086 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009087 final long identity = Binder.clearCallingIdentity();
9088 try {
9089 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009090 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009091 if (componentName == null) {
9092 throw new SecurityException(
9093 "Caller not current active visual voicemail package[null]");
9094 }
9095 String vvmPackage = componentName.getPackageName();
9096 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009097 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009098 }
9099 } finally {
9100 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009101 }
9102 }
9103
9104 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009105 * Return the application ID for the app type.
9106 *
9107 * @param subId the subscription ID that this request applies to.
9108 * @param appType the uicc app type.
9109 * @return Application ID for specificied app type, or null if no uicc.
9110 */
9111 @Override
9112 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009113 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07009114 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009115
9116 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009117 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009118 if (phone == null) {
9119 return null;
9120 }
9121 String aid = null;
9122 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009123 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009124 .getApplicationByType(appType).getAid();
9125 } catch (Exception e) {
9126 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9127 }
9128 return aid;
9129 } finally {
9130 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009131 }
Youhan Wange64578a2016-05-02 15:32:42 -07009132 }
9133
Youhan Wang4001d252016-05-11 10:29:41 -07009134 /**
9135 * Return the Electronic Serial Number.
9136 *
9137 * @param subId the subscription ID that this request applies to.
9138 * @return ESN or null if error.
9139 */
9140 @Override
9141 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009142 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009143 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009144
9145 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009146 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009147 if (phone == null) {
9148 return null;
9149 }
9150 String esn = null;
9151 try {
9152 esn = phone.getEsn();
9153 } catch (Exception e) {
9154 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9155 }
9156 return esn;
9157 } finally {
9158 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009159 }
Youhan Wang4001d252016-05-11 10:29:41 -07009160 }
9161
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009162 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009163 * Return the Preferred Roaming List Version.
9164 *
9165 * @param subId the subscription ID that this request applies to.
9166 * @return PRLVersion or null if error.
9167 */
9168 @Override
9169 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009170 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07009171 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009172
9173 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009174 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009175 if (phone == null) {
9176 return null;
9177 }
9178 String cdmaPrlVersion = null;
9179 try {
9180 cdmaPrlVersion = phone.getCdmaPrlVersion();
9181 } catch (Exception e) {
9182 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9183 }
9184 return cdmaPrlVersion;
9185 } finally {
9186 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009187 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009188 }
9189
9190 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009191 * Get snapshot of Telephony histograms
9192 * @return List of Telephony histograms
9193 * @hide
9194 */
9195 @Override
9196 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009197 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9198 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009199
9200 final long identity = Binder.clearCallingIdentity();
9201 try {
9202 return RIL.getTelephonyRILTimingHistograms();
9203 } finally {
9204 Binder.restoreCallingIdentity(identity);
9205 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009206 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009207
9208 /**
9209 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009210 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9211 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009212 * Require system privileges. In the future we may add this to carrier APIs.
9213 *
Michele Berionne482f8202018-11-27 18:57:59 -08009214 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009215 */
9216 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009217 @TelephonyManager.SetCarrierRestrictionResult
9218 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009219 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07009220 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009221
Michele Berionne482f8202018-11-27 18:57:59 -08009222 if (carrierRestrictionRules == null) {
9223 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009224 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009225
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009226 final long identity = Binder.clearCallingIdentity();
9227 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009228 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009229 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009230 } finally {
9231 Binder.restoreCallingIdentity(identity);
9232 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009233 }
9234
9235 /**
9236 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009237 * Get the allowed carrier list and the excluded carrier list, including the priority between
9238 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009239 * Require system privileges. In the future we may add this to carrier APIs.
9240 *
Michele Berionne482f8202018-11-27 18:57:59 -08009241 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009242 */
9243 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009244 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009245 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07009246 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009247
9248 final long identity = Binder.clearCallingIdentity();
9249 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009250 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9251 if (response instanceof CarrierRestrictionRules) {
9252 return (CarrierRestrictionRules) response;
9253 }
9254 // Response is an Exception of some kind,
9255 // which is signalled to the user as a NULL retval
9256 return null;
9257 } catch (Exception e) {
9258 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9259 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009260 } finally {
9261 Binder.restoreCallingIdentity(identity);
9262 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009263 }
9264
fionaxu59545b42016-05-25 15:53:37 -07009265 /**
arunvoddud7401012022-12-15 16:08:12 +00009266 * Fetches the carrier restriction status of the device and sends the status to the caller
9267 * through the callback.
9268 *
9269 * @param callback The callback that will be used to send the result.
9270 * @throws SecurityException if the caller does not have the required permission/privileges or
9271 * the caller is not allowlisted.
9272 */
9273 @Override
9274 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9275 enforceReadPermission("getCarrierRestrictionStatus");
9276 int carrierId = validateCallerAndGetCarrierId(packageName);
9277 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
9278 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9279 throw new SecurityException("Not an authorized caller");
9280 }
9281 final long identity = Binder.clearCallingIdentity();
9282 try {
9283 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
9284 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
9285 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9286 } finally {
9287 Binder.restoreCallingIdentity(identity);
9288 }
9289 }
9290
9291 @VisibleForTesting
9292 public int validateCallerAndGetCarrierId(String packageName) {
9293 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9294 return allowListInfo.validateCallerAndGetCarrierId(packageName);
9295 }
9296
9297 /**
fionaxu59545b42016-05-25 15:53:37 -07009298 * Action set from carrier signalling broadcast receivers to enable/disable radio
9299 * @param subId the subscription ID that this action applies to.
9300 * @param enabled control enable or disable radio.
9301 * {@hide}
9302 */
9303 @Override
9304 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9305 enforceModifyPermission();
9306 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009307
9308 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009309 if (phone == null) {
9310 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9311 return;
9312 }
9313 try {
9314 phone.carrierActionSetRadioEnabled(enabled);
9315 } catch (Exception e) {
9316 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009317 } finally {
9318 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009319 }
9320 }
9321
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009322 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009323 * Enable or disable Voice over NR (VoNR)
9324 * @param subId the subscription ID that this action applies to.
9325 * @param enabled enable or disable VoNR.
9326 * @return operation result.
9327 */
9328 @Override
9329 public int setVoNrEnabled(int subId, boolean enabled) {
9330 enforceModifyPermission();
9331 final Phone phone = getPhone(subId);
9332
9333 final long identity = Binder.clearCallingIdentity();
9334 if (phone == null) {
9335 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9336 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9337 }
9338
9339 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9340 try {
9341 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9342 workSource);
9343 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009344
9345 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9346 if (DBG) {
9347 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9348 }
9349 SubscriptionManager.setSubscriptionProperty(
9350 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9351 (enabled ? "1" : "0"));
9352 }
9353
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009354 return result;
9355 } finally {
9356 Binder.restoreCallingIdentity(identity);
9357 }
9358 }
9359
9360 /**
9361 * Is voice over NR enabled
9362 * @return true if VoNR is enabled else false
9363 */
9364 @Override
9365 public boolean isVoNrEnabled(int subId) {
9366 enforceReadPrivilegedPermission("isVoNrEnabled");
9367 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9368 final long identity = Binder.clearCallingIdentity();
9369 try {
9370 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9371 null, subId, workSource);
9372 if (DBG) log("isVoNrEnabled: " + isEnabled);
9373 return isEnabled;
9374 } finally {
9375 Binder.restoreCallingIdentity(identity);
9376 }
9377 }
9378
9379 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009380 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9381 * network status based on which carrier apps could apply actions accordingly,
9382 * enable/disable default url handler for example.
9383 *
9384 * @param subId the subscription ID that this action applies to.
9385 * @param report control start/stop reporting the default network status.
9386 * {@hide}
9387 */
9388 @Override
9389 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9390 enforceModifyPermission();
9391 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009392
9393 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009394 if (phone == null) {
9395 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9396 return;
9397 }
9398 try {
9399 phone.carrierActionReportDefaultNetworkStatus(report);
9400 } catch (Exception e) {
9401 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009402 } finally {
9403 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009404 }
9405 }
9406
9407 /**
fionaxud9622282017-07-17 17:51:30 -07009408 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9409 * @param subId the subscription ID that this action applies to.
9410 * {@hide}
9411 */
9412 @Override
9413 public void carrierActionResetAll(int subId) {
9414 enforceModifyPermission();
9415 final Phone phone = getPhone(subId);
9416 if (phone == null) {
9417 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9418 return;
9419 }
9420 try {
9421 phone.carrierActionResetAll();
9422 } catch (Exception e) {
9423 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9424 }
9425 }
9426
9427 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009428 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9429 * bug report is being generated.
9430 */
9431 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009432 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009433 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9434 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009435 writer.println("Permission Denial: can't dump Phone from pid="
9436 + Binder.getCallingPid()
9437 + ", uid=" + Binder.getCallingUid()
9438 + "without permission "
9439 + android.Manifest.permission.DUMP);
9440 return;
9441 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009442 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009443 }
Jack Yueb89b242016-06-22 13:27:47 -07009444
Brad Ebingerdac2f002018-04-03 15:17:52 -07009445 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009446 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9447 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9448 @NonNull String[] args) {
9449 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9450 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009451 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009452 }
9453
Jack Yueb89b242016-06-22 13:27:47 -07009454 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009455 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009456 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009457 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009458 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009459 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009460 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009461 */
9462 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009463 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009464 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009465 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9466 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9467 try {
9468 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009469 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009470 } catch (SecurityException se) {
9471 enforceModifyPermission();
9472 }
9473 } else {
9474 enforceModifyPermission();
9475 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009476
9477 final long identity = Binder.clearCallingIdentity();
9478 try {
9479 Phone phone = getPhone(subId);
9480 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009481 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9482 phone.carrierActionSetMeteredApnsEnabled(enabled);
9483 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009484 phone.getDataSettingsManager().setDataEnabled(
9485 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009486 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009487 }
9488 } finally {
9489 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009490 }
9491 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009492
9493 /**
9494 * Get Client request stats
9495 * @return List of Client Request Stats
9496 * @hide
9497 */
9498 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009499 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9500 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009501 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009502 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009503 return null;
9504 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009505 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009506
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009507 final long identity = Binder.clearCallingIdentity();
9508 try {
9509 if (phone != null) {
9510 return phone.getClientRequestStats();
9511 }
9512
9513 return null;
9514 } finally {
9515 Binder.restoreCallingIdentity(identity);
9516 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009517 }
9518
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009519 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009520 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009521 if (uid == Process.ROOT_UID && packageName == null) {
9522 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9523 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9524 // exception. ROOT_UID seems not to have a valid package name returned by
9525 // PackageManager, so just fake it here to avoid issues when running telephony shell
9526 // commands that plumb through the RIL as root, like so:
9527 // $ adb root
9528 // $ adb shell cmd phone ...
9529 packageName = "root";
9530 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009531 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009532 }
Jack Yueb4124c2017-02-16 15:32:43 -08009533
9534 /**
Grace Chen70990072017-03-24 17:21:30 -07009535 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009536 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009537 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009538 * @param state State of SIM (power down, power up, pass through)
9539 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9540 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9541 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009542 *
9543 **/
9544 @Override
Grace Chen70990072017-03-24 17:21:30 -07009545 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009546 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009547 Phone phone = PhoneFactory.getPhone(slotIndex);
9548
vagdeviaf9a5b92018-08-15 16:01:53 -07009549 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9550
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009551 final long identity = Binder.clearCallingIdentity();
9552 try {
9553 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009554 phone.setSimPowerState(state, null, workSource);
9555 }
9556 } finally {
9557 Binder.restoreCallingIdentity(identity);
9558 }
9559 }
9560
9561 /**
9562 * Set SIM card power state.
9563 *
9564 * @param slotIndex SIM slot id.
9565 * @param state State of SIM (power down, power up, pass through)
9566 * @param callback callback to trigger after success or failure
9567 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9568 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9569 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9570 *
9571 **/
9572 @Override
9573 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9574 IIntegerConsumer callback) {
9575 enforceModifyPermission();
9576 Phone phone = PhoneFactory.getPhone(slotIndex);
9577
9578 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9579
9580 final long identity = Binder.clearCallingIdentity();
9581 try {
9582 if (phone != null) {
9583 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9584 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009585 }
9586 } finally {
9587 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009588 }
9589 }
Shuo Qiandd210312017-04-12 22:11:33 +00009590
Tyler Gunn65d45c22017-06-05 11:22:26 -07009591 private boolean isUssdApiAllowed(int subId) {
9592 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009593 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009594 if (configManager == null) {
9595 return false;
9596 }
9597 PersistableBundle pb = configManager.getConfigForSubId(subId);
9598 if (pb == null) {
9599 return false;
9600 }
9601 return pb.getBoolean(
9602 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9603 }
9604
Shuo Qiandd210312017-04-12 22:11:33 +00009605 /**
9606 * Check if phone is in emergency callback mode
9607 * @return true if phone is in emergency callback mode
9608 * @param subId sub id
9609 */
goneil9c5f4872017-12-05 14:07:56 -08009610 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009611 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009612 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00009613 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009614
9615 final long identity = Binder.clearCallingIdentity();
9616 try {
9617 if (phone != null) {
9618 return phone.isInEcm();
9619 } else {
9620 return false;
9621 }
9622 } finally {
9623 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009624 }
9625 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009626
9627 /**
9628 * Get the current signal strength information for the given subscription.
9629 * Because this information is not updated when the device is in a low power state
9630 * it should not be relied-upon to be current.
9631 * @param subId Subscription index
9632 * @return the most recent cached signal strength info from the modem
9633 */
9634 @Override
9635 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009636 final long identity = Binder.clearCallingIdentity();
9637 try {
9638 Phone p = getPhone(subId);
9639 if (p == null) {
9640 return null;
9641 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009642
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009643 return p.getSignalStrength();
9644 } finally {
9645 Binder.restoreCallingIdentity(identity);
9646 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009647 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009648
Pengquan Meng77b7f132018-08-22 14:49:57 -07009649 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009650 * Get the current modem radio state for the given slot.
9651 * @param slotIndex slot index.
9652 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009653 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009654 * @return the current radio power state from the modem
9655 */
9656 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009657 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009658 Phone phone = PhoneFactory.getPhone(slotIndex);
9659 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009660 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9661 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009662 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9663 }
9664
9665 final long identity = Binder.clearCallingIdentity();
9666 try {
9667 return phone.getRadioPowerState();
9668 } finally {
9669 Binder.restoreCallingIdentity(identity);
9670 }
9671 }
9672 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9673 }
9674
9675 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009676 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9677 *
9678 * <p>Requires one of the following permissions:
9679 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009680 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009681 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9682 * privileges.
9683 *
9684 * @param subId subscription id
9685 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9686 * {@code false}.
9687 */
9688 @Override
9689 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009690 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009691 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009692 try {
9693 mApp.enforceCallingOrSelfPermission(
9694 android.Manifest.permission.ACCESS_NETWORK_STATE,
9695 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009696 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009697 mApp.enforceCallingOrSelfPermission(
9698 permission.READ_BASIC_PHONE_STATE, functionName);
9699 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009700 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009701 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009702 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009703 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009704
Pengquan Menga1bb6272018-09-06 09:59:22 -07009705 boolean isEnabled = false;
9706 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009707 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009708 Phone phone = getPhone(subId);
9709 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009710 } finally {
9711 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009712 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009713 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009714 }
9715
9716
9717 /**
9718 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9719 *
9720 * <p> Requires permission:
9721 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9722 * privileges.
9723 *
9724 * @param subId subscription id
9725 * @param isEnabled {@code true} means enable, {@code false} means disable.
9726 */
9727 @Override
9728 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009729 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9730 mApp, subId, "setDataRoamingEnabled");
9731
Pengquan Menga1bb6272018-09-06 09:59:22 -07009732 final long identity = Binder.clearCallingIdentity();
9733 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009734 Phone phone = getPhone(subId);
9735 if (phone != null) {
9736 phone.setDataRoamingEnabled(isEnabled);
9737 }
9738 } finally {
9739 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009740 }
9741 }
9742
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009743 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009744 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009745 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009746 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009747 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009748
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009749 boolean isAllowed = true;
9750 final long identity = Binder.clearCallingIdentity();
9751 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009752 Phone phone = getPhone(subId);
9753 if (phone != null) {
9754 isAllowed = phone.isCspPlmnEnabled();
9755 }
9756 } finally {
9757 Binder.restoreCallingIdentity(identity);
9758 }
9759 return isAllowed;
9760 }
9761
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009762 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9763 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009764 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009765 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009766 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009767 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9768 if (phone == null) {
9769 return false;
9770 }
9771 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9772 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9773 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009774 }
9775
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009776 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009777 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009778 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009779 mApp.getSystemService(AppOpsManager.class)
9780 .checkPackage(Binder.getCallingUid(), callingPackage);
9781
Jordan Liu1e142fc2019-04-22 15:10:43 -07009782 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009783 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009784 try {
9785 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009786 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009787 } catch (SecurityException e) {
9788 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9789 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009790 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009791 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009792 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009793 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009794 }
sandeepjsb6c87872021-09-27 15:34:44 +00009795 // checking compatibility, if calling app's target SDK is T and beyond.
9796 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9797 Binder.getCallingUid())) {
9798 isIccIdAccessRestricted = true;
9799 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009800 final long identity = Binder.clearCallingIdentity();
9801 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009802 UiccController uiccController = UiccController.getInstance();
9803 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009804 if (hasReadPermission) {
9805 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009806 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009807
9808 // Remove private info if the caller doesn't have access
9809 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9810 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009811 //setting the value after compatibility check
9812 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009813 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9814 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009815 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009816 if (card == null) {
9817 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009818 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009819 continue;
9820 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009821 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9822 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009823 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009824 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009825 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009826 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9827 for (UiccPortInfo portInfo : portInfos) {
9828 UiccPort port = uiccController.getUiccPortForSlot(
9829 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9830 if (port == null) {
9831 // assume no access if port is null
9832 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9833 continue;
9834 }
9835 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9836 uiccPortInfos.add(portInfo);
9837 } else {
9838 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9839 }
9840 }
9841 filteredInfos.add(new UiccCardInfo(
9842 cardInfo.isEuicc(),
9843 cardInfo.getCardId(),
9844 null,
9845 cardInfo.getPhysicalSlotIndex(),
9846 cardInfo.isRemovable(),
9847 cardInfo.isMultipleEnabledProfilesSupported(),
9848 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009849 }
9850 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009851 } finally {
9852 Binder.restoreCallingIdentity(identity);
9853 }
9854 }
9855
sandeepjsb6c87872021-09-27 15:34:44 +00009856 /**
9857 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9858 * generally private and require carrier privileges to view.
9859 *
9860 * @hide
9861 */
9862 @NonNull
9863 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9864 List<UiccPortInfo> portinfo = new ArrayList<>();
9865 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9866 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9867 }
9868 return new UiccCardInfo(
9869 cardInfo.isEuicc(),
9870 cardInfo.getCardId(),
9871 null,
9872 cardInfo.getPhysicalSlotIndex(),
9873 cardInfo.isRemovable(),
9874 cardInfo.isMultipleEnabledProfilesSupported(),
9875 portinfo
9876 );
9877 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009878
sandeepjsb6c87872021-09-27 15:34:44 +00009879 /**
9880 * @hide
9881 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9882 * These values are generally private and require carrier privileges to view.
9883 */
9884 @NonNull
9885 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9886 return new UiccPortInfo(
9887 UiccPortInfo.ICCID_REDACTED,
9888 portInfo.getPortIndex(),
9889 portInfo.getLogicalSlotIndex(),
9890 portInfo.isActive()
9891 );
9892 }
9893 @Override
9894 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009895 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009896 mApp.getSystemService(AppOpsManager.class)
9897 .checkPackage(Binder.getCallingUid(), callingPackage);
9898
sandeepjsb6c87872021-09-27 15:34:44 +00009899 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009900
Aman Guptaf3c90b32022-03-17 04:54:16 +00009901 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9902 // we are reading iccId which is PII data.
9903 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009904
9905 // checking compatibility, if calling app's target SDK is T and beyond.
9906 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9907 Binder.getCallingUid())) {
9908 isLogicalSlotAccessRestricted = true;
9909 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009910 final long identity = Binder.clearCallingIdentity();
9911 try {
9912 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009913 if (slots == null || slots.length == 0) {
9914 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009915 return null;
9916 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009917 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9918 for (int i = 0; i < slots.length; i++) {
9919 UiccSlot slot = slots[i];
9920 if (slot == null) {
9921 continue;
9922 }
9923
Jordan Liu7be7e652019-05-06 18:55:02 +00009924 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009925 UiccCard card = slot.getUiccCard();
9926 if (card != null) {
9927 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009928 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009929 cardId = slot.getEid();
9930 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009931 // If cardId is null, use iccId of default port as cardId.
9932 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009933 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009934 }
9935
Jordan Liu857451f2019-05-09 16:35:35 -07009936 if (cardId != null) {
9937 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9938 // if cardId is an EID, it's all digits so this is fine
9939 cardId = IccUtils.stripTrailingFs(cardId);
9940 }
9941
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009942 int cardState = 0;
9943 switch (slot.getCardState()) {
9944 case CARDSTATE_ABSENT:
9945 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9946 break;
9947 case CARDSTATE_PRESENT:
9948 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9949 break;
9950 case CARDSTATE_ERROR:
9951 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9952 break;
9953 case CARDSTATE_RESTRICTED:
9954 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9955 break;
9956 default:
9957 break;
9958
9959 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009960 List<UiccPortInfo> portInfos = new ArrayList<>();
9961 int[] portIndexes = slot.getPortList();
9962 for (int portIdx : portIndexes) {
9963 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009964 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009965 portInfos.add(new UiccPortInfo(iccId, portIdx,
9966 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009967 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009968 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009969 slot.isEuicc(),
9970 cardId,
9971 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009972 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009973 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009974 //setting the value after compatibility check
9975 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009976 }
9977 return infos;
9978 } finally {
9979 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009980 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009981 }
9982
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009983 /* Returns null if doesn't have read permission or carrier privilege access. */
9984 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9985 boolean hasReadPermission) {
9986 String iccId = slot.getIccId(portIndex);
9987 if (hasReadPermission) { // if has read permission
9988 return iccId;
9989 } else {
9990 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9991 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9992 // if no read permission, checking carrier privilege access
9993 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9994 return iccId;
9995 }
9996 }
9997 }
9998 // No read permission or carrier privilege access.
9999 return UiccPortInfo.ICCID_REDACTED;
10000 }
10001
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010002 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010003 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010004 public boolean switchSlots(int[] physicalSlots) {
10005 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010006
10007 final long identity = Binder.clearCallingIdentity();
10008 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010009 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10010 for (int i = 0; i < physicalSlots.length; i++) {
10011 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10012 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10013 physicalSlots[i], i));
10014 }
10015 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010016 } finally {
10017 Binder.restoreCallingIdentity(identity);
10018 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010019 }
Jack Yu4c988042018-02-27 15:30:01 -080010020
10021 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010022 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10023 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10024 enforceModifyPermission();
10025
10026 final long identity = Binder.clearCallingIdentity();
10027 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010028 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010029 } finally {
10030 Binder.restoreCallingIdentity(identity);
10031 }
10032 }
10033
10034 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010035 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -080010036 final long identity = Binder.clearCallingIdentity();
10037 try {
10038 return UiccController.getInstance().getCardIdForDefaultEuicc();
10039 } finally {
10040 Binder.restoreCallingIdentity(identity);
10041 }
10042 }
10043
Pengquan Meng85728fb2018-03-12 16:31:21 -070010044 /**
goneil47ffb6e2018-04-06 15:40:58 -070010045 * A test API to reload the UICC profile.
10046 *
10047 * <p>Requires that the calling app has permission
10048 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10049 * @hide
10050 */
10051 @Override
10052 public void refreshUiccProfile(int subId) {
10053 enforceModifyPermission();
10054
10055 final long identity = Binder.clearCallingIdentity();
10056 try {
10057 Phone phone = getPhone(subId);
10058 if (phone == null) {
10059 return;
10060 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010061 UiccPort uiccPort = phone.getUiccPort();
10062 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010063 return;
10064 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010065 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010066 if (uiccProfile == null) {
10067 return;
10068 }
10069 uiccProfile.refresh();
10070 } finally {
10071 Binder.restoreCallingIdentity(identity);
10072 }
10073 }
10074
10075 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010076 * Returns false if the mobile data is disabled by default, otherwise return true.
10077 */
10078 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010079 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010080 }
10081
10082 /**
10083 * Returns true if the data roaming is enabled by default, i.e the system property
10084 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
10085 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
10086 */
10087 private boolean getDefaultDataRoamingEnabled(int subId) {
10088 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010089 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -070010090 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010091 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
10092 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
10093 return isDataRoamingEnabled;
10094 }
10095
10096 /**
10097 * Returns the default network type for the given {@code subId}, if the default network type is
10098 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10099 */
10100 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010101 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010102 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010103 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10104 return list.get(phoneId);
10105 }
10106 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010107 }
fionaxua13278b2018-03-21 00:08:13 -070010108
10109 @Override
10110 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010111 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010112 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010113
10114 final long identity = Binder.clearCallingIdentity();
10115 try {
10116 final Phone phone = getPhone(subId);
10117 if (phone == null) {
10118 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10119 return;
10120 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010121 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10122 if (cpt != null) {
10123 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10124 }
10125 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010126 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10127 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010128 if (carrierPrivilegeRules == null) {
10129 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10130 } else {
10131 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10132 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010133 } finally {
10134 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010135 }
fionaxua13278b2018-03-21 00:08:13 -070010136 }
10137
10138 @Override
10139 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010140 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010141
10142 final long identity = Binder.clearCallingIdentity();
10143 try {
10144 final Phone phone = getPhone(subId);
10145 if (phone == null) {
10146 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10147 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10148 }
10149 return phone.getCarrierIdListVersion();
10150 } finally {
10151 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010152 }
fionaxua13278b2018-03-21 00:08:13 -070010153 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010154
10155 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010156 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10157 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010158 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010159 mApp, subId, callingPackage, callingFeatureId,
10160 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010161 return -1;
10162 }
10163
10164 final long identity = Binder.clearCallingIdentity();
10165 try {
10166 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10167 } finally {
10168 Binder.restoreCallingIdentity(identity);
10169 }
10170 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010171
10172 @Override
10173 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010174 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010175 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010176 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010177
10178 final long identity = Binder.clearCallingIdentity();
10179 try {
10180 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10181 } finally {
10182 Binder.restoreCallingIdentity(identity);
10183 }
10184 }
10185
10186 @Override
10187 public boolean setCdmaRoamingMode(int subId, int mode) {
10188 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10189 mApp, subId, "setCdmaRoamingMode");
10190
10191 final long identity = Binder.clearCallingIdentity();
10192 try {
10193 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10194 } finally {
10195 Binder.restoreCallingIdentity(identity);
10196 }
10197 }
10198
10199 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010200 public int getCdmaSubscriptionMode(int subId) {
10201 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010202 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010203 mApp, subId, "getCdmaSubscriptionMode");
10204
10205 final long identity = Binder.clearCallingIdentity();
10206 try {
10207 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10208 } finally {
10209 Binder.restoreCallingIdentity(identity);
10210 }
10211 }
10212
10213 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010214 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10215 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10216 mApp, subId, "setCdmaSubscriptionMode");
10217
10218 final long identity = Binder.clearCallingIdentity();
10219 try {
10220 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10221 } finally {
10222 Binder.restoreCallingIdentity(identity);
10223 }
10224 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010225
sqianc5eccab2018-10-19 18:46:41 -070010226 @Override
sqian8c685422019-02-22 15:55:18 -080010227 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010228 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010229 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010230 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10231 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010232 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10233 }
10234 final long identity = Binder.clearCallingIdentity();
10235 try {
sqian854d44b2018-12-12 16:48:18 -080010236 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10237 for (Phone phone: PhoneFactory.getPhones()) {
10238 if (phone.getEmergencyNumberTracker() != null
10239 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10240 emergencyNumberListInternal.put(
10241 phone.getSubId(),
10242 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10243 }
sqian11b7a0e2018-12-05 18:48:28 -080010244 }
sqian854d44b2018-12-12 16:48:18 -080010245 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010246 } finally {
10247 Binder.restoreCallingIdentity(identity);
10248 }
sqianc5eccab2018-10-19 18:46:41 -070010249 }
10250
10251 @Override
sqian8c685422019-02-22 15:55:18 -080010252 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010253 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010254 if (!exactMatch) {
10255 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010256 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010257 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010258 }
10259 final long identity = Binder.clearCallingIdentity();
10260 try {
sqian854d44b2018-12-12 16:48:18 -080010261 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010262 //Note: we ignore passed in param exactMatch. We can remove it once
10263 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010264 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010265 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010266 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010267 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010268 }
sqian11b7a0e2018-12-05 18:48:28 -080010269 }
10270 return false;
10271 } finally {
10272 Binder.restoreCallingIdentity(identity);
10273 }
10274 }
10275
sqianf4ca7ed2019-01-15 18:32:07 -080010276 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010277 * Start emergency callback mode for GsmCdmaPhone for testing.
10278 */
10279 @Override
10280 public void startEmergencyCallbackMode() {
10281 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10282 "startEmergencyCallbackMode");
10283 enforceModifyPermission();
10284 final long identity = Binder.clearCallingIdentity();
10285 try {
10286 for (Phone phone : PhoneFactory.getPhones()) {
10287 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10288 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10289 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10290 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10291 gsmCdmaPhone.obtainMessage(
10292 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10293 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10294 }
10295 }
10296 } finally {
10297 Binder.restoreCallingIdentity(identity);
10298 }
10299 }
10300
10301 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010302 * Update emergency number list for test mode.
10303 */
10304 @Override
10305 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10306 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10307 "updateEmergencyNumberListTestMode");
10308
10309 final long identity = Binder.clearCallingIdentity();
10310 try {
10311 for (Phone phone: PhoneFactory.getPhones()) {
10312 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10313 if (tracker != null) {
10314 tracker.executeEmergencyNumberTestModeCommand(action, num);
10315 }
10316 }
10317 } finally {
10318 Binder.restoreCallingIdentity(identity);
10319 }
10320 }
10321
10322 /**
10323 * Get the full emergency number list for test mode.
10324 */
10325 @Override
10326 public List<String> getEmergencyNumberListTestMode() {
10327 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10328 "getEmergencyNumberListTestMode");
10329
10330 final long identity = Binder.clearCallingIdentity();
10331 try {
10332 Set<String> emergencyNumbers = new HashSet<>();
10333 for (Phone phone: PhoneFactory.getPhones()) {
10334 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10335 if (tracker != null) {
10336 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10337 emergencyNumbers.add(num.getNumber());
10338 }
10339 }
10340 }
10341 return new ArrayList<>(emergencyNumbers);
10342 } finally {
10343 Binder.restoreCallingIdentity(identity);
10344 }
10345 }
10346
chen xud6b45bd2018-10-30 22:27:10 -070010347 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010348 public int getEmergencyNumberDbVersion(int subId) {
10349 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10350
10351 final long identity = Binder.clearCallingIdentity();
10352 try {
10353 final Phone phone = getPhone(subId);
10354 if (phone == null) {
10355 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10356 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10357 }
10358 return phone.getEmergencyNumberDbVersion();
10359 } finally {
10360 Binder.restoreCallingIdentity(identity);
10361 }
10362 }
10363
10364 @Override
10365 public void notifyOtaEmergencyNumberDbInstalled() {
10366 enforceModifyPermission();
10367
10368 final long identity = Binder.clearCallingIdentity();
10369 try {
10370 for (Phone phone: PhoneFactory.getPhones()) {
10371 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10372 if (tracker != null) {
10373 tracker.updateOtaEmergencyNumberDatabase();
10374 }
10375 }
10376 } finally {
10377 Binder.restoreCallingIdentity(identity);
10378 }
10379 }
10380
10381 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010382 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010383 enforceActiveEmergencySessionPermission();
10384
10385 final long identity = Binder.clearCallingIdentity();
10386 try {
10387 for (Phone phone: PhoneFactory.getPhones()) {
10388 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10389 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010390 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10391 }
10392 }
10393 } finally {
10394 Binder.restoreCallingIdentity(identity);
10395 }
10396 }
10397
10398 @Override
10399 public void resetOtaEmergencyNumberDbFilePath() {
10400 enforceActiveEmergencySessionPermission();
10401
10402 final long identity = Binder.clearCallingIdentity();
10403 try {
10404 for (Phone phone: PhoneFactory.getPhones()) {
10405 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10406 if (tracker != null) {
10407 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010408 }
10409 }
10410 } finally {
10411 Binder.restoreCallingIdentity(identity);
10412 }
10413 }
10414
10415 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010416 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10417 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10418 Phone phone = getPhone(subId);
10419 if (phone == null) {
10420 return null;
10421 }
10422 final long identity = Binder.clearCallingIdentity();
10423 try {
10424 UiccProfile profile = UiccController.getInstance()
10425 .getUiccProfileForPhone(phone.getPhoneId());
10426 if (profile != null) {
10427 return profile.getCertsFromCarrierPrivilegeAccessRules();
10428 }
10429 } finally {
10430 Binder.restoreCallingIdentity(identity);
10431 }
10432 return null;
10433 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010434
10435 /**
10436 * Enable or disable a modem stack.
10437 */
10438 @Override
10439 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10440 enforceModifyPermission();
10441
10442 final long identity = Binder.clearCallingIdentity();
10443 try {
10444 Phone phone = PhoneFactory.getPhone(slotIndex);
10445 if (phone == null) {
10446 return false;
10447 } else {
10448 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10449 }
10450 } finally {
10451 Binder.restoreCallingIdentity(identity);
10452 }
10453 }
Michelecea4cf22018-12-21 15:00:11 -080010454
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010455 /**
10456 * Whether a modem stack is enabled or not.
10457 */
10458 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010459 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10460 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010461 Phone phone = PhoneFactory.getPhone(slotIndex);
10462 if (phone == null) return false;
10463
10464 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010465 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10466 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010467 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10468 }
10469
10470 final long identity = Binder.clearCallingIdentity();
10471 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010472 try {
10473 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10474 } catch (NoSuchElementException ex) {
10475 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10476 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010477 } finally {
10478 Binder.restoreCallingIdentity(identity);
10479 }
10480 }
10481
Michelecea4cf22018-12-21 15:00:11 -080010482 @Override
Michele0ea7d782019-03-19 14:58:42 -070010483 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010484 enforceModifyPermission();
10485
10486 final long identity = Binder.clearCallingIdentity();
10487 try {
10488 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010489 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010490 .commit();
10491 } finally {
10492 Binder.restoreCallingIdentity(identity);
10493 }
10494 }
10495
10496 @Override
Michele0ea7d782019-03-19 14:58:42 -070010497 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010498 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010499 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010500 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10501 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010502 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010503 }
Michelecea4cf22018-12-21 15:00:11 -080010504
10505 final long identity = Binder.clearCallingIdentity();
10506 try {
Michele0ea7d782019-03-19 14:58:42 -070010507 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010508 } finally {
10509 Binder.restoreCallingIdentity(identity);
10510 }
10511 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010512
Michele0ea7d782019-03-19 14:58:42 -070010513 @TelephonyManager.IsMultiSimSupportedResult
10514 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010515 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10516 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10517 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010518 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10519 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010520 }
10521 // Check if the hardware supports multisim functionality. If usage of multisim is not
10522 // supported by the modem, indicate that it is restricted.
10523 PhoneCapability staticCapability =
10524 mPhoneConfigurationManager.getStaticPhoneCapability();
10525 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010526 loge("isMultiSimSupportedInternal: no static configuration available");
10527 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010528 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010529 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010530 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10531 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010532 }
10533 // Check if support of multiple SIMs is restricted by carrier
10534 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010535 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010536 }
10537
Michele0ea7d782019-03-19 14:58:42 -070010538 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010539 }
10540
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010541 /**
10542 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010543 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10544 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10545 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010546 * @param numOfSims number of active sims we want to switch to
10547 */
10548 @Override
10549 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010550 if (numOfSims == 1) {
10551 enforceModifyPermission();
10552 } else {
10553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10554 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10555 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010556 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010557
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010558 try {
Michele30b57b22019-03-01 12:01:14 -080010559 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010560 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010561 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10562 return;
10563 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010564 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10565 } finally {
10566 Binder.restoreCallingIdentity(identity);
10567 }
10568 }
10569
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010570 @Override
10571 public boolean isApplicationOnUicc(int subId, int appType) {
10572 enforceReadPrivilegedPermission("isApplicationOnUicc");
10573 Phone phone = getPhone(subId);
10574 if (phone == null) {
10575 return false;
10576 }
10577 final long identity = Binder.clearCallingIdentity();
10578 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010579 UiccPort uiccPort = phone.getUiccPort();
10580 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010581 return false;
10582 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010583 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010584 if (uiccProfile == null) {
10585 return false;
10586 }
10587 if (TelephonyManager.APPTYPE_SIM <= appType
10588 && appType <= TelephonyManager.APPTYPE_ISIM) {
10589 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10590 }
10591 return false;
10592 } finally {
10593 Binder.restoreCallingIdentity(identity);
10594 }
10595 }
10596
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010597 /**
chen xub4baa772019-04-03 10:23:41 -070010598 * Get whether making changes to modem configurations will trigger reboot.
10599 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010600 */
10601 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010602 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10603 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010604 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010605 mApp, subId, callingPackage, callingFeatureId,
10606 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010607 return false;
10608 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010609 final long identity = Binder.clearCallingIdentity();
10610 try {
10611 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10612 } finally {
10613 Binder.restoreCallingIdentity(identity);
10614 }
10615 }
10616
Nathan Harold29f5f052019-02-15 13:41:57 -080010617 private void updateModemStateMetrics() {
10618 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10619 // TODO: check the state for each modem if the api is ready.
10620 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10621 }
10622
Pengquan Meng3889a572019-01-23 11:16:29 -080010623 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010624 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010625 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010626 // Verify that the callingPackage belongs to the calling UID
10627 mApp.getSystemService(AppOpsManager.class)
10628 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010629 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010630 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010631 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010632 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10633 if (slotInfos != null) {
10634 for (int i = 0; i < slotInfos.length; i++) {
10635 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10636 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10637 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10638 portInfo.getLogicalSlotIndex()));
10639 }
10640 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010641 }
10642 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010643 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010644 } finally {
10645 Binder.restoreCallingIdentity(identity);
10646 }
10647 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010648
10649 /**
10650 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010651 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010652 */
jimsunf9ec1622022-09-13 21:18:43 +080010653 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010654 @Override
10655 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010656 return getHalVersion(HAL_SERVICE_RADIO);
10657 }
10658
10659 /**
10660 * Get the HAL Version of a specific service
10661 */
10662 @Override
10663 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010664 Phone phone = getDefaultPhone();
10665 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010666 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010667 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10668 return hv.major * 100 + hv.minor;
10669 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010670
10671 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010672 * Get the current calling package name.
10673 * @return the current calling package name
10674 */
10675 @Override
10676 public String getCurrentPackageName() {
10677 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10678 }
10679
10680 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010681 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10682 * corresponding network requests on a subId.
10683 *
10684 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010685 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010686 * 2) APN is un-metered for this subscription, or
10687 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010688 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010689 *
10690 * @return whether data is allowed for a apn type.
10691 *
10692 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010693 */
10694 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010695 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010696 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10697 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010698
10699 // Now that all security checks passes, perform the operation as ourselves.
10700 final long identity = Binder.clearCallingIdentity();
10701 try {
10702 Phone phone = getPhone(subId);
10703 if (phone == null) return false;
10704
Jack Yu27422a52022-03-21 10:38:05 -070010705 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010706 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010707 isMetered = phone.getDataNetworkController().getDataConfigManager()
10708 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10709 phone.getServiceState().getDataRoaming());
10710 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010711 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010712 } finally {
10713 Binder.restoreCallingIdentity(identity);
10714 }
10715 }
10716
10717 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010718 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010719 enforceReadPrivilegedPermission("isApnMetered");
10720
10721 // Now that all security checks passes, perform the operation as ourselves.
10722 final long identity = Binder.clearCallingIdentity();
10723 try {
10724 Phone phone = getPhone(subId);
10725 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010726 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10727 DataUtils.apnTypeToNetworkCapability(apnType),
10728 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010729 } finally {
10730 Binder.restoreCallingIdentity(identity);
10731 }
10732 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010733
10734 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010735 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10736 int subscriptionId, IBooleanConsumer resultCallback) {
10737 enforceModifyPermission();
10738 long token = Binder.clearCallingIdentity();
10739 try {
10740 Phone phone = getPhone(subscriptionId);
10741 if (phone == null) {
10742 try {
10743 if (resultCallback != null) {
10744 resultCallback.accept(false);
10745 }
10746 } catch (RemoteException e) {
10747 // ignore
10748 }
10749 return;
10750 }
10751 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10752 Pair.create(specifiers, (x) -> {
10753 try {
10754 if (resultCallback != null) {
10755 resultCallback.accept(x);
10756 }
10757 } catch (RemoteException e) {
10758 // ignore
10759 }
10760 });
10761 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10762 } finally {
10763 Binder.restoreCallingIdentity(token);
10764 }
10765 }
10766
10767 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010768 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10769 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010770 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010771 mApp, subId, "getSystemSelectionChannels");
10772 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10773 final long identity = Binder.clearCallingIdentity();
10774 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010775 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10776 if (result instanceof IllegalStateException) {
10777 throw (IllegalStateException) result;
10778 }
10779 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010780 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10781 return specifiers;
10782 } finally {
10783 Binder.restoreCallingIdentity(identity);
10784 }
10785 }
10786
10787 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010788 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010789 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010790 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010791 }
10792
10793 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010794 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10795 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010796 if (callingPackage == null) {
10797 callingPackage = getCurrentPackageName();
10798 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010799 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10800 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010801 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10802 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010803 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10804 }
10805 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10806 Intent intent = new Intent();
10807 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10808 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10809 // Bring up choose default SMS subscription dialog right now
10810 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10811 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10812 mApp.startActivity(intent);
10813 }
chen xud5ca2d52019-05-28 15:20:57 -070010814
10815 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010816 public void showSwitchToManagedProfileDialog() {
10817 enforceModifyPermission();
10818
10819 Intent intent = new Intent();
10820 intent.setClass(mApp, ErrorDialogActivity.class);
10821 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10822 mApp.startActivity(intent);
10823 }
10824
10825 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010826 public String getMmsUAProfUrl(int subId) {
10827 //TODO investigate if this API should require proper permission check in R b/133791609
10828 final long identity = Binder.clearCallingIdentity();
10829 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010830 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10831 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10832 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10833 return carrierUAProfUrl;
10834 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010835 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10836 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010837 } finally {
10838 Binder.restoreCallingIdentity(identity);
10839 }
10840 }
10841
10842 @Override
10843 public String getMmsUserAgent(int subId) {
10844 //TODO investigate if this API should require proper permission check in R b/133791609
10845 final long identity = Binder.clearCallingIdentity();
10846 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010847 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10848 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10849 if (!TextUtils.isEmpty(carrierUserAgent)) {
10850 return carrierUserAgent;
10851 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010852 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10853 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010854 } finally {
10855 Binder.restoreCallingIdentity(identity);
10856 }
10857 }
Jack Yub07d4972019-05-28 16:12:25 -070010858
10859 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010860 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10861 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010862
Jack Yub07d4972019-05-28 16:12:25 -070010863 final long identity = Binder.clearCallingIdentity();
10864 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010865 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010866 if (phone == null) return false;
10867
Ling Maf188d502022-09-16 15:22:36 -070010868 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010869 } finally {
10870 Binder.restoreCallingIdentity(identity);
10871 }
10872 }
10873
10874 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010875 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010876 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010877 enforceModifyPermission();
10878
changbettyd5c246e2019-12-24 15:40:37 +080010879 final long identity = Binder.clearCallingIdentity();
10880 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010881 Phone phone = getPhone(subscriptionId);
10882 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010883
Ling Maf188d502022-09-16 15:22:36 -070010884 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010885 } finally {
10886 Binder.restoreCallingIdentity(identity);
10887 }
10888 }
10889
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010890 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010891 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010892 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10893 * otherwise.
10894 */
10895 @Override
10896 public void setCepEnabled(boolean isCepEnabled) {
10897 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10898
10899 final long identity = Binder.clearCallingIdentity();
10900 try {
10901 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10902 for (Phone phone : PhoneFactory.getPhones()) {
10903 Phone defaultPhone = phone.getImsPhone();
10904 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10905 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10906 ImsPhoneCallTracker imsPhoneCallTracker =
10907 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10908 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10909 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10910 + imsPhone.getMsisdn());
10911 }
10912 }
10913 } finally {
10914 Binder.restoreCallingIdentity(identity);
10915 }
10916 }
allenwtsu46dcc572020-01-08 18:24:03 +080010917
10918 /**
10919 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10920 *
10921 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10922 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10923 * before being read.
10924 */
10925 @Override
10926 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10927 isCompressed) {
10928 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10929 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010930 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10931 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10932 }
10933 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010934 // ProvisioningManager can not handle ServiceSpecificException.
10935 // Throw the IllegalStateException and annotate ProvisioningManager.
10936 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010937 }
10938
10939 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010940 try {
Hui Wang761a6682020-10-31 05:12:53 +000010941 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10942 } finally {
10943 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010944 }
10945 }
zoey chene02881a2019-12-30 16:11:23 +080010946
10947 @Override
10948 public boolean isIccLockEnabled(int subId) {
10949 enforceReadPrivilegedPermission("isIccLockEnabled");
10950
10951 // Now that all security checks passes, perform the operation as ourselves.
10952 final long identity = Binder.clearCallingIdentity();
10953 try {
10954 Phone phone = getPhone(subId);
10955 if (phone != null && phone.getIccCard() != null) {
10956 return phone.getIccCard().getIccLockEnabled();
10957 } else {
10958 return false;
10959 }
10960 } finally {
10961 Binder.restoreCallingIdentity(identity);
10962 }
10963 }
10964
10965 /**
10966 * Set the ICC pin lock enabled or disabled.
10967 *
10968 * @return an integer representing the status of IccLock enabled or disabled in the following
10969 * three cases:
10970 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10971 * successfully.
10972 * - Positive number and zero for remaining password attempts.
10973 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10974 *
10975 */
10976 @Override
10977 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10978 enforceModifyPermission();
10979
10980 Phone phone = getPhone(subId);
10981 if (phone == null) {
10982 return 0;
10983 }
10984 // Now that all security checks passes, perform the operation as ourselves.
10985 final long identity = Binder.clearCallingIdentity();
10986 try {
10987 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10988 new Pair<Boolean, String>(enabled, password), phone, null);
10989 return attemptsRemaining;
10990
10991 } catch (Exception e) {
10992 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10993 } finally {
10994 Binder.restoreCallingIdentity(identity);
10995 }
10996 return 0;
10997 }
10998
10999 /**
11000 * Change the ICC password used in ICC pin lock.
11001 *
11002 * @return an integer representing the status of IccLock changed in the following three cases:
11003 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11004 * - Positive number and zero for remaining password attempts.
11005 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11006 *
11007 */
11008 @Override
11009 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11010 enforceModifyPermission();
11011
11012 Phone phone = getPhone(subId);
11013 if (phone == null) {
11014 return 0;
11015 }
11016 // Now that all security checks passes, perform the operation as ourselves.
11017 final long identity = Binder.clearCallingIdentity();
11018 try {
11019 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11020 new Pair<String, String>(oldPassword, newPassword), phone, null);
11021 return attemptsRemaining;
11022
11023 } catch (Exception e) {
11024 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11025 } finally {
11026 Binder.restoreCallingIdentity(identity);
11027 }
11028 return 0;
11029 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011030
11031 /**
11032 * Request for receiving user activity notification
11033 */
11034 @Override
11035 public void requestUserActivityNotification() {
11036 if (!mNotifyUserActivity.get()
11037 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11038 mNotifyUserActivity.set(true);
11039 }
11040 }
11041
11042 /**
11043 * Called when userActivity is signalled in the power manager.
11044 * This is safe to call from any thread, with any window manager locks held or not.
11045 */
11046 @Override
11047 public void userActivity() {
11048 // ***************************************
11049 // * Inherited from PhoneWindowManager *
11050 // ***************************************
11051 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11052 // WITH ITS LOCKS HELD.
11053 //
11054 // This code must be VERY careful about the locks
11055 // it acquires.
11056 // In fact, the current code acquires way too many,
11057 // and probably has lurking deadlocks.
11058
11059 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11060 throw new SecurityException("Only the OS may call notifyUserActivity()");
11061 }
11062
11063 if (mNotifyUserActivity.getAndSet(false)) {
11064 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11065 USER_ACTIVITY_NOTIFICATION_DELAY);
11066 }
11067 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011068
11069 @Override
11070 public boolean canConnectTo5GInDsdsMode() {
11071 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11072 }
Jack Yud10cdd42020-09-28 20:28:01 -070011073
11074 @Override
11075 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11076 String callingFeatureId) {
11077 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11078 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11079 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11080 }
11081
11082 Phone phone = getPhone(subId);
11083 if (phone == null) {
11084 throw new RuntimeException("phone is not available");
11085 }
11086 // Now that all security checks passes, perform the operation as ourselves.
11087 final long identity = Binder.clearCallingIdentity();
11088 try {
11089 return phone.getEquivalentHomePlmns();
11090 } finally {
11091 Binder.restoreCallingIdentity(identity);
11092 }
11093 }
Daniel Bright59e67312020-11-13 11:49:37 -080011094
11095 @Override
11096 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011097 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
11098 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011099 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011100 if (radioInterfaceCapabilities == null) {
11101 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011102 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011103 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011104 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011105
Hui Wang641e81c2020-10-12 12:14:23 -070011106 @Override
11107 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11108 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011109 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11110 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11111 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11112 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11113 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070011114 if (DBG) {
11115 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11116 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11117 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11118 }
11119
11120 if (!SubscriptionManager.isValidSubscriptionId(subId)
11121 || appType < TelephonyManager.APPTYPE_UNKNOWN
11122 || appType > TelephonyManager.APPTYPE_ISIM
11123 || nafUrl == null || securityProtocol == null || callback == null) {
11124 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11125 if (callback != null) {
11126 try {
11127 callback.onAuthenticationFailure(
11128 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11129 } catch (RemoteException exception) {
11130 log("Fail to notify onAuthenticationFailure due to " + exception);
11131 }
11132 return;
11133 }
11134 }
11135
11136 final long token = Binder.clearCallingIdentity();
11137 try {
11138 getGbaManager(subId).bootstrapAuthenticationRequest(
11139 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011140 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011141 } finally {
11142 Binder.restoreCallingIdentity(token);
11143 }
11144 }
11145
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011146 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011147 * Attempts to set the radio power state for all phones for thermal reason.
11148 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011149 * requested radio power state will actually be set. See {@link
11150 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11151 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011152 * @param enable {@code true} if trying to turn radio on.
11153 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11154 * false}.
11155 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011156 private boolean setRadioPowerForThermal(boolean enable) {
11157 boolean isPhoneAvailable = false;
11158 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11159 Phone phone = PhoneFactory.getPhone(i);
11160 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011161 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011162 isPhoneAvailable = true;
11163 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011164 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011165
11166 // return true if successfully informed the phone object about the thermal radio power
11167 // request.
11168 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011169 }
11170
11171 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011172 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011173 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11174 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11175 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11176 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11177 throw new IllegalArgumentException("modem does not support data throttling");
11178 }
11179
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011180 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11181 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011182 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011183 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11184 }
11185
Sarah Chinecc78c42022-03-31 21:16:48 -070011186 setDataEnabledForReason(
11187 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011188
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011189 if (isDataThrottlingSupported) {
11190 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011191 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011192 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11193 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11194 } else if (thermalMitigationResult
11195 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011196 log("Modem likely does not support data throttling on secondary carrier. Data " +
11197 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11198 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011199 }
11200 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011201 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011202
11203 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011204 }
11205
Jack Nudelman644b91a2021-03-12 14:09:48 -080011206 private static List<String> getThermalMitigationAllowlist(Context context) {
11207 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11208 for (String pckg : context.getResources()
11209 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11210 sThermalMitigationAllowlistedPackages.add(pckg);
11211 }
11212 }
11213
11214 return sThermalMitigationAllowlistedPackages;
11215 }
11216
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011217 private boolean isAnyPhoneInEmergencyState() {
11218 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11219 if (tm.isInEmergencyCall()) {
11220 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11221 return true;
11222 }
11223 for (Phone phone : PhoneFactory.getPhones()) {
11224 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11225 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011226 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11227 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011228 return true;
11229 }
11230 }
11231
11232 return false;
11233 }
11234
Jack Nudelman644b91a2021-03-12 14:09:48 -080011235 /**
11236 * Used by shell commands to add an authorized package name for thermal mitigation.
11237 * @param packageName name of package to be allowlisted
11238 * @param context
11239 */
11240 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11241 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11242 sThermalMitigationAllowlistedPackages.add(packageName);
11243 }
11244
11245 /**
11246 * Used by shell commands to remove an authorized package name for thermal mitigation.
11247 * @param packageName name of package to remove from allowlist
11248 * @param context
11249 */
11250 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11251 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11252 sThermalMitigationAllowlistedPackages.remove(packageName);
11253 }
11254
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011255 /**
11256 * Thermal mitigation request to control functionalities at modem.
11257 *
11258 * @param subId the id of the subscription.
11259 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011260 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011261 *
11262 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11263 */
11264 @Override
11265 @ThermalMitigationResult
11266 public int sendThermalMitigationRequest(
11267 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011268 ThermalMitigationRequest thermalMitigationRequest,
11269 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011270 enforceModifyPermission();
11271
Jack Nudelman644b91a2021-03-12 14:09:48 -080011272 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11273 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11274 .contains(callingPackage)) {
11275 throw new SecurityException("Calling package must be configured in the device config. "
11276 + "calling package: " + callingPackage);
11277 }
11278
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011279 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11280 final long identity = Binder.clearCallingIdentity();
11281
11282 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11283 try {
11284 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11285 switch (thermalMitigationAction) {
11286 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11287 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011288 handleDataThrottlingRequest(subId,
11289 thermalMitigationRequest.getDataThrottlingRequest(),
11290 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011291 break;
11292 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11293 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11294 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11295 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11296 }
11297
11298 // Ensure that radio is on. If not able to power on due to phone being
11299 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011300 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011301 thermalMitigationResult =
11302 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11303 break;
11304 }
11305
11306 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011307 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011308 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11309 break;
11310 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11311 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11312 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11313 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11314 }
11315
11316 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11317 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011318 Phone phone = getPhone(subId);
11319 if (phone == null) {
11320 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011321 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011322 break;
11323 }
11324
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011325 TelephonyConnectionService service =
11326 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011327 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011328 Log.e(LOG_TAG, "An emergency call is pending");
11329 thermalMitigationResult =
11330 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11331 break;
11332 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011333 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011334 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011335 break;
11336 }
11337 } else {
11338 thermalMitigationResult =
11339 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11340 break;
11341 }
11342
11343 // Turn radio off. If not able to power off due to phone being unavailable,
11344 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011345 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011346 thermalMitigationResult =
11347 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11348 break;
11349 }
11350 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011351 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011352 break;
11353 default:
11354 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11355 + "not exist. Requested action: " + thermalMitigationAction);
11356 }
11357 } catch (IllegalArgumentException e) {
11358 throw e;
11359 } catch (Exception e) {
11360 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11361 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11362 } finally {
11363 Binder.restoreCallingIdentity(identity);
11364 }
11365
11366 if (DBG) {
11367 log("thermalMitigationRequest returning with thermalMitigationResult: "
11368 + thermalMitigationResult);
11369 }
11370
11371 return thermalMitigationResult;
11372 }
Hui Wang641e81c2020-10-12 12:14:23 -070011373
11374 /**
11375 * Set the GbaService Package Name that Telephony will bind to.
11376 *
11377 * @param subId The sim that the GbaService is associated with.
11378 * @param packageName The name of the package to be replaced with.
11379 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11380 */
11381 @Override
11382 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11383 enforceModifyPermission();
11384
11385 final long identity = Binder.clearCallingIdentity();
11386 try {
11387 return getGbaManager(subId).overrideServicePackage(packageName);
11388 } finally {
11389 Binder.restoreCallingIdentity(identity);
11390 }
11391 }
11392
11393 /**
11394 * Return the package name of the currently bound GbaService.
11395 *
11396 * @param subId The sim that the GbaService is associated with.
11397 * @return the package name of the GbaService configuration, null if GBA is not supported.
11398 */
11399 @Override
11400 public String getBoundGbaService(int subId) {
11401 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11402
11403 final long identity = Binder.clearCallingIdentity();
11404 try {
11405 return getGbaManager(subId).getServicePackage();
11406 } finally {
11407 Binder.restoreCallingIdentity(identity);
11408 }
11409 }
11410
11411 /**
11412 * Set the release time for telephony to unbind GbaService.
11413 *
11414 * @param subId The sim that the GbaService is associated with.
11415 * @param interval The release time to unbind GbaService by millisecond.
11416 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11417 */
11418 @Override
11419 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11420 enforceModifyPermission();
11421
11422 final long identity = Binder.clearCallingIdentity();
11423 try {
11424 return getGbaManager(subId).overrideReleaseTime(interval);
11425 } finally {
11426 Binder.restoreCallingIdentity(identity);
11427 }
11428 }
11429
11430 /**
11431 * Return the release time for telephony to unbind GbaService.
11432 *
11433 * @param subId The sim that the GbaService is associated with.
11434 * @return The release time to unbind GbaService by millisecond.
11435 */
11436 @Override
11437 public int getGbaReleaseTime(int subId) {
11438 enforceReadPrivilegedPermission("getGbaReleaseTime");
11439
11440 final long identity = Binder.clearCallingIdentity();
11441 try {
11442 return getGbaManager(subId).getReleaseTime();
11443 } finally {
11444 Binder.restoreCallingIdentity(identity);
11445 }
11446 }
11447
11448 private GbaManager getGbaManager(int subId) {
11449 GbaManager instance = GbaManager.getInstance(subId);
11450 if (instance == null) {
11451 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11452 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11453 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11454 }
11455 return instance;
11456 }
Hui Wang761a6682020-10-31 05:12:53 +000011457
11458 /**
11459 * indicate whether the device and the carrier can support
11460 * RCS VoLTE single registration.
11461 */
11462 @Override
11463 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011464 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11465 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11466 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11467 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011468
11469 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11470 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11471 }
11472
11473 final long identity = Binder.clearCallingIdentity();
11474 try {
11475 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11476 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011477 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11478 if (isCapable != null) {
11479 return isCapable;
11480 }
Hui Wang761a6682020-10-31 05:12:53 +000011481 }
Hui Wang67af90e2021-06-04 16:57:15 -070011482 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11483 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011484 } finally {
11485 Binder.restoreCallingIdentity(identity);
11486 }
11487 }
11488
11489 /**
11490 * Register RCS provisioning callback.
11491 */
11492 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011493 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011494 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011495 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011496 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011497 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11498 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011499
11500 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11501 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11502 }
11503 if (!isImsAvailableOnDevice()) {
11504 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11505 "IMS not available on device.");
11506 }
11507
11508 final long identity = Binder.clearCallingIdentity();
11509 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011510 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011511 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011512 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11513 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011514 }
Hui Wang761a6682020-10-31 05:12:53 +000011515 } finally {
11516 Binder.restoreCallingIdentity(identity);
11517 }
11518 }
11519
11520 /**
11521 * Unregister RCS provisioning callback.
11522 */
11523 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011524 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011525 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011526 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011527 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011528 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11529 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011530
11531 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11532 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11533 }
11534 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011535 // operation failed silently
11536 Rlog.w(LOG_TAG, "IMS not available on device.");
11537 return;
Hui Wang761a6682020-10-31 05:12:53 +000011538 }
11539
11540 final long identity = Binder.clearCallingIdentity();
11541 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011542 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011543 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011544 } finally {
11545 Binder.restoreCallingIdentity(identity);
11546 }
11547 }
11548
11549 /**
11550 * trigger RCS reconfiguration.
11551 */
11552 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011553 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11554 "triggerRcsReconfiguration",
11555 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011556
11557 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11558 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11559 }
11560 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011561 // ProvisioningManager can not handle ServiceSpecificException.
11562 // Throw the IllegalStateException and annotate ProvisioningManager.
11563 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000011564 }
11565
11566 final long identity = Binder.clearCallingIdentity();
11567 try {
11568 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11569 } finally {
11570 Binder.restoreCallingIdentity(identity);
11571 }
11572 }
11573
11574 /**
11575 * Provide the client configuration parameters of the RCS application.
11576 */
11577 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011578 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11579 "setRcsClientConfiguration",
11580 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011581
11582 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11583 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11584 }
11585 if (!isImsAvailableOnDevice()) {
11586 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11587 "IMS not available on device.");
11588 }
11589
11590 final long identity = Binder.clearCallingIdentity();
11591
11592 try {
11593 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11594 if (configBinder == null) {
11595 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011596 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11597 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011598 } else {
11599 configBinder.setRcsClientConfiguration(rcc);
11600 }
joonhunshin3e154242021-09-17 06:33:39 +000011601
11602 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11603 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011604 } catch (RemoteException e) {
11605 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011606 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11607 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011608 } finally {
11609 Binder.restoreCallingIdentity(identity);
11610 }
11611 }
11612
11613 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011614 * Enables or disables the test mode for RCS VoLTE single registration.
11615 */
11616 @Override
11617 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11618 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11619 "setRcsSingleRegistrationTestModeEnabled");
11620
11621 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11622 }
11623
11624 /**
11625 * Gets the test mode for RCS VoLTE single registration.
11626 */
11627 @Override
11628 public boolean getRcsSingleRegistrationTestModeEnabled() {
11629 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11630 "getRcsSingleRegistrationTestModeEnabled");
11631
11632 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11633 }
11634
11635 /**
Hui Wang761a6682020-10-31 05:12:53 +000011636 * Overrides the config of RCS VoLTE single registration enabled for the device.
11637 */
11638 @Override
11639 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11640 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11641 "setDeviceSingleRegistrationEnabledOverride");
11642 enforceModifyPermission();
11643
11644 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11645 : Boolean.parseBoolean(enabledStr);
11646 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011647 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011648 }
11649
11650 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011651 * Sends a device to device communication message. Only usable via shell.
11652 * @param message message to send.
11653 * @param value message value.
11654 */
11655 @Override
11656 public void sendDeviceToDeviceMessage(int message, int value) {
11657 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011658 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011659 enforceModifyPermission();
11660
11661 final long identity = Binder.clearCallingIdentity();
11662 try {
11663 TelephonyConnectionService service =
11664 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11665 if (service == null) {
11666 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11667 return;
11668 }
11669 service.sendTestDeviceToDeviceMessage(message, value);
11670 } finally {
11671 Binder.restoreCallingIdentity(identity);
11672 }
11673 }
11674
Tyler Gunnbabbda02021-02-10 11:05:02 -080011675 /**
11676 * Sets the specified device to device transport active.
11677 * @param transport The transport to set active.
11678 */
11679 @Override
11680 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11681 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11682 "setActiveDeviceToDeviceTransport");
11683 enforceModifyPermission();
11684
11685 final long identity = Binder.clearCallingIdentity();
11686 try {
11687 TelephonyConnectionService service =
11688 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11689 if (service == null) {
11690 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11691 return;
11692 }
11693 service.setActiveDeviceToDeviceTransport(transport);
11694 } finally {
11695 Binder.restoreCallingIdentity(identity);
11696 }
11697 }
Tyler Gunn92479152021-01-20 16:30:10 -080011698
Tyler Gunnd4339262021-05-03 14:46:49 -070011699 @Override
11700 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11701 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11702 "setDeviceToDeviceForceEnabled");
11703
11704 final long identity = Binder.clearCallingIdentity();
11705 try {
11706 Arrays.stream(PhoneFactory.getPhones()).forEach(
11707 p -> {
11708 Phone thePhone = p.getImsPhone();
11709 if (thePhone != null && thePhone instanceof ImsPhone) {
11710 ImsPhone imsPhone = (ImsPhone) thePhone;
11711 CallTracker tracker = imsPhone.getCallTracker();
11712 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11713 ImsPhoneCallTracker imsPhoneCallTracker =
11714 (ImsPhoneCallTracker) tracker;
11715 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11716 }
11717 }
11718 }
11719 );
11720 } finally {
11721 Binder.restoreCallingIdentity(identity);
11722 }
11723 }
11724
Tyler Gunn92479152021-01-20 16:30:10 -080011725 /**
Hui Wang761a6682020-10-31 05:12:53 +000011726 * Gets the config of RCS VoLTE single registration enabled for the device.
11727 */
11728 @Override
11729 public boolean getDeviceSingleRegistrationEnabled() {
11730 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11731 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11732 }
11733
11734 /**
11735 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11736 */
11737 @Override
11738 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11739 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11740 "setCarrierSingleRegistrationEnabledOverride");
11741 enforceModifyPermission();
11742
11743 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11744 : Boolean.parseBoolean(enabledStr);
11745 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11746 subId, enabled);
11747 }
11748
11749 /**
11750 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11751 */
11752 @Override
11753 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11754 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11755 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11756 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011757
11758 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011759 * Overrides the ims feature validation result
11760 */
11761 @Override
11762 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11763 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11764 "setImsFeatureValidationOverride");
11765
11766 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11767 : Boolean.parseBoolean(enabledStr);
11768 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11769 subId, enabled);
11770 }
11771
11772 /**
11773 * Gets the ims feature validation override value
11774 */
11775 @Override
11776 public boolean getImsFeatureValidationOverride(int subId) {
11777 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11778 "getImsFeatureValidationOverride");
11779 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11780 }
11781
11782 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011783 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11784 * their mobile plan.
11785 */
11786 @Override
11787 public String getMobileProvisioningUrl() {
11788 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11789 final long identity = Binder.clearCallingIdentity();
11790 try {
11791 return getDefaultPhone().getMobileProvisioningUrl();
11792 } finally {
11793 Binder.restoreCallingIdentity(identity);
11794 }
11795 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011796
James.cf Linbcdf8b32021-01-14 16:44:13 +080011797 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011798 * Get the EAB contact from the EAB database.
11799 */
11800 @Override
11801 public String getContactFromEab(String contact) {
11802 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11803 enforceModifyPermission();
11804 final long identity = Binder.clearCallingIdentity();
11805 try {
11806 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11807 } finally {
11808 Binder.restoreCallingIdentity(identity);
11809 }
11810 }
11811
11812 /**
Calvin Pana1434322021-07-01 19:27:01 +080011813 * Get the EAB capability from the EAB database.
11814 */
11815 @Override
11816 public String getCapabilityFromEab(String contact) {
11817 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11818 enforceModifyPermission();
11819 final long identity = Binder.clearCallingIdentity();
11820 try {
11821 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11822 } finally {
11823 Binder.restoreCallingIdentity(identity);
11824 }
11825 }
11826
11827 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011828 * Remove the EAB contacts from the EAB database.
11829 */
11830 @Override
11831 public int removeContactFromEab(int subId, String contacts) {
11832 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11833 enforceModifyPermission();
11834 final long identity = Binder.clearCallingIdentity();
11835 try {
11836 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11837 } finally {
11838 Binder.restoreCallingIdentity(identity);
11839 }
11840 }
11841
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011842 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011843 public boolean getDeviceUceEnabled() {
11844 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11845 final long identity = Binder.clearCallingIdentity();
11846 try {
11847 return mApp.getDeviceUceEnabled();
11848 } finally {
11849 Binder.restoreCallingIdentity(identity);
11850 }
11851 }
11852
11853 @Override
11854 public void setDeviceUceEnabled(boolean isEnabled) {
11855 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11856 final long identity = Binder.clearCallingIdentity();
11857 try {
11858 mApp.setDeviceUceEnabled(isEnabled);
11859 } finally {
11860 Binder.restoreCallingIdentity(identity);
11861 }
11862 }
11863
Brad Ebinger14d467f2021-02-12 06:18:28 +000011864 /**
11865 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11866 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11867 */
11868 // Used for SHELL command only right now.
11869 @Override
11870 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11871 List<String> featureTags) {
11872 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11873 "addUceRegistrationOverrideShell");
11874 final long identity = Binder.clearCallingIdentity();
11875 try {
11876 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11877 new ArraySet<>(featureTags));
11878 } catch (ImsException e) {
11879 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11880 } finally {
11881 Binder.restoreCallingIdentity(identity);
11882 }
11883 }
11884
11885 /**
11886 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11887 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11888 */
11889 // Used for SHELL command only right now.
11890 @Override
11891 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11892 List<String> featureTags) {
11893 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11894 "removeUceRegistrationOverrideShell");
11895 final long identity = Binder.clearCallingIdentity();
11896 try {
11897 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11898 new ArraySet<>(featureTags));
11899 } catch (ImsException e) {
11900 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11901 } finally {
11902 Binder.restoreCallingIdentity(identity);
11903 }
11904 }
11905
11906 /**
11907 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11908 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11909 */
11910 // Used for SHELL command only right now.
11911 @Override
11912 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11913 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11914 "clearUceRegistrationOverrideShell");
11915 final long identity = Binder.clearCallingIdentity();
11916 try {
11917 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11918 } catch (ImsException e) {
11919 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11920 } finally {
11921 Binder.restoreCallingIdentity(identity);
11922 }
11923 }
11924
11925 /**
11926 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11927 */
11928 // Used for SHELL command only right now.
11929 @Override
11930 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11931 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11932 "getLatestRcsContactUceCapabilityShell");
11933 final long identity = Binder.clearCallingIdentity();
11934 try {
11935 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11936 } catch (ImsException e) {
11937 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11938 } finally {
11939 Binder.restoreCallingIdentity(identity);
11940 }
11941 }
11942
11943 /**
11944 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11945 * device does not have an active PUBLISH.
11946 */
11947 // Used for SHELL command only right now.
11948 @Override
11949 public String getLastUcePidfXmlShell(int subId) {
11950 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11951 final long identity = Binder.clearCallingIdentity();
11952 try {
11953 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11954 } catch (ImsException e) {
11955 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11956 } finally {
11957 Binder.restoreCallingIdentity(identity);
11958 }
11959 }
11960
James.cf Line8713a42021-04-29 16:04:26 +080011961 /**
11962 * Remove UCE requests cannot be sent to the network status.
11963 */
11964 // Used for SHELL command only right now.
11965 @Override
11966 public boolean removeUceRequestDisallowedStatus(int subId) {
11967 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11968 final long identity = Binder.clearCallingIdentity();
11969 try {
11970 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11971 } catch (ImsException e) {
11972 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11973 } finally {
11974 Binder.restoreCallingIdentity(identity);
11975 }
11976 }
11977
James.cf Lin18bb9002021-05-25 01:37:38 +080011978 /**
11979 * Remove UCE requests cannot be sent to the network status.
11980 */
11981 // Used for SHELL command only.
11982 @Override
11983 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11984 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11985 final long identity = Binder.clearCallingIdentity();
11986 try {
11987 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11988 } catch (ImsException e) {
11989 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11990 } finally {
11991 Binder.restoreCallingIdentity(identity);
11992 }
11993 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011994
James.cf Lin4b784aa2021-01-31 03:25:15 +080011995 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011996 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11997 String callingPackage) {
11998 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11999 mApp, subId, "setSignalStrengthUpdateRequest");
12000
12001 final int callingUid = Binder.getCallingUid();
12002 // Verify that tha callingPackage belongs to the calling UID
12003 mApp.getSystemService(AppOpsManager.class)
12004 .checkPackage(callingUid, callingPackage);
12005
Rambo Wang3607f502021-02-01 21:51:40 -080012006 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012007
12008 final long identity = Binder.clearCallingIdentity();
12009 try {
12010 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12011 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12012
12013 if (result instanceof IllegalStateException) {
12014 throw (IllegalStateException) result;
12015 }
12016 } finally {
12017 Binder.restoreCallingIdentity(identity);
12018 }
12019 }
12020
12021 @Override
12022 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12023 String callingPackage) {
12024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12025 mApp, subId, "clearSignalStrengthUpdateRequest");
12026
12027 final int callingUid = Binder.getCallingUid();
12028 // Verify that tha callingPackage belongs to the calling UID
12029 mApp.getSystemService(AppOpsManager.class)
12030 .checkPackage(callingUid, callingPackage);
12031
12032 final long identity = Binder.clearCallingIdentity();
12033 try {
12034 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12035 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12036
12037 if (result instanceof IllegalStateException) {
12038 throw (IllegalStateException) result;
12039 }
12040 } finally {
12041 Binder.restoreCallingIdentity(identity);
12042 }
12043 }
12044
Rambo Wang3607f502021-02-01 21:51:40 -080012045 private static void validateSignalStrengthUpdateRequest(Context context,
12046 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012047 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12048 // phone/system process do not have further restriction on request
12049 return;
12050 }
12051
12052 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012053 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012054 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012055 context.enforceCallingOrSelfPermission(
12056 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12057 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012058 }
12059
12060 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012061 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012062 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012063 || info.isEnabled()) {
12064 throw new IllegalArgumentException(
12065 "Only system can set hide fields in SignalThresholdInfo");
12066 }
12067
12068 // Thresholds length for each RAN need in range. This has been validated in
12069 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12070 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12071 final int[] thresholds = info.getThresholds();
12072 Objects.requireNonNull(thresholds);
12073 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12074 || thresholds.length
12075 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12076 throw new IllegalArgumentException(
12077 "thresholds length is out of range: " + thresholds.length);
12078 }
12079 }
12080 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012081
12082 /**
12083 * Gets the current phone capability.
12084 *
12085 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12086 * @return the PhoneCapability which describes the data connection capability of modem.
12087 * It's used to evaluate possible phone config change, for example from single
12088 * SIM device to multi-SIM device.
12089 */
12090 @Override
12091 public PhoneCapability getPhoneCapability() {
12092 enforceReadPrivilegedPermission("getPhoneCapability");
12093 final long identity = Binder.clearCallingIdentity();
12094 try {
12095 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12096 } finally {
12097 Binder.restoreCallingIdentity(identity);
12098 }
12099 }
Michele Berionne5e411512020-11-13 02:36:59 +000012100
12101 /**
12102 * Prepare TelephonyManager for an unattended reboot. The reboot is
12103 * required to be done shortly after the API is invoked.
12104 */
12105 @Override
12106 @TelephonyManager.PrepareUnattendedRebootResult
12107 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012108 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012109 enforceRebootPermission();
12110
12111 final long identity = Binder.clearCallingIdentity();
12112 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012113 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012114 } finally {
12115 Binder.restoreCallingIdentity(identity);
12116 }
12117 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012118
12119 /**
12120 * Request to get the current slicing configuration including URSP rules and
12121 * NSSAIs (configured, allowed and rejected).
12122 *
12123 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12124 */
12125 @Override
12126 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012127 TelephonyPermissions
12128 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12129 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012130
12131 final long identity = Binder.clearCallingIdentity();
12132 try {
12133 Phone phone = getDefaultPhone();
12134 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12135 } finally {
12136 Binder.restoreCallingIdentity(identity);
12137 }
12138 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012139
12140 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012141 * Check whether the given premium capability is available for purchase from the carrier.
12142 *
12143 * @param capability The premium capability to check.
12144 * @param subId The subId to check the premium capability for.
12145 *
12146 * @return Whether the given premium capability is available to purchase.
12147 */
12148 @Override
12149 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12150 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12151 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12152 log("Premium capability "
12153 + TelephonyManager.convertPremiumCapabilityToString(capability)
12154 + " is not available for purchase due to missing permissions.");
12155 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12156 + "permission READ_BASIC_PHONE_STATE.");
12157 }
12158
12159 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012160 if (phone == null) {
12161 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12162 return false;
12163 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012164 final long identity = Binder.clearCallingIdentity();
12165 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070012166 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012167 .isPremiumCapabilityAvailableForPurchase(capability);
12168 } finally {
12169 Binder.restoreCallingIdentity(identity);
12170 }
12171 }
12172
12173 /**
12174 * Purchase the given premium capability from the carrier.
12175 *
12176 * @param capability The premium capability to purchase.
12177 * @param callback The result of the purchase request.
12178 * @param subId The subId to purchase the premium capability for.
12179 */
12180 @Override
12181 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12182 log("purchasePremiumCapability: capability="
12183 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12184 + getCurrentPackageName());
12185
12186 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12187 mApp, "purchasePremiumCapability")) {
12188 log("purchasePremiumCapability "
12189 + TelephonyManager.convertPremiumCapabilityToString(capability)
12190 + " failed due to missing permissions.");
12191 throw new SecurityException("purchasePremiumCapability requires permission "
12192 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012193 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12194 mApp, "purchasePremiumCapability")) {
12195 log("purchasePremiumCapability "
12196 + TelephonyManager.convertPremiumCapabilityToString(capability)
12197 + " failed due to missing permissions.");
12198 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012199 }
12200
12201 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012202 if (phone == null) {
12203 try {
12204 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12205 callback.accept(result);
12206 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12207 } catch (RemoteException e) {
12208 String logStr = "Purchase premium capability "
12209 + TelephonyManager.convertPremiumCapabilityToString(capability)
12210 + " failed due to RemoteException handling null phone: " + e;
12211 if (DBG) log(logStr);
12212 AnomalyReporter.reportAnomaly(
12213 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12214 }
12215 return;
12216 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012217
12218 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012219 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012220 callingProcess = mApp.getPackageManager().getApplicationInfo(
12221 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012222 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012223 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012224 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012225
12226 boolean isVisible = false;
12227 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12228 if (am != null) {
12229 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12230 if (processes != null) {
12231 for (ActivityManager.RunningAppProcessInfo process : processes) {
12232 log("purchasePremiumCapability: process " + process.processName
12233 + "has importance " + process.importance);
12234 if (process.processName.equals(callingProcess) && process.importance
12235 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12236 isVisible = true;
12237 break;
12238 }
12239 }
12240 }
12241 }
12242
12243 if (!isVisible) {
12244 try {
12245 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12246 callback.accept(result);
12247 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12248 } catch (RemoteException e) {
12249 String logStr = "Purchase premium capability "
12250 + TelephonyManager.convertPremiumCapabilityToString(capability)
12251 + " failed due to RemoteException handling background application: " + e;
12252 if (DBG) log(logStr);
12253 AnomalyReporter.reportAnomaly(
12254 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12255 }
12256 return;
12257 }
12258
Sarah Chin71b3a852022-09-28 15:54:19 -070012259 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012260 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012261 }
12262
12263 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012264 * Register an IMS connection state callback
12265 */
12266 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012267 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12268 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012269 if (feature == ImsFeature.FEATURE_MMTEL) {
12270 // ImsMmTelManager
12271 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12272 TelephonyPermissions
12273 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12274 mApp, subId, "registerImsStateCallback");
12275 } else if (feature == ImsFeature.FEATURE_RCS) {
12276 // ImsRcsManager or SipDelegateManager
12277 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12278 Binder.getCallingUid(), "registerImsStateCallback",
12279 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12280 Manifest.permission.READ_PRECISE_PHONE_STATE,
12281 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12282 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12283 }
12284
12285 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12286 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12287 "IMS not available on device.");
12288 }
12289
12290 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12291 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12292 }
12293
12294 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12295 if (controller == null) {
12296 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12297 "IMS not available on device.");
12298 }
12299
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012300 if (callingPackage == null) {
12301 callingPackage = getCurrentPackageName();
12302 }
12303
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012304 final long token = Binder.clearCallingIdentity();
12305 try {
12306 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012307 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012308 } catch (ImsException e) {
12309 throw new ServiceSpecificException(e.getCode());
12310 } finally {
12311 Binder.restoreCallingIdentity(token);
12312 }
12313 }
12314
12315 /**
12316 * Unregister an IMS connection state callback
12317 */
12318 @Override
12319 public void unregisterImsStateCallback(IImsStateCallback cb) {
12320 final long token = Binder.clearCallingIdentity();
12321 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12322 if (controller == null) {
12323 return;
12324 }
12325 try {
12326 controller.unregisterImsStateCallback(cb);
12327 } finally {
12328 Binder.restoreCallingIdentity(token);
12329 }
12330 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012331
12332 /**
12333 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12334 *
12335 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
12336 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
12337 * SecurityException.
12338 * If there is current registered network this value will be same as the registered cell
12339 * identity. If the device goes out of service the previous cell identity is cached and
12340 * will be returned. If the cache age of the Cell identity is more than 24 hours
12341 * it will be cleared and null will be returned.
12342 *
12343 */
12344 @Override
12345 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12346 String callingFeatureId) {
12347 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12348 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12349 LocationAccessPolicy.checkLocationPermission(mApp,
12350 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12351 .setCallingPackage(callingPackage)
12352 .setCallingFeatureId(callingFeatureId)
12353 .setCallingPid(Binder.getCallingPid())
12354 .setCallingUid(Binder.getCallingUid())
12355 .setMethod("getLastKnownCellIdentity")
12356 .setLogAsInfo(true)
12357 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12358 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12359 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12360 .build());
12361
12362 boolean hasFinePermission =
12363 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12364 if (!hasFinePermission
12365 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12366 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012367 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012368 }
12369
12370 final long identity = Binder.clearCallingIdentity();
12371 try {
12372 Phone phone = getPhone(subId);
12373 if (phone == null) return null;
12374 ServiceStateTracker sst = phone.getServiceStateTracker();
12375 if (sst == null) return null;
12376 return sst.getLastKnownCellIdentity();
12377 } finally {
12378 Binder.restoreCallingIdentity(identity);
12379 }
12380 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012381
jimsun3b9ccac2021-10-26 15:01:23 +080012382 /**
12383 * Sets the modem service class Name that Telephony will bind to.
12384 *
12385 * @param serviceName The class name of the modem service.
12386 * @return true if the operation is succeed, otherwise false.
12387 */
12388 public boolean setModemService(String serviceName) {
12389 Log.d(LOG_TAG, "setModemService - " + serviceName);
12390 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012392 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12393 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012394 return mPhoneConfigurationManager.setModemService(serviceName);
12395 }
12396
12397 /**
12398 * Return the class name of the currently bounded modem service.
12399 *
12400 * @return the class name of the modem service.
12401 */
12402 public String getModemService() {
12403 String result;
12404 Log.d(LOG_TAG, "getModemService");
12405 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12406 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012407 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012408 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12409 "getModemService");
12410 result = mPhoneConfigurationManager.getModemService();
12411 Log.d(LOG_TAG, "result = " + result);
12412 return result;
12413 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012414
12415 @Override
12416 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12417 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12418 mApp.enforceCallingOrSelfPermission(
12419 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12420 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12421
12422 final long identity = Binder.clearCallingIdentity();
12423 try {
12424 Phone phone = getPhone(subId);
12425 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012426 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12427 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012428 phone.setVoiceServiceStateOverride(hasService);
12429 } finally {
12430 Binder.restoreCallingIdentity(identity);
12431 }
12432 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012433
12434 /**
12435 * set removable eSIM as default eUICC.
12436 *
12437 * @hide
12438 */
12439 @Override
12440 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12441 enforceModifyPermission();
12442 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12443
12444 final long identity = Binder.clearCallingIdentity();
12445 try {
12446 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12447 } finally {
12448 Binder.restoreCallingIdentity(identity);
12449 }
12450 }
12451
12452 /**
12453 * Returns whether the removable eSIM is default eUICC or not.
12454 *
12455 * @hide
12456 */
12457 @Override
12458 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12459 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12460 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12461
12462 final long identity = Binder.clearCallingIdentity();
12463 try {
12464 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12465 } finally {
12466 Binder.restoreCallingIdentity(identity);
12467 }
12468 }
12469
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012470 /**
12471 * Get the component name of the default app to direct respond-via-message intent for the
12472 * user associated with this subscription, update the cache if there is no respond-via-message
12473 * application currently configured for this user.
12474 * @return component name of the app and class to direct Respond Via Message intent to, or
12475 * {@code null} if the functionality is not supported.
12476 * @hide
12477 */
12478 @Override
12479 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12480 boolean updateIfNeeded) {
12481 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012482
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012483 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12484
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012485 UserHandle userHandle = null;
12486 final long identity = Binder.clearCallingIdentity();
12487 try {
12488 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12489 } finally {
12490 Binder.restoreCallingIdentity(identity);
12491 }
12492 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12493 updateIfNeeded, userHandle);
12494 }
Jack Yuf5badd92022-12-08 00:50:53 -080012495
12496 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012497 * Set whether the device is able to connect with null ciphering or integrity
12498 * algorithms. This is a global setting and will apply to all active subscriptions
12499 * and all new subscriptions after this.
12500 *
12501 * @param enabled when true, null cipher and integrity algorithms are allowed.
12502 * @hide
12503 */
12504 @Override
12505 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12506 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12507 enforceModifyPermission();
12508 checkForNullCipherAndIntegritySupport();
12509
12510 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12511 // for listening to these preference changes and applying them immediately.
12512 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12513 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12514 editor.apply();
12515
12516 for (Phone phone: PhoneFactory.getPhones()) {
12517 phone.handleNullCipherEnabledChange();
12518 }
12519 }
12520
12521
12522 /**
12523 * Get whether the device is able to connect with null ciphering or integrity
12524 * algorithms. Note that this retrieves the phone-global preference and not
12525 * the state of the radio.
12526 *
12527 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12528 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12529 * version for this feature.
12530 * @hide
12531 */
12532 @Override
12533 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12534 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12535 enforceReadPermission();
12536 checkForNullCipherAndIntegritySupport();
12537 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12538 }
12539
12540 private void checkForNullCipherAndIntegritySupport() {
12541 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12542 throw new UnsupportedOperationException(
12543 "Null cipher and integrity operations require HAL 2.1 or above");
12544 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012545 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12546 throw new UnsupportedOperationException(
12547 "Null cipher and integrity operations unsupported by modem");
12548 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012549 }
12550
12551 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012552 * Get the SIM state for the slot index.
12553 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12554 *
12555 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12556 */
12557 @Override
12558 @SimState
12559 public int getSimStateForSlotIndex(int slotIndex) {
12560 IccCardConstants.State simState;
12561 if (slotIndex < 0) {
12562 simState = IccCardConstants.State.UNKNOWN;
12563 } else {
12564 Phone phone = null;
12565 try {
12566 phone = PhoneFactory.getPhone(slotIndex);
12567 } catch (IllegalStateException e) {
12568 // ignore
12569 }
12570 if (phone == null) {
12571 simState = IccCardConstants.State.UNKNOWN;
12572 } else {
12573 IccCard icc = phone.getIccCard();
12574 if (icc == null) {
12575 simState = IccCardConstants.State.UNKNOWN;
12576 } else {
12577 simState = icc.getState();
12578 }
12579 }
12580 }
12581 return simState.ordinal();
12582 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012583
12584 /**
12585 * Get current cell broadcast ranges.
12586 */
12587 @Override
12588 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12589 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12590 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12591 "getCellBroadcastIdRanges");
12592 final long identity = Binder.clearCallingIdentity();
12593 try {
12594 return getPhone(subId).getCellBroadcastIdRanges();
12595 } finally {
12596 Binder.restoreCallingIdentity(identity);
12597 }
12598 }
12599
12600 /**
12601 * Set reception of cell broadcast messages with the list of the given ranges
12602 *
12603 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12604 */
12605 @Override
12606 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12607 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12608 @Nullable IIntegerConsumer callback) {
12609 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12610 "setCellBroadcastIdRanges");
12611 final long identity = Binder.clearCallingIdentity();
12612 try {
12613 Phone phone = getPhoneFromSubId(subId);
12614 if (DBG) {
12615 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12616 }
12617 phone.setCellBroadcastIdRanges(ranges, result -> {
12618 if (callback != null) {
12619 try {
12620 callback.accept(result);
12621 } catch (RemoteException e) {
12622 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12623 }
12624 }
12625 });
12626 } finally {
12627 Binder.restoreCallingIdentity(identity);
12628 }
12629 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012630
12631 /**
12632 * Returns whether the device supports the domain selection service.
12633 *
12634 * @return {@code true} if the device supports the domain selection service.
12635 */
12636 @Override
12637 public boolean isDomainSelectionSupported() {
12638 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12639 "isDomainSelectionSupported");
12640
12641 final long identity = Binder.clearCallingIdentity();
12642 try {
12643 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12644 } finally {
12645 Binder.restoreCallingIdentity(identity);
12646 }
12647 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012648
12649 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012650 * Enable or disable the satellite modem. If the satellite modem is enabled, this will also
12651 * disable the cellular modem, and if the satellite modem is disabled, this will also re-enable
12652 * the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012653 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012654 * @param subId The subId to set satellite enabled for.
12655 * @param enable {@code true} to enable the satellite modem and {@code false} to disable.
12656 * @param callback The callback to get the error code of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012657 *
12658 * @throws SecurityException if the caller doesn't have the required permission.
12659 */
12660 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012661 public void setSatelliteEnabled(int subId, boolean enable, @NonNull IIntegerConsumer callback) {
12662 enforceSatelliteCommunicationPermission("setSatelliteEnabled");
12663 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012664 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012665 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12666 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012667 }
Sarah Chin503828c2023-02-01 23:54:20 -080012668
12669 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012670 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012671 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
12672 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012673 }
12674
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012675 Phone phone = getPhoneOrDefault(validSubId, "setSatelliteEnabled");
Sarah Chin503828c2023-02-01 23:54:20 -080012676 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012677 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
12678 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012679 }
12680
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012681 Pair<Boolean, Consumer<Integer>> arg = new Pair<>(enable, result);
12682 sendRequestAsync(CMD_SET_SATELLITE_ENABLED, arg, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080012683 }
12684
12685 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012686 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012687 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012688 * @param subId The subId to check whether satellite is enabled for.
12689 * @param result The result receiver that returns whether the satellite modem is enabled
12690 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012691 *
12692 * @throws SecurityException if the caller doesn't have the required permission.
12693 */
12694 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012695 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12696 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012697 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012698 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
12699 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012700 }
Sarah Chin503828c2023-02-01 23:54:20 -080012701
12702 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012703 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012704 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
12705 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012706 }
12707
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012708 Phone phone = getPhoneOrDefault(validSubId, "requestIsSatelliteEnabled");
Sarah Chin503828c2023-02-01 23:54:20 -080012709 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012710 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12711 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012712 }
12713
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012714 sendRequest(CMD_IS_SATELLITE_ENABLED, result, subId);
Sarah Chin503828c2023-02-01 23:54:20 -080012715 }
12716
12717 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012718 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012719 *
12720 * @param subId The subId to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012721 * @param result The result receiver that returns whether the satellite service is supported on
12722 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012723 */
12724 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012725 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012726 synchronized (mIsSatelliteSupportedLock) {
12727 if (mIsSatelliteSupported != null) {
12728 /* We have already successfully queried the satellite modem. */
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012729 Bundle bundle = new Bundle();
12730 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, mIsSatelliteSupported);
12731 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, bundle);
12732 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012733 }
12734 }
Sarah Chin503828c2023-02-01 23:54:20 -080012735
12736 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012737 Phone phone = getPhoneOrDefault(validSubId, "requestIsSatelliteSupported");
Sarah Chin503828c2023-02-01 23:54:20 -080012738 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012739 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12740 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012741 }
12742
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012743 sendRequestAsync(CMD_IS_SATELLITE_SUPPORTED, result, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080012744 }
12745
12746 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012747 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012748 *
12749 * @param subId The subId to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012750 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12751 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012752 *
12753 * @throws SecurityException if the caller doesn't have required permission.
12754 */
12755 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012756 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12757 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012758 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012759 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
12760 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012761 }
Sarah Chin503828c2023-02-01 23:54:20 -080012762
12763 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012764 Phone phone = getPhoneOrDefault(validSubId, "requestSatelliteCapabilities");
Sarah Chin503828c2023-02-01 23:54:20 -080012765 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012766 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12767 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012768 }
12769
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012770 sendRequestAsync(CMD_GET_SATELLITE_CAPABILITIES, result, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080012771 }
12772
12773 /**
Sarah Chineccfbd12023-01-20 19:00:35 -080012774 * Start receiving satellite position updates.
12775 * This can be called by the pointing UI when the user starts pointing to the satellite.
12776 * Modem should continue to report the pointing input as the device or satellite moves.
12777 *
12778 * @param subId The subId to start satellite position updates for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012779 * @param errorCallback The callback to get the error code of the request.
Sarah Chineccfbd12023-01-20 19:00:35 -080012780 * @param callback The callback to notify of changes in satellite position.
Sarah Chin503828c2023-02-01 23:54:20 -080012781 *
12782 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012783 */
12784 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012785 public void startSatellitePositionUpdates(int subId, @NonNull IIntegerConsumer errorCallback,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012786 @NonNull ISatelliteStateListener callback) {
Sarah Chinf75afa72023-02-01 01:32:19 -080012787 enforceSatelliteCommunicationPermission("startSatellitePositionUpdates");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012788 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012789 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012790 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12791 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012792 }
Sarah Chinf75afa72023-02-01 01:32:19 -080012793
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012794 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012795 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012796 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
12797 return;
Sarah Chinf75afa72023-02-01 01:32:19 -080012798 }
12799
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012800 Phone phone = getPhoneOrDefault(validSubId, "startSatellitePositionUpdates");
Sarah Chineccfbd12023-01-20 19:00:35 -080012801 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012802 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
12803 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012804 }
12805
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012806 if (mSatellitePositionUpdateHandlers.containsKey(callback.asBinder())) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012807 if (DBG) {
12808 log("startSatellitePositionUpdates: callback already registered: "
12809 + callback.asBinder());
12810 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012811 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
12812 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012813 }
12814
12815 SatellitePositionUpdateHandler handler =
12816 new SatellitePositionUpdateHandler(callback, Looper.getMainLooper());
12817 phone.registerForSatellitePointingInfoChanged(handler,
12818 SatellitePositionUpdateHandler.EVENT_POSITION_UPDATE, null);
12819 phone.registerForSatelliteMessagesTransferComplete(handler,
12820 SatellitePositionUpdateHandler.EVENT_MESSAGE_TRANSFER_STATE_UPDATE, null);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012821 mSatellitePositionUpdateHandlers.put(callback.asBinder(), handler);
Sarah Chineccfbd12023-01-20 19:00:35 -080012822
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012823 sendRequestAsync(CMD_START_SATELLITE_POSITION_UPDATES, result, phone, null);
Sarah Chineccfbd12023-01-20 19:00:35 -080012824 }
12825
12826 /**
12827 * Stop receiving satellite position updates.
12828 * This can be called by the pointing UI when the user stops pointing to the satellite.
12829 *
12830 * @param subId The subId to stop satellite position updates for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012831 * @param errorCallback The callback to get the error code of the request.
12832 * @param callback The callback that was passed to {@link
12833 * #startSatellitePositionUpdates(int, IIntegerConsumer, ISatelliteStateListener)}
Sarah Chin503828c2023-02-01 23:54:20 -080012834 *
12835 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012836 */
12837 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012838 public void stopSatellitePositionUpdates(int subId, @NonNull IIntegerConsumer errorCallback,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012839 @NonNull ISatelliteStateListener callback) {
Sarah Chinf75afa72023-02-01 01:32:19 -080012840 enforceSatelliteCommunicationPermission("stopSatellitePositionUpdates");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012841 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012842 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012843 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12844 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012845 }
Sarah Chinf75afa72023-02-01 01:32:19 -080012846
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012847 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012848 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012849 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
12850 return;
Sarah Chinf75afa72023-02-01 01:32:19 -080012851 }
12852
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012853 Phone phone = getPhoneOrDefault(validSubId, "stopSatellitePositionUpdates");
Sarah Chineccfbd12023-01-20 19:00:35 -080012854 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012855 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
12856 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012857 }
12858
12859 SatellitePositionUpdateHandler handler =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012860 mSatellitePositionUpdateHandlers.remove(callback.asBinder());
Sarah Chineccfbd12023-01-20 19:00:35 -080012861 if (handler == null) {
12862 loge("stopSatellitePositionUpdates: No SatellitePositionArgument");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012863 result.accept(SatelliteManager.SATELLITE_INVALID_ARGUMENTS);
12864 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012865 } else {
12866 phone.unregisterForSatellitePointingInfoChanged(handler);
12867 phone.unregisterForSatelliteMessagesTransferComplete(handler);
12868 }
12869
12870 if (!mSatellitePositionUpdateHandlers.isEmpty()) {
12871 log("stopSatellitePositionUpdates: other listeners still exist.");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012872 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
12873 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012874 }
12875
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012876 sendRequestAsync(CMD_STOP_SATELLITE_POSITION_UPDATES, result, phone, null);
Sarah Chineccfbd12023-01-20 19:00:35 -080012877 }
12878
12879 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012880 * Request to get the maximum number of characters per text message on satellite.
12881 *
12882 * @param subId The subId of the subscription.
12883 * @param result The result receiver that returns the maximum number of characters per text
12884 * message on satellite if the request is successful or an error code
12885 * if the request failed.
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012886 *
12887 * @throws SecurityException if the caller doesn't have the required permission.
12888 */
12889 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012890 public void requestMaxCharactersPerSatelliteTextMessage(int subId,
12891 @NonNull ResultReceiver result) {
12892 enforceSatelliteCommunicationPermission("requestMaxCharactersPerSatelliteTextMessage");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012893 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012894 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
12895 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012896 }
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012897
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012898 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012899 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012900 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
12901 return;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012902 }
12903
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012904 Phone phone = getPhoneOrDefault(validSubId, "requestMaxCharactersPerSatelliteTextMessage");
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012905 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012906 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12907 return;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012908 }
12909
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012910 sendRequestAsync(CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG, result, phone, null);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012911 }
12912
12913 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012914 * Register the subscription with a satellite provider.
12915 * This is needed to register the subscription if the provider allows dynamic registration.
12916 *
12917 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012918 * @param token The token to be used as a unique identifier for provisioning with satellite
12919 * gateway.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012920 * @param callback The callback to get the error code of the request.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012921 * @return The signal transport used by the caller to cancel the provision request,
12922 * or {@code null} if the request failed.
12923 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012924 * @throws SecurityException if the caller doesn't have the required permission.
12925 */
12926 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012927 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
12928 @NonNull String token, @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012929 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012930 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012931 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012932 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012933 return null;
12934 }
12935
12936 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012937 Phone phone = getPhoneOrDefault(validSubId, "provisionSatelliteService");
12938 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012939 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012940 return null;
12941 }
12942
12943 if (mSatelliteProvisionCallbacks.containsKey(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012944 result.accept(SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012945 return null;
12946 }
12947
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012948 if (isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012949 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012950 return null;
12951 }
12952
12953 sendRequestAsync(CMD_PROVISION_SATELLITE_SERVICE,
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012954 new ProvisionSatelliteServiceArgument(token, result, validSubId), phone, null);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012955
12956 ICancellationSignal cancelTransport = CancellationSignal.createTransport();
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012957 CancellationSignal.fromTransport(cancelTransport).setOnCancelListener(() -> {
12958 sendRequestAsync(CMD_DEPROVISION_SATELLITE_SERVICE,
12959 new ProvisionSatelliteServiceArgument(token, null, validSubId),
12960 phone, null);
12961 });
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012962 return cancelTransport;
12963 }
12964
12965 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012966 * Unregister the device/subscription with the satellite provider.
12967 * This is needed if the provider allows dynamic registration. Once deprovisioned,
12968 * {@link SatelliteCallback.SatelliteProvisionStateListener#onSatelliteProvisionStateChanged}
12969 * should report as deprovisioned.
12970 *
12971 * @param subId The subId of the subscription to be deprovisioned.
12972 * @param token The token of the device/subscription to be deprovisioned.
12973 * @param callback The callback to get the error code of the request.
12974 *
12975 * @throws SecurityException if the caller doesn't have the required permission.
12976 */
12977 @Override
12978 public void deprovisionSatelliteService(int subId,
12979 @NonNull String token, @NonNull IIntegerConsumer callback) {
12980 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
12981 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
12982 if (!isSatelliteSupported()) {
12983 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12984 return;
12985 }
12986
12987 final int validSubId = getValidSatelliteSubId(subId);
12988 if (!isSatelliteProvisioned(validSubId)) {
12989 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
12990 return;
12991 }
12992
12993 Phone phone = getPhoneOrDefault(validSubId, "deprovisionSatelliteService");
12994 if (phone == null) {
12995 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
12996 return;
12997 }
12998
12999 sendRequestAsync(CMD_DEPROVISION_SATELLITE_SERVICE,
13000 new ProvisionSatelliteServiceArgument(token, result, validSubId), phone, null);
13001 }
13002
13003 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013004 * Register for the satellite provision state change.
13005 *
13006 * @param subId The subId of the subscription associated with the satellite service.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013007 * @param errorCallback The callback to get the error code of the request.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013008 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013009 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013010 * @throws SecurityException if the caller doesn't have the required permission.
13011 */
13012 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013013 public void registerForSatelliteProvisionStateChanged(int subId,
13014 @NonNull IIntegerConsumer errorCallback, @NonNull ISatelliteStateListener callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013015 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013016 registerForSatelliteProvisionStateChangedInternal(subId, errorCallback, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013017 }
13018
13019 /**
13020 * Unregister for the satellite provision state change.
13021 *
13022 * @param subId The subId of the subscription associated with the satellite service.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013023 * @param errorCallback The callback to get the error code of the request.
13024 * @param callback The callback that was passed to {@link
13025 * #registerForSatelliteProvisionStateChanged(int, IIntegerConsumer, ISatelliteStateListener)}.
13026 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013027 * @throws SecurityException if the caller doesn't have the required permission.
13028 */
13029 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013030 public void unregisterForSatelliteProvisionStateChanged(int subId,
13031 @NonNull IIntegerConsumer errorCallback, @NonNull ISatelliteStateListener callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013032 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013033 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013034 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013035 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
13036 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013037 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013038
13039 final int validSubId = getValidSatelliteSubId(subId);
13040 SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler =
13041 mSatelliteProvisionStateChangedHandlers.get(validSubId);
13042 if (satelliteProvisionStateChangedHandler != null) {
13043 if (satelliteProvisionStateChangedHandler.removeListener(callback)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013044 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
13045 return;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013046 }
13047 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013048 result.accept(SatelliteManager.SATELLITE_INVALID_ARGUMENTS);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013049 }
13050
13051 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013052 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013053 *
13054 * @param subId The subId of the subscription associated with the satellite service.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013055 * @param result The result receiver that returns whether the device is provisioned with a
13056 * satellite provider if the request is successful or an error code if the
13057 * request failed.
13058 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013059 * @throws SecurityException if the caller doesn't have the required permission.
13060 */
13061 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013062 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13063 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013064 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013065 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
13066 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013067 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013068
13069 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013070 Bundle bundle = new Bundle();
13071 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_PROVISIONED,
13072 isSatelliteProvisioned(validSubId));
13073 result.send(SatelliteManager.SATELLITE_ERROR_NONE, bundle);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013074 }
13075
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013076 /**
13077 * Register for listening to satellite state changes.
13078 *
13079 * @param subId - The subId to start listening to satellite state changes for.
13080 * @param callback - The callback to handle the satellite state change event.
13081 * @return The result of the operation.
13082 * @throws SecurityException if the caller doesn't have the required permission.
13083 */
13084 @Override
13085 @SatelliteManager.SatelliteError
13086 public int registerForSatelliteModemStateChange(int subId,
13087 @NonNull ISatelliteStateListener callback) {
13088 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChange");
13089
13090 final int validSubId = getValidSatelliteSubId(subId);
13091 Phone phone = getPhoneOrDefault(
13092 validSubId, "registerForSatelliteModemStateChange");
13093 if (phone == null) {
13094 return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
13095 }
13096
13097 SatelliteStateListenerHandler satelliteStateListenerHandler =
13098 mSatelliteStateListenerHandlers.get(validSubId);
13099 if (satelliteStateListenerHandler == null) {
13100 satelliteStateListenerHandler = new SatelliteStateListenerHandler(
13101 Looper.getMainLooper(), validSubId);
13102 phone.registerForSatelliteModemStateChange(satelliteStateListenerHandler,
13103 SatelliteStateListenerHandler.EVENT_SATELLITE_MODEM_STATE_CHANGE, null);
13104 phone.registerForPendingMessageCount(satelliteStateListenerHandler,
13105 SatelliteStateListenerHandler.EVENT_PENDING_MESSAGE_COUNT, null);
13106 }
13107
13108 satelliteStateListenerHandler.addListener(callback);
13109 mSatelliteStateListenerHandlers.put(validSubId, satelliteStateListenerHandler);
13110 return SatelliteManager.SATELLITE_ERROR_NONE;
13111 }
13112
13113 /**
13114 * Unregister from listening to satellite state changes.
13115 *
13116 * @param subId - The subId to stop listening to satellite state changes for.
13117 * @param callback - The callback that was passed to
13118 * {@link #registerForSatelliteModemStateChange(int, ISatelliteStateListener)}
13119 * @return The result of the operation.
13120 *
13121 * @throws SecurityException if the caller doesn't have the required permission.
13122 */
13123 @Override
13124 @SatelliteManager.SatelliteError
13125 public int unregisterForSatelliteModemStateChange(int subId,
13126 @NonNull ISatelliteStateListener callback) {
13127 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChange");
13128
13129 final int validSubId = getValidSatelliteSubId(subId);
13130 SatelliteStateListenerHandler satelliteStateListenerHandler =
13131 mSatelliteStateListenerHandlers.get(validSubId);
13132 if (satelliteStateListenerHandler != null) {
13133 if (satelliteStateListenerHandler.removeListener(callback)) {
13134 return SatelliteManager.SATELLITE_ERROR_NONE;
13135 }
13136 }
13137 return SatelliteManager.SATELLITE_INVALID_ARGUMENTS;
13138 }
13139
13140 /**
13141 * Register to receive incoming datagrams over satellite.
13142 *
13143 * @param subId - The subId to start receiving datagrams over satellite.
13144 * @param datagramType - type of datagram
13145 * @param callback - The callback to handle incoming datagrams over satellite.
13146 * @return The result of the operation.
13147 * @throws SecurityException if the caller doesn't have the required permission.
13148 */
13149 @Override
13150 @SatelliteManager.SatelliteError
13151 public int registerForSatelliteDatagram(int subId,
13152 @SatelliteManager.DatagramType int datagramType,
13153 @NonNull ISatelliteStateListener callback) {
13154 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
13155
13156 final int validSubId = getValidSatelliteSubId(subId);
13157 Phone phone = getPhoneOrDefault(
13158 validSubId, "registerForSatelliteDatagram");
13159 if (phone == null) {
13160 return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
13161 }
13162
13163 SatelliteDatagramListenerHandler satelliteDatagramListenerHandler =
13164 mSatelliteDatagramListenerHandlers.get(validSubId);
13165 if (satelliteDatagramListenerHandler == null) {
13166 satelliteDatagramListenerHandler = new SatelliteDatagramListenerHandler(
13167 Looper.getMainLooper(), validSubId);
13168 phone.registerForNewSatelliteDatagram(satelliteDatagramListenerHandler,
13169 SatelliteDatagramListenerHandler.EVENT_SATELLITE_DATAGRAMS_RECEIVED, null);
13170 }
13171
13172 satelliteDatagramListenerHandler.addListener(callback);
13173 mSatelliteDatagramListenerHandlers.put(validSubId, satelliteDatagramListenerHandler);
13174 return SatelliteManager.SATELLITE_ERROR_NONE;
13175 }
13176
13177 /**
13178 * Unregister to stop receiving incoming datagrams over satellite.
13179 *
13180 * @param subId - The subId to stop listening incoming datagrams over satellite.
13181 * @param callback - The callback that was passed to
13182 * {@link #registerForSatelliteDatagram(int, int, ISatelliteStateListener)}
13183 * @return The result of the operation.
13184 *
13185 * @throws SecurityException if the caller doesn't have the required permission.
13186 */
13187 @Override
13188 @SatelliteManager.SatelliteError
13189 public int unregisterForSatelliteDatagram(int subId,
13190 @NonNull ISatelliteStateListener callback) {
13191 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
13192
13193 final int validSubId = getValidSatelliteSubId(subId);
13194 SatelliteDatagramListenerHandler satelliteDatagramListenerHandler =
13195 mSatelliteDatagramListenerHandlers.get(validSubId);
13196 if (satelliteDatagramListenerHandler != null) {
13197 if (satelliteDatagramListenerHandler.removeListener(callback)) {
13198 return SatelliteManager.SATELLITE_ERROR_NONE;
13199 }
13200 }
13201 return SatelliteManager.SATELLITE_INVALID_ARGUMENTS;
13202 }
13203
13204
13205 /**
13206 * Poll pending satellite datagrams over satellite.
13207 * @param subId - The subId of the subscription used for receiving datagrams.
13208 * @return The result of the operation.
13209 * @throws SecurityException if the caller doesn't have the required permission.
13210 */
13211 @Override
13212 @SatelliteManager.SatelliteError
13213 public int pollPendingSatelliteDatagrams(int subId) {
13214 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
13215
13216 final int validSubId = getValidSatelliteSubId(subId);
13217 if (!isSatelliteProvisioned(validSubId)) {
13218 return SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED;
13219 }
13220
13221 Phone phone = getPhoneOrDefault(validSubId, "pollPendingSatelliteDatagrams");
13222 if (phone == null) {
13223 return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
13224 }
13225
13226 int result = (int) sendRequest(CMD_POLL_PENDING_SATELLITE_DATAGRAMS, null, validSubId);
13227 if (DBG) log("pollPendingSatelliteDatagrams result: " + result);
13228 return result;
13229 }
13230
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013231 private void handleCmdProvisionSatelliteService(@NonNull ProvisionSatelliteServiceArgument arg,
13232 @NonNull Phone phone, Message onCompleted) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013233 if (!mSatelliteProvisionCallbacks.containsKey(arg.subId)) {
13234 mSatelliteProvisionCallbacks.put(arg.subId, arg.callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013235 phone.provisionSatelliteService(onCompleted, arg.token);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013236 } else {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013237 arg.callback.accept(SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013238 }
13239 }
13240
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013241 private void handleEventProvisionSatelliteServiceDone(
13242 @NonNull ProvisionSatelliteServiceArgument arg,
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013243 @SatelliteManager.SatelliteError int result) {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013244 log("handleEventProvisionSatelliteServiceDone: result="
13245 + result + ", subId=" + arg.subId);
13246
13247 Consumer<Integer> callback = mSatelliteProvisionCallbacks.remove(arg.subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013248 if (callback == null) {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013249 loge("handleEventProvisionSatelliteServiceDone: callback is null for subId="
13250 + arg.subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013251 return;
13252 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013253 callback.accept(result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013254
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013255 if (result == SatelliteManager.SATELLITE_ERROR_NONE) {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013256 setSatelliteProvisioned(arg.subId, true);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013257 }
13258
13259 /**
13260 * We need to update satellite provision status in SubscriptionController
13261 * or SatelliteController.
13262 * TODO (b/267826133) we need to do this for all subscriptions on the device.
13263 */
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013264 registerForSatelliteProvisionStateChangedInternal(arg.subId, null, null);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013265 }
13266
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013267 private void handleCmdDeprovisionSatelliteService(
13268 @NonNull ProvisionSatelliteServiceArgument arg,
13269 @NonNull Phone phone, Message onCompleted) {
13270 if (arg == null) {
13271 loge("handleCmdDeprovisionSatelliteService: arg is null");
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013272 return;
13273 }
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013274 if (phone == null) {
13275 loge("handleCmdDeprovisionSatelliteService: phone is null");
13276 if (arg.callback != null) {
13277 arg.callback.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
13278 }
13279 return;
13280 }
13281 phone.deprovisionSatelliteService(onCompleted, arg.token);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013282 }
13283
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013284 private void handleEventDeprovisionSatelliteServiceDone(
13285 @NonNull ProvisionSatelliteServiceArgument arg,
13286 @SatelliteManager.SatelliteError int result) {
13287 if (arg == null) {
13288 loge("handleEventDeprovisionSatelliteServiceDone: arg is null");
13289 return;
13290 }
13291 log("handleEventDeprovisionSatelliteServiceDone: result="
13292 + result + ", subId=" + arg.subId);
13293
13294 if (arg.callback != null) {
13295 arg.callback.accept(result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013296 }
13297
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013298 if (result == SatelliteManager.SATELLITE_ERROR_NONE) {
13299 setSatelliteProvisioned(arg.subId, false);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013300 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013301 }
13302
13303 private Phone getPhoneOrDefault(int subId, String caller) {
13304 Phone phone = getPhone(subId);
13305 if (phone == null) {
13306 loge(caller + " called with invalid subId: " + subId
13307 + ". Retrying with default phone.");
13308 phone = getDefaultPhone();
13309 if (phone == null) {
13310 loge(caller + " failed with no phone object.");
13311 }
13312 }
13313 return phone;
13314 }
13315
13316 /**
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013317 * Check if satellite is provisioned for a subscription or the device.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013318 *
13319 * Note: this is the version without permission check for telephony internal use only. The
13320 * caller need to take care of the permission check.
13321 */
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013322 private boolean isSatelliteProvisioned(int subId) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013323 if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
13324 if (mSubscriptionController == null) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013325 loge("isSatelliteProvisioned mSubscriptionController is null");
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013326 return false;
13327 }
13328
13329 String strResult = mSubscriptionController.getSubscriptionProperty(
13330 subId, SubscriptionManager.SATELLITE_ENABLED);
13331 if (strResult != null) {
13332 int intResult = Integer.parseInt(strResult);
13333 return (intResult == 1) ? true : false;
13334 }
13335 } else {
13336 //TODO (b/267826133): check via SatelliteController
13337 }
13338 return false;
13339 }
13340
13341 /**
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013342 * Set satellite provisioned for a subscription or the device.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013343 *
13344 * The permission {@link android.Manifest.permission#MODIFY_PHONE_STATE} will be enforced by
13345 * {@link SubscriptionController} when setting satellite enabled for an active subscription.
13346 * Otherwise, {@link android.Manifest.permission#SATELLITE_COMMUNICATION} will be enforced.
13347 */
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013348 private synchronized void setSatelliteProvisioned(int subId, boolean isEnabled) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013349 if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
13350 if (mSubscriptionController == null) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013351 loge("setSatelliteProvisioned mSubscriptionController is null");
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013352 return;
13353 }
13354 mSubscriptionController.setSubscriptionProperty(
13355 subId, SubscriptionManager.SATELLITE_ENABLED, isEnabled ? "1" : "0");
13356 } else {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013357 //TODO (b/267826133): set via SatelliteController
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013358 }
13359 }
13360
13361 private int getValidSatelliteSubId(int subId) {
13362 if (mSubscriptionController == null) {
13363 loge("getValidSatelliteSubId mSubscriptionController is null. "
13364 + "Use DEFAULT_SUBSCRIPTION_ID for subId=" + subId);
13365 return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
13366 }
13367 final long identity = Binder.clearCallingIdentity();
13368 try {
13369 Context context = getDefaultPhone().getContext();
13370 if (mSubscriptionController.isActiveSubId(
13371 subId, context.getOpPackageName(), context.getAttributionTag())) {
13372 return subId;
13373 }
13374 } finally {
13375 Binder.restoreCallingIdentity(identity);
13376 }
13377 if (DBG) log("getValidSatelliteSubId: use DEFAULT_SUBSCRIPTION_ID for subId=" + subId);
13378 return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
13379 }
13380
13381 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013382 * If we have not successfully queried the satellite modem for its satellite service support,
13383 * we will retry the query one more time. Otherwise, we will return the queried result.
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013384 */
13385 private boolean isSatelliteSupported() {
13386 synchronized (mIsSatelliteSupportedLock) {
13387 if (mIsSatelliteSupported != null) {
13388 /* We have already successfully queried the satellite modem. */
13389 return mIsSatelliteSupported;
13390 }
13391 }
13392 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013393 * We have not successfully checked whether the modem supports satellite service.
13394 * Thus, we need to retry it now.
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013395 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013396 requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
13397 mSatelliteSupportedReceiver);
13398 return false;
13399 }
13400
13401 /**
13402 * Get the {@link SatelliteManager.SatelliteError} from the provided result.
13403 * @param ar AsyncResult used to determine the error code.
13404 * @param caller The satellite request.
13405 * @param checkResult Whether to check if the result exists.
13406 * @return The {@link SatelliteManager.SatelliteError} error code from the request.
13407 */
13408 @SatelliteManager.SatelliteError private int getSatelliteError(@NonNull AsyncResult ar,
13409 @NonNull String caller, boolean checkResult) {
13410 int errorCode;
13411 if (ar.exception == null) {
13412 errorCode = SatelliteManager.SATELLITE_ERROR_NONE;
13413 if (checkResult && ar.result == null) {
13414 loge(caller + ": result is null");
13415 errorCode = SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
13416 }
13417 } else {
13418 errorCode = SatelliteManager.SATELLITE_ERROR;
13419 if (ar.exception instanceof CommandException) {
13420 CommandException.Error error =
13421 ((CommandException) (ar.exception)).getCommandError();
13422 errorCode = RILUtils.convertToSatelliteError(error);
13423 loge(caller + " CommandException: " + ar.exception);
13424 } else {
13425 loge(caller + " unknown exception: " + ar.exception);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013426 }
13427 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013428 log(caller + " error: " + errorCode);
13429 return errorCode;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013430 }
13431
13432 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013433 * Register for the satellite provision state change.
13434 *
13435 * @param subId The subId of the subscription associated with the satellite service.
13436 * @param errorCallback The callback to get the error code of the request.
13437 * @param callback The callback to handle the satellite provision state changed event.
13438 */
13439 private void registerForSatelliteProvisionStateChangedInternal(int subId,
13440 @Nullable IIntegerConsumer errorCallback, @Nullable ISatelliteStateListener callback) {
13441 Consumer<Integer> result = null;
13442 if (errorCallback != null) {
13443 result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
13444 }
13445 if (!isSatelliteSupported()) {
13446 if (result != null) {
13447 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
13448 }
13449 return;
13450 }
13451
13452 final int validSubId = getValidSatelliteSubId(subId);
13453 Phone phone = getPhoneOrDefault(validSubId, "registerForSatelliteProvisionStateChanged");
13454 if (phone == null) {
13455 if (result != null) {
13456 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
13457 }
13458 return;
13459 }
13460
13461 SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler =
13462 mSatelliteProvisionStateChangedHandlers.get(validSubId);
13463 if (satelliteProvisionStateChangedHandler == null) {
13464 satelliteProvisionStateChangedHandler = new SatelliteProvisionStateChangedHandler(
13465 Looper.getMainLooper(), validSubId);
13466 phone.registerForSatelliteProvisionStateChanged(satelliteProvisionStateChangedHandler,
13467 SatelliteProvisionStateChangedHandler.EVENT_PROVISION_STATE_CHANGED, null);
13468 }
13469
13470 if (callback != null) {
13471 satelliteProvisionStateChangedHandler.addListener(callback);
13472 }
13473 mSatelliteProvisionStateChangedHandlers.put(
13474 validSubId, satelliteProvisionStateChangedHandler);
13475 if (result != null) {
13476 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
13477 }
13478 }
13479
13480 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000013481 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
13482 *
13483 * <p>This method behaves in one of the following ways:
13484 * <ul>
13485 * <li>return true : if the calling package has the appop permission {@link
13486 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
13487 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
13488 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
13489 * Owner device identifier access check, or the calling package has carrier privileges</>
13490 * <li>throw SecurityException: if the caller does not meet any of the requirements.
13491 * </ul>
13492 */
13493 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
13494 String callingPackage, @Nullable String callingFeatureId, String message) {
13495 for (Phone phone : PhoneFactory.getPhones()) {
13496 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
13497 phone.getSubId(), callingPackage, callingFeatureId, message)) {
13498 return true;
13499 }
13500 }
13501 return false;
13502 }
arunvoddud7401012022-12-15 16:08:12 +000013503
13504 /**
Jack Yufa8ed012023-02-11 15:42:28 -080013505 * @return The subscription manager service instance.
13506 */
13507 public SubscriptionManagerService getSubscriptionManagerService() {
13508 return SubscriptionManagerService.getInstance();
13509 }
13510
13511 /**
arunvoddud7401012022-12-15 16:08:12 +000013512 * Class binds the consumer[callback] and carrierId.
13513 */
13514 private static class CallerCallbackInfo {
13515 private final Consumer<Integer> mConsumer;
13516 private final int mCarrierId;
13517
13518 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
13519 mConsumer = consumer;
13520 mCarrierId = carrierId;
13521 }
13522
13523 public Consumer<Integer> getConsumer() {
13524 return mConsumer;
13525 }
13526
13527 public int getCarrierId() {
13528 return mCarrierId;
13529 }
13530 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013531
13532 private static SatelliteDatagram[] convertToSatelliteDatagramArray(byte[][] datagrams) {
13533 // Convert 2D byte array into SatelliteDatagramArray.
13534 SatelliteDatagram[] satelliteDatagramArray =
13535 new SatelliteDatagram[datagrams.length];
13536 for (int i = 0; i < datagrams.length; i++) {
13537 satelliteDatagramArray[i] = new SatelliteDatagram(datagrams[i]);
13538 }
13539 return satelliteDatagramArray;
13540 }
Jack Yufa8ed012023-02-11 15:42:28 -080013541}