blob: 44df7a009ed65a47216b7ca91d78a33521c17f86 [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;
396 private static final int CMD_CANCEL_PROVISION_SATELLITE_SERVICE = 127;
397 private static final int EVENT_CANCEL_PROVISION_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;
644 int[] features = (int[]) ar.result;
645 log("Received EVENT_PROVISION_STATE_CHANGED for subId=" + mSubId
646 + ", features=" + Arrays.toString(features)
647 + ", provisioned=" + provisioned);
648 mListeners.values().forEach(listener -> {
649 try {
650 listener.onSatelliteProvisionStateChanged(features, provisioned);
651 } catch (RemoteException e) {
652 log("EVENT_PROVISION_STATE_CHANGED RemoteException: " + e);
653 }
654 });
655
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800656 setSatelliteProvisioned(provisioned);
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800657 /**
658 * TODO: Take bugreport if provisioned is true and user did not initiate the
659 * provision procedure for the corresponding subscription.
660 */
661 break;
662 }
663 default:
664 loge("SatelliteProvisionStateChangedHandler unknown event: " + msg.what);
665 }
666 }
667
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800668 private void setSatelliteProvisioned(boolean isProvisioned) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800669 if (mSubId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
670 SubscriptionManager.setSubscriptionProperty(
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800671 mSubId, SubscriptionManager.SATELLITE_ENABLED, isProvisioned ? "1" : "0");
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800672 } else {
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800673 //TODO (b/267826133): set via SatelliteController.
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800674 }
675 }
676 }
677
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000678 private static final class SatelliteStateListenerHandler extends Handler {
679 public static final int EVENT_SATELLITE_MODEM_STATE_CHANGE = 1;
680 public static final int EVENT_PENDING_MESSAGE_COUNT = 2;
681
682 private ConcurrentHashMap<IBinder, ISatelliteStateListener> mListeners;
683 private final int mSubId;
684
685 SatelliteStateListenerHandler(Looper looper, int subId) {
686 super(looper);
687 mSubId = subId;
688 mListeners = new ConcurrentHashMap<>();
689 }
690
691 public void addListener(ISatelliteStateListener listener) {
692 mListeners.put(listener.asBinder(), listener);
693 }
694
695 public boolean removeListener(ISatelliteStateListener listener) {
696 return (mListeners.remove(listener.asBinder()) != null);
697 }
698
699 @Override
700 public void handleMessage(@NonNull Message msg) {
701 switch (msg.what) {
702 case EVENT_SATELLITE_MODEM_STATE_CHANGE : {
703 AsyncResult ar = (AsyncResult) msg.obj;
704 int state = (int) ar.result;
705 log("Received EVENT_SATELLITE_MODEM_STATE_CHANGE for subId=" + mSubId
706 + ", state=" + state);
707 mListeners.values().forEach(listener -> {
708 try {
709 listener.onSatelliteModemStateChange(state);
710 } catch (RemoteException e) {
711 log("EVENT_SATELLITE_MODEM_STATE_CHANGE RemoteException: " + e);
712 }
713 });
714 break;
715 }
716 case EVENT_PENDING_MESSAGE_COUNT: {
717 AsyncResult ar = (AsyncResult) msg.obj;
718 int count = (int) ar.result;
719 log("Received EVENT_PENDING_MESSAGE_COUNT for subId=" + mSubId
720 + ", count=" + count);
721 mListeners.values().forEach(listener -> {
722 try {
723 listener.onPendingMessageCount(count);
724 } catch (RemoteException e) {
725 log("EVENT_PENDING_MESSAGE_COUNT RemoteException: " + e);
726 }
727 });
728 break;
729 }
730 default:
731 loge("SatelliteStateListenerHandler unknown event: " + msg.what);
732 }
733 }
734 }
735
736 private static final class SatelliteDatagramListenerHandler extends Handler {
737 public static final int EVENT_SATELLITE_DATAGRAMS_RECEIVED = 1;
738
739 private ConcurrentHashMap<IBinder, ISatelliteStateListener> mListeners;
740 private final int mSubId;
741
742 SatelliteDatagramListenerHandler(Looper looper, int subId) {
743 super(looper);
744 mSubId = subId;
745 mListeners = new ConcurrentHashMap<>();
746 }
747
748 public void addListener(ISatelliteStateListener listener) {
749 mListeners.put(listener.asBinder(), listener);
750 }
751
752 public boolean removeListener(ISatelliteStateListener listener) {
753 return (mListeners.remove(listener.asBinder()) != null);
754 }
755
756 @Override
757 public void handleMessage(@NonNull Message msg) {
758 switch (msg.what) {
759 case EVENT_SATELLITE_DATAGRAMS_RECEIVED : {
760 AsyncResult ar = (AsyncResult) msg.obj;
761 byte[][] datagrams = (byte[][]) ar.result;
762 SatelliteDatagram[] satelliteDatagramArray =
763 convertToSatelliteDatagramArray(datagrams);
764
765 log("Received EVENT_SATELLITE_DATAGRAMS_RECEIVED for subId=" + mSubId);
766 mListeners.values().forEach(listener -> {
767 try {
768 listener.onSatelliteDatagrams(satelliteDatagramArray);
769 } catch (RemoteException e) {
770 log("EVENT_SATELLITE_DATAGRAMS_RECEIVED RemoteException: " + e);
771 }
772 });
773 break;
774 }
775 default:
776 loge("SatelliteDatagramListenerHandler unknown event: " + msg.what);
777 }
778 }
779 }
780
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700781 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700782 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
783 * request after sending. The main thread will notify the request when it is complete.
784 */
785 private static final class MainThreadRequest {
786 /** The argument to use for the request */
787 public Object argument;
788 /** The result of the request that is run on the main thread */
789 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800790 // The subscriber id that this request applies to. Defaults to
791 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
792 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700793
Nathan Harold92bed182018-10-12 18:16:49 -0700794 // In cases where subId is unavailable, the caller needs to specify the phone.
795 public Phone phone;
796
vagdeviaf9a5b92018-08-15 16:01:53 -0700797 public WorkSource workSource;
798
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700799 public MainThreadRequest(Object argument) {
800 this.argument = argument;
801 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800802
Nathan Harold92bed182018-10-12 18:16:49 -0700803 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
804 this.argument = argument;
805 if (phone != null) {
806 this.phone = phone;
807 }
808 this.workSource = workSource;
809 }
810
vagdeviaf9a5b92018-08-15 16:01:53 -0700811 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800812 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800813 if (subId != null) {
814 this.subId = subId;
815 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700816 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800817 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700818 }
819
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800820 private static final class IncomingThirdPartyCallArgs {
821 public final ComponentName component;
822 public final String callId;
823 public final String callerDisplayName;
824
825 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
826 String callerDisplayName) {
827 this.component = component;
828 this.callId = callId;
829 this.callerDisplayName = callerDisplayName;
830 }
831 }
832
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700833 /**
834 * A handler that processes messages on the main thread in the phone process. Since many
835 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
836 * inbound binder threads to the main thread in the phone process. The Binder thread
837 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
838 * on, which will be notified when the operation completes and will contain the result of the
839 * request.
840 *
841 * <p>If a MainThreadRequest object is provided in the msg.obj field,
842 * note that request.result must be set to something non-null for the calling thread to
843 * unblock.
844 */
845 private final class MainThreadHandler extends Handler {
846 @Override
847 public void handleMessage(Message msg) {
848 MainThreadRequest request;
849 Message onCompleted;
850 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000851 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700852 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800853 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700854
855 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700856 case CMD_HANDLE_USSD_REQUEST: {
857 request = (MainThreadRequest) msg.obj;
858 final Phone phone = getPhoneFromRequest(request);
859 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800860 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700861 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700862
Pengquan Menga1bb6272018-09-06 09:59:22 -0700863 if (!isUssdApiAllowed(request.subId)) {
864 // Carrier does not support use of this API, return failure.
865 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
866 UssdResponse response = new UssdResponse(ussdRequest, null);
867 Bundle returnData = new Bundle();
868 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
869 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700870
Pengquan Menga1bb6272018-09-06 09:59:22 -0700871 request.result = true;
872 notifyRequester(request);
873 return;
874 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700875
Pengquan Menga1bb6272018-09-06 09:59:22 -0700876 try {
877 request.result = phone != null
878 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
879 } catch (CallStateException cse) {
880 request.result = false;
881 }
882 // Wake up the requesting thread
883 notifyRequester(request);
884 break;
pkanwar32d516d2016-10-14 19:37:38 -0700885 }
886
Yorke Lee716f67e2015-06-17 15:39:16 -0700887 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700888 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700889 final Phone phone = getPhoneFromRequest(request);
890 request.result = phone != null ?
891 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
892 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700893 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700894 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700895 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700896 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700897
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700898 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700899 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700900 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000901 uiccPort = getUiccPortFromRequest(request);
902 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700903 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800904 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700905 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700906 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700907 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800908 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000909 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800910 iccArgument.channel, iccArgument.cla, iccArgument.command,
911 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
912 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700913 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700914 break;
915
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700916 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700917 ar = (AsyncResult) msg.obj;
918 request = (MainThreadRequest) ar.userObj;
919 if (ar.exception == null && ar.result != null) {
920 request.result = ar.result;
921 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800922 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700923 if (ar.result == null) {
924 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800925 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700926 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800927 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700928 } else {
929 loge("iccTransmitApduLogicalChannel: Unknown exception");
930 }
931 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700932 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700933 break;
934
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700935 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
936 request = (MainThreadRequest) msg.obj;
937 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000938 uiccPort = getUiccPortFromRequest(request);
939 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700940 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800941 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700942 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700943 } else {
944 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800945 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000946 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800947 iccArgument.cla, iccArgument.command, iccArgument.p1,
948 iccArgument.p2,
949 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700950 }
951 break;
952
953 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
954 ar = (AsyncResult) msg.obj;
955 request = (MainThreadRequest) ar.userObj;
956 if (ar.exception == null && ar.result != null) {
957 request.result = ar.result;
958 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800959 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700960 if (ar.result == null) {
961 loge("iccTransmitApduBasicChannel: Empty response");
962 } else if (ar.exception instanceof CommandException) {
963 loge("iccTransmitApduBasicChannel: CommandException: " +
964 ar.exception);
965 } else {
966 loge("iccTransmitApduBasicChannel: Unknown exception");
967 }
968 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700969 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700970 break;
971
972 case CMD_EXCHANGE_SIM_IO:
973 request = (MainThreadRequest) msg.obj;
974 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000975 uiccPort = getUiccPortFromRequest(request);
976 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700977 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800978 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700979 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700980 } else {
981 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
982 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000983 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700984 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
985 iccArgument.data, onCompleted);
986 }
987 break;
988
989 case EVENT_EXCHANGE_SIM_IO_DONE:
990 ar = (AsyncResult) msg.obj;
991 request = (MainThreadRequest) ar.userObj;
992 if (ar.exception == null && ar.result != null) {
993 request.result = ar.result;
994 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800995 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700996 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700997 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700998 break;
999
Derek Tan4d5e5c12014-02-04 11:54:58 -08001000 case CMD_SEND_ENVELOPE:
1001 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001002 uiccPort = getUiccPortFromRequest(request);
1003 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001004 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -08001005 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001006 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001007 } else {
1008 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -08001009 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001010 }
Derek Tan4d5e5c12014-02-04 11:54:58 -08001011 break;
1012
1013 case EVENT_SEND_ENVELOPE_DONE:
1014 ar = (AsyncResult) msg.obj;
1015 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -07001016 if (ar.exception == null && ar.result != null) {
1017 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -08001018 } else {
Chen Xue9d737e2022-01-01 23:41:31 -08001019 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -07001020 if (ar.result == null) {
1021 loge("sendEnvelopeWithStatus: Empty response");
1022 } else if (ar.exception instanceof CommandException) {
1023 loge("sendEnvelopeWithStatus: CommandException: " +
1024 ar.exception);
1025 } else {
1026 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
1027 }
Derek Tan4d5e5c12014-02-04 11:54:58 -08001028 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001029 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -08001030 break;
1031
Shishir Agrawal566b7612013-10-28 14:41:00 -07001032 case CMD_OPEN_CHANNEL:
1033 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001034 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -08001035 IccLogicalChannelRequest openChannelRequest =
1036 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001037 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001038 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -08001039 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -08001040 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001041 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001042 } else {
1043 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -08001044 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
1045 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001046 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001047 break;
1048
1049 case EVENT_OPEN_CHANNEL_DONE:
1050 ar = (AsyncResult) msg.obj;
1051 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001052 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -07001053 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001054 int[] result = (int[]) ar.result;
1055 int channelId = result[0];
1056 byte[] selectResponse = null;
1057 if (result.length > 1) {
1058 selectResponse = new byte[result.length - 1];
1059 for (int i = 1; i < result.length; ++i) {
1060 selectResponse[i - 1] = (byte) result[i];
1061 }
1062 }
1063 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -08001064 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -08001065
1066 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -07001067 if (uiccPort == null) {
1068 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
1069 } else {
1070 IccLogicalChannelRequest channelRequest =
1071 (IccLogicalChannelRequest) request.argument;
1072 channelRequest.channel = channelId;
1073 uiccPort.onLogicalChannelOpened(channelRequest);
1074 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001075 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -07001076 if (ar.result == null) {
1077 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -07001078 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001079 if (ar.exception != null) {
1080 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
1081 }
1082
Shishir Agrawal527e8bf2014-08-25 08:54:56 -07001083 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -07001084 if (ar.exception instanceof CommandException) {
1085 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -08001086 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -07001087 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -07001088 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -07001089 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -07001090 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001091 }
1092 }
1093 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -08001094 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001095 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -07001096 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001097 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001098 break;
1099
1100 case CMD_CLOSE_CHANNEL:
1101 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001102 uiccPort = getUiccPortFromRequest(request);
1103 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001104 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -08001105 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001106 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -08001107 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001108 } else {
1109 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001110 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001111 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001112 break;
1113
1114 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -08001115 ar = (AsyncResult) msg.obj;
1116 request = (MainThreadRequest) ar.userObj;
1117 if (ar.exception == null) {
1118 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -08001119 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -07001120 if (uiccPort == null) {
1121 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
1122 } else {
1123 final int channelId = (Integer) request.argument;
1124 uiccPort.onLogicalChannelClosed(channelId);
1125 }
Chen Xu540470b2021-12-14 17:15:47 -08001126 } else {
1127 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -08001128 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -08001129 if (ar.exception instanceof CommandException) {
1130 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
1131 CommandException.Error error =
1132 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -08001133 if (error == CommandException.Error.INVALID_ARGUMENTS) {
1134 // should only throw exceptions from the binder threads.
1135 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -08001136 "iccCloseLogicalChannel: invalid argument ");
1137 }
1138 } else {
1139 loge("iccCloseLogicalChannel: Unknown exception");
1140 }
Chen Xua8f0dff2022-02-12 00:34:15 -08001141 request.result = (exception != null) ? exception :
1142 new IllegalStateException(
1143 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -08001144 }
1145 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001146 break;
1147
1148 case CMD_NV_READ_ITEM:
1149 request = (MainThreadRequest) msg.obj;
1150 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001151 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
1152 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -08001153 break;
1154
1155 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -07001156 ar = (AsyncResult) msg.obj;
1157 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -08001158 if (ar.exception == null && ar.result != null) {
1159 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -07001160 } else {
Jake Hambye994d462014-02-03 13:10:13 -08001161 request.result = "";
1162 if (ar.result == null) {
1163 loge("nvReadItem: Empty response");
1164 } else if (ar.exception instanceof CommandException) {
1165 loge("nvReadItem: CommandException: " +
1166 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001167 } else {
Jake Hambye994d462014-02-03 13:10:13 -08001168 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -07001169 }
1170 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001171 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001172 break;
1173
Jake Hambye994d462014-02-03 13:10:13 -08001174 case CMD_NV_WRITE_ITEM:
1175 request = (MainThreadRequest) msg.obj;
1176 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
1177 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001178 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -07001179 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -08001180 break;
1181
1182 case EVENT_NV_WRITE_ITEM_DONE:
1183 handleNullReturnEvent(msg, "nvWriteItem");
1184 break;
1185
1186 case CMD_NV_WRITE_CDMA_PRL:
1187 request = (MainThreadRequest) msg.obj;
1188 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001189 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -08001190 break;
1191
1192 case EVENT_NV_WRITE_CDMA_PRL_DONE:
1193 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
1194 break;
1195
chen xu6dac5ab2018-10-26 17:39:23 -07001196 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -08001197 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -07001198 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001199 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -08001200 break;
1201
chen xu6dac5ab2018-10-26 17:39:23 -07001202 case EVENT_RESET_MODEM_CONFIG_DONE:
1203 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -08001204 break;
1205
Sooraj Sasindran37444802020-08-11 10:40:43 -07001206 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
1207 request = (MainThreadRequest) msg.obj;
1208 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
1209 request);
1210 Phone phone = getPhoneFromRequest(request);
1211 if (phone != null) {
1212 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
1213 } else {
1214 loge("isNRDualConnectivityEnabled: No phone object");
1215 request.result = false;
1216 notifyRequester(request);
1217 }
1218 break;
1219 }
1220
1221 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
1222 ar = (AsyncResult) msg.obj;
1223 request = (MainThreadRequest) ar.userObj;
1224 if (ar.exception == null && ar.result != null) {
1225 request.result = ar.result;
1226 } else {
1227 // request.result must be set to something non-null
1228 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001229 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -07001230 request.result = ar.result;
1231 } else {
1232 request.result = false;
1233 }
1234 if (ar.result == null) {
1235 loge("isNRDualConnectivityEnabled: Empty response");
1236 } else if (ar.exception instanceof CommandException) {
1237 loge("isNRDualConnectivityEnabled: CommandException: "
1238 + ar.exception);
1239 } else {
1240 loge("isNRDualConnectivityEnabled: Unknown exception");
1241 }
1242 }
1243 notifyRequester(request);
1244 break;
1245
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001246 case CMD_IS_VONR_ENABLED: {
1247 request = (MainThreadRequest) msg.obj;
1248 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1249 request);
1250 Phone phone = getPhoneFromRequest(request);
1251 if (phone != null) {
1252 phone.isVoNrEnabled(onCompleted, request.workSource);
1253 } else {
1254 loge("isVoNrEnabled: No phone object");
1255 request.result = false;
1256 notifyRequester(request);
1257 }
1258 break;
1259 }
1260
1261 case EVENT_IS_VONR_ENABLED_DONE:
1262 ar = (AsyncResult) msg.obj;
1263 request = (MainThreadRequest) ar.userObj;
1264 if (ar.exception == null && ar.result != null) {
1265 request.result = ar.result;
1266 } else {
1267 // request.result must be set to something non-null
1268 // for the calling thread to unblock
1269 if (ar.result != null) {
1270 request.result = ar.result;
1271 } else {
1272 request.result = false;
1273 }
1274 if (ar.result == null) {
1275 loge("isVoNrEnabled: Empty response");
1276 } else if (ar.exception instanceof CommandException) {
1277 loge("isVoNrEnabled: CommandException: "
1278 + ar.exception);
1279 } else {
1280 loge("isVoNrEnabled: Unknown exception");
1281 }
1282 }
1283 notifyRequester(request);
1284 break;
1285
Sooraj Sasindran37444802020-08-11 10:40:43 -07001286 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1287 request = (MainThreadRequest) msg.obj;
1288 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1289 Phone phone = getPhoneFromRequest(request);
1290 if (phone != null) {
1291 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1292 request.workSource);
1293 } else {
1294 loge("enableNrDualConnectivity: No phone object");
1295 request.result =
1296 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1297 notifyRequester(request);
1298 }
1299 break;
1300 }
1301
1302 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1303 ar = (AsyncResult) msg.obj;
1304 request = (MainThreadRequest) ar.userObj;
1305 if (ar.exception == null) {
1306 request.result =
1307 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1308 } else {
1309 request.result =
1310 TelephonyManager
1311 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1312 if (ar.exception instanceof CommandException) {
1313 CommandException.Error error =
1314 ((CommandException) (ar.exception)).getCommandError();
1315 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1316 request.result =
1317 TelephonyManager
1318 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001319 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1320 request.result =
1321 TelephonyManager
1322 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001323 }
1324 loge("enableNrDualConnectivity" + ": CommandException: "
1325 + ar.exception);
1326 } else {
1327 loge("enableNrDualConnectivity" + ": Unknown exception");
1328 }
1329 }
1330 notifyRequester(request);
1331 break;
1332 }
1333
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001334 case CMD_ENABLE_VONR: {
1335 request = (MainThreadRequest) msg.obj;
1336 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1337 Phone phone = getPhoneFromRequest(request);
1338 if (phone != null) {
1339 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1340 request.workSource);
1341 } else {
1342 loge("setVoNrEnabled: No phone object");
1343 request.result =
1344 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1345 notifyRequester(request);
1346 }
1347 break;
1348 }
1349
1350 case EVENT_ENABLE_VONR_DONE: {
1351 ar = (AsyncResult) msg.obj;
1352 request = (MainThreadRequest) ar.userObj;
1353 if (ar.exception == null) {
1354 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1355 } else {
1356 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1357 if (ar.exception instanceof CommandException) {
1358 CommandException.Error error =
1359 ((CommandException) (ar.exception)).getCommandError();
1360 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1361 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1362 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1363 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1364 } else {
1365 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1366 }
1367 loge("setVoNrEnabled" + ": CommandException: "
1368 + ar.exception);
1369 } else {
1370 loge("setVoNrEnabled" + ": Unknown exception");
1371 }
1372 }
1373 notifyRequester(request);
1374 break;
1375 }
1376
SongFerngWang3ef3e072020-12-21 16:41:52 +08001377 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001378 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001379 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1380 request);
1381 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001382 break;
1383
SongFerngWang3ef3e072020-12-21 16:41:52 +08001384 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001385 ar = (AsyncResult) msg.obj;
1386 request = (MainThreadRequest) ar.userObj;
1387 if (ar.exception == null && ar.result != null) {
1388 request.result = ar.result; // Integer
1389 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301390 // request.result must be set to something non-null
1391 // for the calling thread to unblock
1392 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001393 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001394 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001395 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001396 loge("getAllowedNetworkTypesBitmask: CommandException: "
1397 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001398 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001399 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001400 }
1401 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001402 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001403 break;
1404
SongFerngWang3ef3e072020-12-21 16:41:52 +08001405 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001406 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001407 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1408 request);
1409 Pair<Integer, Long> reasonWithNetworkTypes =
1410 (Pair<Integer, Long>) request.argument;
1411 getPhoneFromRequest(request).setAllowedNetworkTypes(
1412 reasonWithNetworkTypes.first,
1413 reasonWithNetworkTypes.second,
1414 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001415 break;
1416
SongFerngWang3ef3e072020-12-21 16:41:52 +08001417 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1418 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001419 break;
1420
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001421 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1422 request = (MainThreadRequest)msg.obj;
1423 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001424 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001425 break;
1426
1427 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1428 ar = (AsyncResult)msg.obj;
1429 request = (MainThreadRequest)ar.userObj;
1430 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001431 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001432 break;
1433
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001434 case CMD_SET_VOICEMAIL_NUMBER:
1435 request = (MainThreadRequest) msg.obj;
1436 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1437 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001438 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1439 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001440 break;
1441
1442 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1443 handleNullReturnEvent(msg, "setVoicemailNumber");
1444 break;
1445
Stuart Scott54788802015-03-30 13:18:01 -07001446 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1447 request = (MainThreadRequest) msg.obj;
1448 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1449 request);
1450 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1451 break;
1452
1453 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1454 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1455 break;
1456
Shishir Agrawal302c8692015-06-19 13:49:39 -07001457 case CMD_PERFORM_NETWORK_SCAN:
1458 request = (MainThreadRequest) msg.obj;
1459 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1460 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1461 break;
1462
Hall Liu27d24262020-09-18 19:04:59 -07001463 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001464 request = (MainThreadRequest) msg.obj;
1465 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001466 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1467 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1468 request.argument;
1469 int callForwardingReason = args.first;
1470 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001471 break;
Hall Liu27d24262020-09-18 19:04:59 -07001472 }
1473 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001474 ar = (AsyncResult) msg.obj;
1475 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001476 TelephonyManager.CallForwardingInfoCallback callback =
1477 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1478 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001479 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001480 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001481 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1482 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1483 // Service Class is a bit mask per 3gpp 27.007. Search for
1484 // any service for voice call.
1485 if ((callForwardInfo.serviceClass
1486 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001487 callForwardingInfo = new CallForwardingInfo(
1488 callForwardInfo.status
1489 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001490 callForwardInfo.reason,
1491 callForwardInfo.number,
1492 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001493 break;
1494 }
1495 }
1496 // Didn't find a call forward info for voice call.
1497 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001498 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1499 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001500 }
Hall Liu27d24262020-09-18 19:04:59 -07001501 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001502 } else {
1503 if (ar.result == null) {
1504 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1505 }
1506 if (ar.exception != null) {
1507 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1508 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001509 int errorCode = TelephonyManager
1510 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001511 if (ar.exception instanceof CommandException) {
1512 CommandException.Error error =
1513 ((CommandException) (ar.exception)).getCommandError();
1514 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001515 errorCode = TelephonyManager
1516 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001517 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001518 errorCode = TelephonyManager
1519 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001520 }
1521 }
Hall Liu27d24262020-09-18 19:04:59 -07001522 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001523 }
Shuo Qian4a594052020-01-23 11:59:30 -08001524 break;
Hall Liu27d24262020-09-18 19:04:59 -07001525 }
Shuo Qian4a594052020-01-23 11:59:30 -08001526
Hall Liu27d24262020-09-18 19:04:59 -07001527 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001528 request = (MainThreadRequest) msg.obj;
1529 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001530 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001531 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001532 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1533 request.argument).first;
1534 request.phone.setCallForwardingOption(
1535 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001536 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001537 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001538 callForwardingInfoToSet.getReason(),
1539 callForwardingInfoToSet.getNumber(),
1540 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1541 break;
Hall Liu27d24262020-09-18 19:04:59 -07001542 }
Shuo Qian4a594052020-01-23 11:59:30 -08001543
Hall Liu27d24262020-09-18 19:04:59 -07001544 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001545 ar = (AsyncResult) msg.obj;
1546 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001547 Consumer<Integer> callback =
1548 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1549 request.argument).second;
1550 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001551 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001552 int errorCode = TelephonyManager.CallForwardingInfoCallback
1553 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001554 if (ar.exception instanceof CommandException) {
1555 CommandException.Error error =
1556 ((CommandException) (ar.exception)).getCommandError();
1557 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001558 errorCode = TelephonyManager.CallForwardingInfoCallback
1559 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001560 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001561 errorCode = TelephonyManager.CallForwardingInfoCallback
1562 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001563 }
1564 }
1565 callback.accept(errorCode);
1566 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001567 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001568 }
Shuo Qian4a594052020-01-23 11:59:30 -08001569 break;
Hall Liu27d24262020-09-18 19:04:59 -07001570 }
Shuo Qian4a594052020-01-23 11:59:30 -08001571
Hall Liu27d24262020-09-18 19:04:59 -07001572 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001573 request = (MainThreadRequest) msg.obj;
1574 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1575 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1576 break;
Hall Liu27d24262020-09-18 19:04:59 -07001577 }
Shuo Qian4a594052020-01-23 11:59:30 -08001578
Hall Liu27d24262020-09-18 19:04:59 -07001579 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001580 ar = (AsyncResult) msg.obj;
1581 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001582 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001583 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001584 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001585 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001586 // Service Class is a bit mask per 3gpp 27.007.
1587 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001588 if (callForwardResults.length > 1
1589 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001590 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001591 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001592 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1593 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001594 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001595 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001596 }
1597 } else {
1598 if (ar.result == null) {
1599 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1600 }
1601 if (ar.exception != null) {
1602 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1603 }
1604 if (ar.exception instanceof CommandException) {
1605 CommandException.Error error =
1606 ((CommandException) (ar.exception)).getCommandError();
1607 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001608 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001609 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001610 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1611 callWaitingStatus =
1612 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001613 }
1614 }
1615 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001616 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001617 break;
Hall Liu27d24262020-09-18 19:04:59 -07001618 }
Shuo Qian4a594052020-01-23 11:59:30 -08001619
Hall Liu27d24262020-09-18 19:04:59 -07001620 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001621 request = (MainThreadRequest) msg.obj;
1622 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001623 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1624 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001625 break;
Hall Liu27d24262020-09-18 19:04:59 -07001626 }
Shuo Qian4a594052020-01-23 11:59:30 -08001627
Hall Liu27d24262020-09-18 19:04:59 -07001628 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001629 ar = (AsyncResult) msg.obj;
1630 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001631 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1632 Consumer<Integer> callback =
1633 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1634 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001635 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001636 if (ar.exception instanceof CommandException) {
1637 CommandException.Error error =
1638 ((CommandException) (ar.exception)).getCommandError();
1639 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1640 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001641 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1642 callback.accept(
1643 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001644 } else {
1645 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1646 }
1647 } else {
1648 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1649 }
1650 } else {
1651 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1652 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001653 }
Shuo Qian4a594052020-01-23 11:59:30 -08001654 break;
Hall Liu27d24262020-09-18 19:04:59 -07001655 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001656 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1657 ar = (AsyncResult) msg.obj;
1658 request = (MainThreadRequest) ar.userObj;
1659 CellNetworkScanResult cellScanResult;
1660 if (ar.exception == null && ar.result != null) {
1661 cellScanResult = new CellNetworkScanResult(
1662 CellNetworkScanResult.STATUS_SUCCESS,
1663 (List<OperatorInfo>) ar.result);
1664 } else {
1665 if (ar.result == null) {
1666 loge("getCellNetworkScanResults: Empty response");
1667 }
1668 if (ar.exception != null) {
1669 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1670 }
1671 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1672 if (ar.exception instanceof CommandException) {
1673 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001674 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001675 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1676 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1677 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1678 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1679 }
1680 }
1681 cellScanResult = new CellNetworkScanResult(errorCode, null);
1682 }
1683 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001684 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001685 break;
1686
1687 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1688 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001689 ManualNetworkSelectionArgument selArg =
1690 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001691 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1692 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001693 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1694 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001695 break;
1696
1697 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001698 ar = (AsyncResult) msg.obj;
1699 request = (MainThreadRequest) ar.userObj;
1700 if (ar.exception == null) {
1701 request.result = true;
1702 } else {
1703 request.result = false;
1704 loge("setNetworkSelectionModeManual " + ar.exception);
1705 }
1706 notifyRequester(request);
1707 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001708 break;
1709
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001710 case CMD_GET_MODEM_ACTIVITY_INFO:
1711 request = (MainThreadRequest) msg.obj;
1712 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001713 if (defaultPhone != null) {
1714 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001715 } else {
1716 ResultReceiver result = (ResultReceiver) request.argument;
1717 Bundle bundle = new Bundle();
1718 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001719 new ModemActivityInfo(0, 0, 0,
1720 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001721 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001722 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001723 break;
1724
Hall Liud0f208c2020-10-14 16:54:44 -07001725 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001726 ar = (AsyncResult) msg.obj;
1727 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001728 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001729 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001730 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001731 if (mLastModemActivityInfo == null) {
1732 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1733 mLastModemActivitySpecificInfo[0] =
1734 new ActivityStatsTechSpecificInfo(
1735 0,
1736 0,
1737 new int[ModemActivityInfo.getNumTxPowerLevels()],
1738 0);
1739 mLastModemActivityInfo =
1740 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1741 }
1742
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001743 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001744 // Update the last modem activity info and the result of the request.
1745 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1746 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001747 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001748 } else {
1749 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001750 }
Kai Shi917fdc62022-11-28 14:01:02 -08001751 // This is needed to decouple ret from mLastModemActivityInfo
1752 // We don't want to return mLastModemActivityInfo which is updated
1753 // inside mergeModemActivityInfo()
1754 ret = new ModemActivityInfo(
1755 mLastModemActivityInfo.getTimestampMillis(),
1756 mLastModemActivityInfo.getSleepTimeMillis(),
1757 mLastModemActivityInfo.getIdleTimeMillis(),
1758 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001759
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001760 } else {
1761 if (ar.result == null) {
1762 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001763 error = TelephonyManager.ModemActivityInfoException
1764 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001765 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001766 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001767 error = TelephonyManager.ModemActivityInfoException
1768 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001769 } else {
1770 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001771 error = TelephonyManager.ModemActivityInfoException
1772 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001773 }
1774 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001775 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001776 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001777 bundle.putParcelable(
1778 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001779 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001780 } else {
1781 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1782 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001783 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001784 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001785 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001786 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001787
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001788 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001789 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001790 CarrierRestrictionRules argument =
1791 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001792 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001793 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001794 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001795 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001796
1797 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1798 ar = (AsyncResult) msg.obj;
1799 request = (MainThreadRequest) ar.userObj;
1800 if (ar.exception == null && ar.result != null) {
1801 request.result = ar.result;
1802 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001803 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1804 if (ar.exception instanceof CommandException) {
1805 loge("setAllowedCarriers: CommandException: " + ar.exception);
1806 CommandException.Error error =
1807 ((CommandException) (ar.exception)).getCommandError();
1808 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1809 request.result =
1810 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1811 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001812 } else {
1813 loge("setAllowedCarriers: Unknown exception");
1814 }
1815 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001816 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001817 break;
1818
1819 case CMD_GET_ALLOWED_CARRIERS:
1820 request = (MainThreadRequest) msg.obj;
1821 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001822 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001823 break;
1824
1825 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1826 ar = (AsyncResult) msg.obj;
1827 request = (MainThreadRequest) ar.userObj;
1828 if (ar.exception == null && ar.result != null) {
1829 request.result = ar.result;
1830 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001831 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001832 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001833 if (ar.result == null) {
1834 loge("getAllowedCarriers: Empty response");
1835 } else if (ar.exception instanceof CommandException) {
1836 loge("getAllowedCarriers: CommandException: " +
1837 ar.exception);
1838 } else {
1839 loge("getAllowedCarriers: Unknown exception");
1840 }
1841 }
arunvoddud7401012022-12-15 16:08:12 +00001842 if (request.argument != null) {
1843 // This is for the implementation of carrierRestrictionStatus.
1844 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1845 Consumer<Integer> callback = callbackInfo.getConsumer();
1846 int callerCarrierId = callbackInfo.getCarrierId();
1847 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1848 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1849 CarrierRestrictionRules carrierRestrictionRules =
1850 (CarrierRestrictionRules) ar.result;
1851 int carrierId = -1;
1852 try {
1853 CarrierIdentifier carrierIdentifier =
1854 carrierRestrictionRules.getAllowedCarriers().get(0);
1855 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1856 carrierIdentifier);
1857 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1858 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1859 }
1860 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1861 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1862 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001863 lockStatus = TelephonyManager
1864 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001865 }
1866 } else {
1867 Rlog.e(LOG_TAG,
1868 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1869 }
1870 callback.accept(lockStatus);
1871 } else {
1872 // This is for the implementation of getAllowedCarriers.
1873 notifyRequester(request);
1874 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001875 break;
1876
Nathan Haroldb3014052017-01-25 15:57:32 -08001877 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1878 ar = (AsyncResult) msg.obj;
1879 request = (MainThreadRequest) ar.userObj;
1880 if (ar.exception == null && ar.result != null) {
1881 request.result = ar.result;
1882 } else {
1883 request.result = new IllegalArgumentException(
1884 "Failed to retrieve Forbidden Plmns");
1885 if (ar.result == null) {
1886 loge("getForbiddenPlmns: Empty response");
1887 } else {
1888 loge("getForbiddenPlmns: Unknown exception");
1889 }
1890 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001891 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001892 break;
1893
1894 case CMD_GET_FORBIDDEN_PLMNS:
1895 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001896 uiccPort = getUiccPortFromRequest(request);
1897 if (uiccPort == null) {
1898 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001899 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001900 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001901 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001902 break;
1903 }
1904 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001905 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001906 if (uiccApp == null) {
1907 loge("getForbiddenPlmns() no app with specified type -- "
1908 + appType);
1909 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001910 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001911 break;
1912 } else {
1913 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1914 + " specified type -- " + appType);
1915 }
1916 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1917 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001918 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001919 break;
1920
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001921 case CMD_SWITCH_SLOTS:
1922 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001923 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001924 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001925 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001926 break;
1927
1928 case EVENT_SWITCH_SLOTS_DONE:
1929 ar = (AsyncResult) msg.obj;
1930 request = (MainThreadRequest) ar.userObj;
1931 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001932 notifyRequester(request);
1933 break;
1934 case CMD_GET_NETWORK_SELECTION_MODE:
1935 request = (MainThreadRequest) msg.obj;
1936 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1937 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1938 break;
1939
1940 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1941 ar = (AsyncResult) msg.obj;
1942 request = (MainThreadRequest) ar.userObj;
1943 if (ar.exception != null) {
1944 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1945 } else {
1946 int mode = ((int[]) ar.result)[0];
1947 if (mode == 0) {
1948 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1949 } else {
1950 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1951 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001952 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001953 notifyRequester(request);
1954 break;
1955 case CMD_GET_CDMA_ROAMING_MODE:
1956 request = (MainThreadRequest) msg.obj;
1957 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1958 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1959 break;
1960 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1961 ar = (AsyncResult) msg.obj;
1962 request = (MainThreadRequest) ar.userObj;
1963 if (ar.exception != null) {
1964 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1965 } else {
1966 request.result = ((int[]) ar.result)[0];
1967 }
1968 notifyRequester(request);
1969 break;
1970 case CMD_SET_CDMA_ROAMING_MODE:
1971 request = (MainThreadRequest) msg.obj;
1972 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1973 int mode = (int) request.argument;
1974 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1975 break;
1976 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1977 ar = (AsyncResult) msg.obj;
1978 request = (MainThreadRequest) ar.userObj;
1979 request.result = ar.exception == null;
1980 notifyRequester(request);
1981 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001982 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1983 request = (MainThreadRequest) msg.obj;
1984 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1985 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1986 break;
1987 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1988 ar = (AsyncResult) msg.obj;
1989 request = (MainThreadRequest) ar.userObj;
1990 if (ar.exception != null) {
1991 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1992 } else {
1993 request.result = ((int[]) ar.result)[0];
1994 }
1995 notifyRequester(request);
1996 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001997 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1998 request = (MainThreadRequest) msg.obj;
1999 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
2000 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07002001 getPhoneFromRequest(request).setCdmaSubscriptionMode(
2002 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07002003 break;
2004 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
2005 ar = (AsyncResult) msg.obj;
2006 request = (MainThreadRequest) ar.userObj;
2007 request.result = ar.exception == null;
2008 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00002009 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07002010 case CMD_GET_ALL_CELL_INFO:
2011 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07002012 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07002013 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07002014 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07002015 case EVENT_GET_ALL_CELL_INFO_DONE:
2016 ar = (AsyncResult) msg.obj;
2017 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07002018 // If a timeout occurs, the response will be null
2019 request.result = (ar.exception == null && ar.result != null)
2020 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07002021 synchronized (request) {
2022 request.notifyAll();
2023 }
2024 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002025 case CMD_REQUEST_CELL_INFO_UPDATE:
2026 request = (MainThreadRequest) msg.obj;
2027 request.phone.requestCellInfoUpdate(request.workSource,
2028 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
2029 break;
2030 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
2031 ar = (AsyncResult) msg.obj;
2032 request = (MainThreadRequest) ar.userObj;
2033 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
2034 try {
2035 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002036 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07002037 cb.onError(
2038 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
2039 ar.exception.getClass().getName(),
2040 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002041 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002042 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07002043 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002044 } else {
2045 // use the result as returned
2046 cb.onCellInfo((List<CellInfo>) ar.result);
2047 }
2048 } catch (RemoteException re) {
2049 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
2050 }
2051 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08002052 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07002053 request = (MainThreadRequest) msg.obj;
2054 WorkSource ws = (WorkSource) request.argument;
2055 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08002056 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07002057 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08002058 }
2059 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07002060 ar = (AsyncResult) msg.obj;
2061 request = (MainThreadRequest) ar.userObj;
2062 if (ar.exception == null) {
2063 request.result = ar.result;
2064 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08002065 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07002066 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08002067 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07002068 }
2069
2070 synchronized (request) {
2071 request.notifyAll();
2072 }
2073 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08002074 }
chen xu6dac5ab2018-10-26 17:39:23 -07002075 case CMD_MODEM_REBOOT:
2076 request = (MainThreadRequest) msg.obj;
2077 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002078 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07002079 break;
chen xu6dac5ab2018-10-26 17:39:23 -07002080 case EVENT_CMD_MODEM_REBOOT_DONE:
2081 handleNullReturnEvent(msg, "rebootModem");
2082 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002083 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002084 request = (MainThreadRequest) msg.obj;
2085 boolean enable = (boolean) request.argument;
2086 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08002087 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002088 PhoneConfigurationManager.getInstance()
2089 .enablePhone(request.phone, enable, onCompleted);
2090 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002091 }
Michele Berionne5e411512020-11-13 02:36:59 +00002092 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002093 ar = (AsyncResult) msg.obj;
2094 request = (MainThreadRequest) ar.userObj;
2095 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07002096 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08002097 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07002098 if ((boolean) request.result) {
2099 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
2100 updateModemStateMetrics();
2101 } else {
2102 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
2103 + ar.exception);
2104 }
2105 notifyRequester(request);
2106 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002107 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07002108 case CMD_GET_MODEM_STATUS:
2109 request = (MainThreadRequest) msg.obj;
2110 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
2111 PhoneConfigurationManager.getInstance()
2112 .getPhoneStatusFromModem(request.phone, onCompleted);
2113 break;
2114 case EVENT_GET_MODEM_STATUS_DONE:
2115 ar = (AsyncResult) msg.obj;
2116 request = (MainThreadRequest) ar.userObj;
2117 int id = request.phone.getPhoneId();
2118 if (ar.exception == null && ar.result != null) {
2119 request.result = ar.result;
2120 //update the cache as modem status has changed
2121 mPhoneConfigurationManager.addToPhoneStatusCache(id,
2122 (boolean) request.result);
2123 } else {
2124 // Return true if modem status cannot be retrieved. For most cases,
2125 // modem status is on. And for older version modems, GET_MODEM_STATUS
2126 // and disable modem are not supported. Modem is always on.
2127 // TODO: this should be fixed in R to support a third
2128 // status UNKNOWN b/131631629
2129 request.result = true;
2130 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
2131 + ar.exception);
2132 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002133 notifyRequester(request);
2134 break;
Hall Liu73f5d362020-01-20 13:42:00 -08002135 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
2136 request = (MainThreadRequest) msg.obj;
2137 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
2138 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
2139 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
2140 request.phone.setSystemSelectionChannels(args.first, onCompleted);
2141 break;
2142 }
2143 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
2144 ar = (AsyncResult) msg.obj;
2145 request = (MainThreadRequest) ar.userObj;
2146 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
2147 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
2148 args.second.accept(ar.exception == null);
2149 notifyRequester(request);
2150 break;
2151 }
Sarah Chin679c08a2020-11-18 13:39:35 -08002152 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
2153 request = (MainThreadRequest) msg.obj;
2154 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
2155 Phone phone = getPhoneFromRequest(request);
2156 if (phone != null) {
2157 phone.getSystemSelectionChannels(onCompleted);
2158 } else {
2159 loge("getSystemSelectionChannels: No phone object");
2160 request.result = new ArrayList<RadioAccessSpecifier>();
2161 notifyRequester(request);
2162 }
2163 break;
2164 }
2165 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
2166 ar = (AsyncResult) msg.obj;
2167 request = (MainThreadRequest) ar.userObj;
2168 if (ar.exception == null && ar.result != null) {
2169 request.result = ar.result;
2170 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08002171 request.result = new IllegalStateException(
2172 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08002173 if (ar.result == null) {
2174 loge("getSystemSelectionChannels: Empty response");
2175 } else {
2176 loge("getSystemSelectionChannels: Unknown exception");
2177 }
2178 }
2179 notifyRequester(request);
2180 break;
yincheng zhao2737e882019-09-06 17:06:54 -07002181 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
2182 ar = (AsyncResult) msg.obj;
2183 request = (MainThreadRequest) ar.userObj;
2184 if (ar.exception == null && ar.result != null) {
2185 request.result = ar.result;
2186 } else {
2187 request.result = -1;
2188 loge("Failed to set Forbidden Plmns");
2189 if (ar.result == null) {
2190 loge("setForbidenPlmns: Empty response");
2191 } else if (ar.exception != null) {
2192 loge("setForbiddenPlmns: Exception: " + ar.exception);
2193 request.result = -1;
2194 } else {
2195 loge("setForbiddenPlmns: Unknown exception");
2196 }
2197 }
2198 notifyRequester(request);
2199 break;
2200 case CMD_SET_FORBIDDEN_PLMNS:
2201 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002202 uiccPort = getUiccPortFromRequest(request);
2203 if (uiccPort == null) {
2204 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07002205 request.result = -1;
2206 notifyRequester(request);
2207 break;
2208 }
2209 Pair<Integer, List<String>> setFplmnsArgs =
2210 (Pair<Integer, List<String>>) request.argument;
2211 appType = setFplmnsArgs.first;
2212 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002213 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07002214 if (uiccApp == null) {
2215 loge("setForbiddenPlmns: no app with specified type -- " + appType);
2216 request.result = -1;
2217 loge("Failed to get UICC App");
2218 notifyRequester(request);
2219 } else {
2220 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
2221 ((SIMRecords) uiccApp.getIccRecords())
2222 .setForbiddenPlmns(onCompleted, fplmns);
2223 }
yinchengzhao4d163c02019-12-12 15:21:47 -08002224 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07002225 case CMD_ERASE_MODEM_CONFIG:
2226 request = (MainThreadRequest) msg.obj;
2227 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
2228 defaultPhone.eraseModemConfig(onCompleted);
2229 break;
2230 case EVENT_ERASE_MODEM_CONFIG_DONE:
2231 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07002232 break;
zoey chene02881a2019-12-30 16:11:23 +08002233
Kai Shif70f46f2021-03-03 13:59:46 -08002234 case CMD_ERASE_DATA_SHARED_PREFERENCES:
2235 request = (MainThreadRequest) msg.obj;
2236 request.result = defaultPhone.eraseDataInSharedPreferences();
2237 notifyRequester(request);
2238 break;
2239
zoey chene02881a2019-12-30 16:11:23 +08002240 case CMD_CHANGE_ICC_LOCK_PASSWORD:
2241 request = (MainThreadRequest) msg.obj;
2242 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
2243 Pair<String, String> changed = (Pair<String, String>) request.argument;
2244 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
2245 changed.first, changed.second, onCompleted);
2246 break;
2247 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2248 ar = (AsyncResult) msg.obj;
2249 request = (MainThreadRequest) ar.userObj;
2250 if (ar.exception == null) {
2251 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002252 // If the operation is successful, update the PIN storage
2253 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2254 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002255 UiccController.getInstance().getPinStorage()
2256 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002257 } else {
2258 request.result = msg.arg1;
2259 }
2260 notifyRequester(request);
2261 break;
2262
Michele Berionne5e411512020-11-13 02:36:59 +00002263 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002264 request = (MainThreadRequest) msg.obj;
2265 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2266 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2267 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2268 enabled.first, enabled.second, onCompleted);
2269 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002270 }
zoey chene02881a2019-12-30 16:11:23 +08002271 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2272 ar = (AsyncResult) msg.obj;
2273 request = (MainThreadRequest) ar.userObj;
2274 if (ar.exception == null) {
2275 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002276 // If the operation is successful, update the PIN storage
2277 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2278 int phoneId = getPhoneFromRequest(request).getPhoneId();
2279 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002280 UiccController.getInstance().getPinStorage()
2281 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002282 } else {
2283 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2284 }
zoey chene02881a2019-12-30 16:11:23 +08002285 } else {
2286 request.result = msg.arg1;
2287 }
Michele Berionne5e411512020-11-13 02:36:59 +00002288
2289
zoey chene02881a2019-12-30 16:11:23 +08002290 notifyRequester(request);
2291 break;
2292
Peter Wangdafb9ac2020-01-15 14:13:38 -08002293 case MSG_NOTIFY_USER_ACTIVITY:
2294 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002295 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002296 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2297 getDefaultPhone().getContext().sendBroadcastAsUser(
2298 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2299 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002300
2301 case CMD_SET_DATA_THROTTLING: {
2302 request = (MainThreadRequest) msg.obj;
2303 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2304 DataThrottlingRequest dataThrottlingRequest =
2305 (DataThrottlingRequest) request.argument;
2306 Phone phone = getPhoneFromRequest(request);
2307 if (phone != null) {
2308 phone.setDataThrottling(onCompleted,
2309 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2310 dataThrottlingRequest.getCompletionDurationMillis());
2311 } else {
2312 loge("setDataThrottling: No phone object");
2313 request.result =
2314 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2315 notifyRequester(request);
2316 }
2317
2318 break;
2319 }
2320 case EVENT_SET_DATA_THROTTLING_DONE:
2321 ar = (AsyncResult) msg.obj;
2322 request = (MainThreadRequest) ar.userObj;
2323
2324 if (ar.exception == null) {
2325 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2326 } else if (ar.exception instanceof CommandException) {
2327 loge("setDataThrottling: CommandException: " + ar.exception);
2328 CommandException.Error error =
2329 ((CommandException) (ar.exception)).getCommandError();
2330
2331 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2332 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002333 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002334 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2335 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002336 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2337 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002338 } else {
2339 request.result =
2340 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2341 }
2342 } else {
2343 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2344 }
2345 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2346 notifyRequester(request);
2347 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002348
2349 case CMD_SET_SIM_POWER: {
2350 request = (MainThreadRequest) msg.obj;
2351 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2352 request = (MainThreadRequest) msg.obj;
2353 int stateToSet =
2354 ((Pair<Integer, IIntegerConsumer>)
2355 request.argument).first;
2356 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2357 break;
2358 }
2359 case EVENT_SET_SIM_POWER_DONE: {
2360 ar = (AsyncResult) msg.obj;
2361 request = (MainThreadRequest) ar.userObj;
2362 IIntegerConsumer callback =
2363 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2364 if (ar.exception != null) {
2365 loge("setSimPower exception: " + ar.exception);
2366 int errorCode = TelephonyManager.CallForwardingInfoCallback
2367 .RESULT_ERROR_UNKNOWN;
2368 if (ar.exception instanceof CommandException) {
2369 CommandException.Error error =
2370 ((CommandException) (ar.exception)).getCommandError();
2371 if (error == CommandException.Error.SIM_ERR) {
2372 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2373 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2374 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2375 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2376 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2377 } else {
2378 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2379 }
2380 }
2381 try {
2382 callback.accept(errorCode);
2383 } catch (RemoteException e) {
2384 // Ignore if the remote process is no longer available to call back.
2385 Log.w(LOG_TAG, "setSimPower: callback not available.");
2386 }
2387 } else {
2388 try {
2389 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2390 } catch (RemoteException e) {
2391 // Ignore if the remote process is no longer available to call back.
2392 Log.w(LOG_TAG, "setSimPower: callback not available.");
2393 }
2394 }
2395 break;
2396 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002397 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2398 request = (MainThreadRequest) msg.obj;
2399
2400 final Phone phone = getPhoneFromRequest(request);
2401 if (phone == null || phone.getServiceStateTracker() == null) {
2402 request.result = new IllegalStateException("Phone or SST is null");
2403 notifyRequester(request);
2404 break;
2405 }
2406
2407 Pair<Integer, SignalStrengthUpdateRequest> pair =
2408 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2409 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2410 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002411 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002412 request.subId, pair.first /*callingUid*/,
2413 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002414 break;
2415 }
2416 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2417 ar = (AsyncResult) msg.obj;
2418 request = (MainThreadRequest) ar.userObj;
2419 // request.result will be the exception of ar if present, true otherwise.
2420 // Be cautious not to leave result null which will wait() forever
2421 request.result = ar.exception != null ? ar.exception : true;
2422 notifyRequester(request);
2423 break;
2424 }
2425 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2426 request = (MainThreadRequest) msg.obj;
2427
2428 Phone phone = getPhoneFromRequest(request);
2429 if (phone == null || phone.getServiceStateTracker() == null) {
2430 request.result = new IllegalStateException("Phone or SST is null");
2431 notifyRequester(request);
2432 break;
2433 }
2434
2435 Pair<Integer, SignalStrengthUpdateRequest> pair =
2436 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2437 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2438 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002439 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002440 request.subId, pair.first /*callingUid*/,
2441 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002442 break;
2443 }
2444 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2445 ar = (AsyncResult) msg.obj;
2446 request = (MainThreadRequest) ar.userObj;
2447 request.result = ar.exception != null ? ar.exception : true;
2448 notifyRequester(request);
2449 break;
2450 }
Jordan Liu109698e2020-11-24 14:50:34 -08002451
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002452 case CMD_GET_SLICING_CONFIG: {
2453 request = (MainThreadRequest) msg.obj;
2454 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2455 request.phone.getSlicingConfig(onCompleted);
2456 break;
2457 }
2458 case EVENT_GET_SLICING_CONFIG_DONE: {
2459 ar = (AsyncResult) msg.obj;
2460 request = (MainThreadRequest) ar.userObj;
2461 ResultReceiver result = (ResultReceiver) request.argument;
2462
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002463 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002464 Bundle bundle = new Bundle();
2465 int resultCode = 0;
2466 if (ar.exception != null) {
2467 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2468 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002469 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002470 } else if (ar.result == null) {
2471 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002472 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002473 } else {
2474 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002475 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2476 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002477 }
2478
2479 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002480 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002481 }
2482 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2483 result.send(resultCode, bundle);
2484 notifyRequester(request);
2485 break;
2486 }
2487
Sarah Chin71b3a852022-09-28 15:54:19 -07002488 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002489 request = (MainThreadRequest) msg.obj;
2490 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002491 PurchasePremiumCapabilityArgument arg =
2492 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002493 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chinb8218c22023-01-04 13:35:29 -08002494 arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002495 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002496 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002497
Sarah Chin71b3a852022-09-28 15:54:19 -07002498 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002499 ar = (AsyncResult) msg.obj;
2500 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002501 PurchasePremiumCapabilityArgument arg =
2502 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002503 try {
2504 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002505 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002506 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002507 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002508 + ", result= "
2509 + TelephonyManager.convertPurchaseResultToString(result));
2510 } catch (RemoteException e) {
2511 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002512 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002513 + " failed: " + e;
2514 if (DBG) log(logStr);
2515 AnomalyReporter.reportAnomaly(
2516 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2517 }
2518 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002519 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002520
Michele Berionne5e411512020-11-13 02:36:59 +00002521 case CMD_PREPARE_UNATTENDED_REBOOT:
2522 request = (MainThreadRequest) msg.obj;
2523 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002524 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002525 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002526 notifyRequester(request);
2527 break;
2528
Sarah Chineccfbd12023-01-20 19:00:35 -08002529 case CMD_START_SATELLITE_POSITION_UPDATES: {
2530 request = (MainThreadRequest) msg.obj;
2531 onCompleted =
2532 obtainMessage(EVENT_START_SATELLITE_POSITION_UPDATES_DONE, request);
2533 Phone phone = getPhoneFromRequest(request);
2534 if (phone != null) {
2535 phone.startSatellitePositionUpdates(onCompleted);
2536 } else {
2537 loge("startSatellitePositionUpdates: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002538 ((Consumer<Integer>) request.argument).accept(
2539 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Sarah Chineccfbd12023-01-20 19:00:35 -08002540 }
2541 break;
2542 }
2543
2544 case EVENT_START_SATELLITE_POSITION_UPDATES_DONE: {
2545 ar = (AsyncResult) msg.obj;
2546 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002547 int error = getSatelliteError(ar, "startSatellitePositionUpdates", false);
2548 ((Consumer<Integer>) request.argument).accept(error);
Sarah Chineccfbd12023-01-20 19:00:35 -08002549 break;
2550 }
2551
2552 case CMD_STOP_SATELLITE_POSITION_UPDATES: {
2553 request = (MainThreadRequest) msg.obj;
2554 onCompleted =
2555 obtainMessage(EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE, request);
2556 Phone phone = getPhoneFromRequest(request);
2557 if (phone != null) {
2558 phone.stopSatellitePositionUpdates(onCompleted);
2559 } else {
2560 loge("stopSatellitePositionUpdates: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002561 ((Consumer<Integer>) request.argument).accept(
2562 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Sarah Chineccfbd12023-01-20 19:00:35 -08002563 }
2564 break;
2565 }
2566
2567 case EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE: {
2568 ar = (AsyncResult) msg.obj;
2569 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002570 int error = getSatelliteError(ar, "stopSatellitePositionUpdates", false);
2571 ((Consumer<Integer>) request.argument).accept(error);
Sarah Chineccfbd12023-01-20 19:00:35 -08002572 break;
2573 }
2574
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002575 case CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG: {
2576 request = (MainThreadRequest) msg.obj;
2577 onCompleted = obtainMessage(EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE,
2578 request);
2579 Phone phone = getPhoneFromRequest(request);
2580 if (phone != null) {
2581 phone.getMaxCharactersPerSatelliteTextMessage(onCompleted);
2582 } else {
2583 loge("getMaxCharactersPerSatelliteTextMessage: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002584 ((ResultReceiver) request.argument).send(
2585 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002586 }
2587 break;
2588 }
2589
2590 case EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE: {
2591 ar = (AsyncResult) msg.obj;
2592 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002593 int error =
2594 getSatelliteError(ar, "getMaxCharactersPerSatelliteTextMessage", true);
2595 Bundle bundle = new Bundle();
2596 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002597 int maxCharLimit = ((int[]) ar.result)[0];
Sarah Chin503828c2023-02-01 23:54:20 -08002598 if (DBG) log("getMaxCharactersPerSatelliteTextMessage: " + maxCharLimit);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002599 bundle.putInt(SatelliteManager.KEY_MAX_CHARACTERS_PER_SATELLITE_TEXT,
2600 maxCharLimit);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002601 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002602 ((ResultReceiver) request.argument).send(error, bundle);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002603 break;
2604 }
2605
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002606 case CMD_PROVISION_SATELLITE_SERVICE: {
2607 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002608 onCompleted = obtainMessage(EVENT_PROVISION_SATELLITE_SERVICE_DONE, request);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002609 Phone phone = getPhoneFromRequest(request);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002610 ProvisionSatelliteServiceArgument argument =
2611 (ProvisionSatelliteServiceArgument) request.argument;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002612 if (phone != null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002613 handleCmdProvisionSatelliteService(argument, phone, onCompleted);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002614 } else {
2615 loge("provisionSatelliteService: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002616 argument.callback.accept(
2617 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002618 notifyRequester(request);
2619 }
2620 break;
2621 }
2622
2623 case EVENT_PROVISION_SATELLITE_SERVICE_DONE: {
2624 ar = (AsyncResult) msg.obj;
2625 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002626 int errorCode = getSatelliteError(ar, "provisionSatelliteService", false);
2627 ProvisionSatelliteServiceArgument argument =
2628 (ProvisionSatelliteServiceArgument) request.argument;
2629 handleEventProvisionSatelliteServiceDone(argument.subId, errorCode);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002630 notifyRequester(request);
2631 break;
2632 }
2633
2634 case CMD_CANCEL_PROVISION_SATELLITE_SERVICE: {
2635 request = (MainThreadRequest) msg.obj;
2636 onCompleted =
2637 obtainMessage(EVENT_CANCEL_PROVISION_SATELLITE_SERVICE_DONE, request);
2638 handleCmdCancelProvisionSatelliteService((int) request.argument, onCompleted);
2639 break;
2640 }
2641
2642 case EVENT_CANCEL_PROVISION_SATELLITE_SERVICE_DONE: {
2643 ar = (AsyncResult) msg.obj;
2644 request = (MainThreadRequest) ar.userObj;
2645
2646 if (ar.exception == null) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -08002647 request.result = SatelliteManager.SATELLITE_ERROR_NONE;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002648 log("cancelProvisionSatelliteService succeeded for subId="
2649 + (int) request.argument);
2650 } else {
Thomas Nguyene77de6d2023-02-10 17:42:43 -08002651 request.result = SatelliteManager.SATELLITE_ERROR;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002652 if (ar.exception instanceof CommandException) {
2653 CommandException.Error error =
2654 ((CommandException) (ar.exception)).getCommandError();
2655 request.result = RILUtils.convertToSatelliteError(error);
2656 loge("cancelProvisionSatelliteService CommandException: "
2657 + ar.exception + ", error code:" + request.result);
2658 } else {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002659 loge("cancelProvisionSatelliteService unknown exception: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002660 + ar.exception);
2661 }
2662 }
2663 notifyRequester(request);
2664 break;
2665 }
2666
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002667 case CMD_SET_SATELLITE_ENABLED: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002668 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002669 onCompleted = obtainMessage(EVENT_SET_SATELLITE_ENABLED_DONE, request);
2670 Pair<Boolean, Consumer<Integer>> argument =
2671 (Pair<Boolean, Consumer<Integer>>) request.argument;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002672 Phone phone = getPhoneFromRequest(request);
2673 if (phone != null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002674 boolean enable = argument.first.booleanValue();
2675 phone.setSatellitePower(onCompleted, enable);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002676 } else {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002677 loge("setSatelliteEnabled: No phone object");
2678 argument.second.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002679 notifyRequester(request);
2680 }
2681 break;
2682 }
2683
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002684 case EVENT_SET_SATELLITE_ENABLED_DONE: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002685 ar = (AsyncResult) msg.obj;
2686 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002687 Pair<Boolean, Consumer<Integer>> argument =
2688 (Pair<Boolean, Consumer<Integer>>) request.argument;
2689 int error = getSatelliteError(ar, "setSatelliteEnabled", false);
2690 argument.second.accept(error);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002691 break;
2692 }
2693
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002694 case CMD_IS_SATELLITE_ENABLED: {
Sarah Chin503828c2023-02-01 23:54:20 -08002695 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002696 onCompleted = obtainMessage(EVENT_IS_SATELLITE_ENABLED_DONE, request);
Sarah Chin503828c2023-02-01 23:54:20 -08002697 Phone phone = getPhoneFromRequest(request);
2698 if (phone != null) {
2699 phone.isSatellitePowerOn(onCompleted);
2700 } else {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002701 loge("isSatelliteEnabled: No phone object");
2702 ((ResultReceiver) request.argument).send(
2703 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002704 }
2705 break;
2706 }
2707
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002708 case EVENT_IS_SATELLITE_ENABLED_DONE: {
Sarah Chin503828c2023-02-01 23:54:20 -08002709 ar = (AsyncResult) msg.obj;
2710 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002711 int error = getSatelliteError(ar, "isSatelliteEnabled", true);
2712 Bundle bundle = new Bundle();
2713 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
2714 boolean enabled = ((int[]) ar.result)[0] == 1;
2715 if (DBG) log("isSatelliteEnabled: " + enabled);
2716 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_ENABLED, enabled);
Sarah Chin503828c2023-02-01 23:54:20 -08002717 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002718 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002719 break;
2720 }
2721
2722 case CMD_IS_SATELLITE_SUPPORTED: {
2723 request = (MainThreadRequest) msg.obj;
2724 onCompleted = obtainMessage(EVENT_IS_SATELLITE_SUPPORTED_DONE, request);
2725 Phone phone = getPhoneFromRequest(request);
2726 if (phone != null) {
2727 phone.isSatelliteSupported(onCompleted);
2728 } else {
2729 loge("isSatelliteSupported: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002730 ((ResultReceiver) request.argument).send(
2731 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002732 }
2733 break;
2734 }
2735
2736 case EVENT_IS_SATELLITE_SUPPORTED_DONE: {
2737 ar = (AsyncResult) msg.obj;
2738 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002739 int error = getSatelliteError(ar, "isSatelliteSupported", true);
2740 Bundle bundle = new Bundle();
2741 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
2742 boolean supported = ((int[]) ar.result)[0] == 1;
2743 if (DBG) log("isSatelliteSupported: " + supported);
2744 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, supported);
Thomas Nguyene77de6d2023-02-10 17:42:43 -08002745 synchronized (mIsSatelliteSupportedLock) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002746 mIsSatelliteSupported = supported;
2747 }
2748 } else {
2749 synchronized (mIsSatelliteSupportedLock) {
2750 mIsSatelliteSupported = null;
Thomas Nguyene77de6d2023-02-10 17:42:43 -08002751 }
Sarah Chin503828c2023-02-01 23:54:20 -08002752 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002753 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002754 break;
2755 }
2756
2757 case CMD_GET_SATELLITE_CAPABILITIES: {
2758 request = (MainThreadRequest) msg.obj;
2759 onCompleted = obtainMessage(EVENT_GET_SATELLITE_CAPABILITIES_DONE, request);
2760 Phone phone = getPhoneFromRequest(request);
2761 if (phone != null) {
2762 phone.getSatelliteCapabilities(onCompleted);
2763 } else {
2764 loge("getSatelliteCapabilities: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002765 ((ResultReceiver) request.argument).send(
2766 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002767 }
2768 break;
2769 }
2770
2771 case EVENT_GET_SATELLITE_CAPABILITIES_DONE: {
2772 ar = (AsyncResult) msg.obj;
2773 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002774 int error = getSatelliteError(ar, "getSatelliteCapabilities", true);
2775 Bundle bundle = new Bundle();
2776 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
Sarah Chin503828c2023-02-01 23:54:20 -08002777 SatelliteCapabilities capabilities = (SatelliteCapabilities) ar.result;
2778 if (DBG) log("getSatelliteCapabilities: " + capabilities);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002779 bundle.putParcelable(SatelliteManager.KEY_SATELLITE_CAPABILITIES,
2780 capabilities);
Sarah Chin503828c2023-02-01 23:54:20 -08002781 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002782 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002783 break;
2784 }
2785
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +00002786 case CMD_POLL_PENDING_SATELLITE_DATAGRAMS: {
2787 request = (MainThreadRequest) msg.obj;
2788 onCompleted = obtainMessage(EVENT_POLL_PENDING_SATELLITE_DATAGRAMS_DONE,
2789 request);
2790 Phone phone = getPhoneFromRequest(request);
2791 if (phone != null) {
2792 phone.pollPendingSatelliteDatagrams(onCompleted);
2793 } else {
2794 loge("pollPendingSatelliteDatagrams: No phone object");
2795 request.result = SatelliteManager
2796 .SATELLITE_INVALID_TELEPHONY_STATE;
2797 notifyRequester(request);
2798 }
2799 break;
2800 }
2801
2802 case EVENT_POLL_PENDING_SATELLITE_DATAGRAMS_DONE: {
2803 ar = (AsyncResult) msg.obj;
2804 request = (MainThreadRequest) ar.userObj;
2805 if (ar.exception != null) {
2806 request.result = SatelliteManager.SATELLITE_SERVICE_ERROR;
2807 if (ar.exception instanceof CommandException) {
2808 CommandException.Error error =
2809 ((CommandException) (ar.exception)).getCommandError();
2810 request.result = RILUtils.convertToSatelliteError(error);
2811 loge("pollPendingSatelliteDatagrams: "
2812 + "CommandException: " + ar.exception);
2813 } else {
2814 loge("pollPendingSatelliteDatagrams: "
2815 + "unknown exception:" + ar.exception);
2816 }
2817 } else if (ar.result == null) {
2818 request.result = SatelliteManager
2819 .SATELLITE_INVALID_TELEPHONY_STATE;
2820 loge("pollPendingSatelliteDatagrams: result is null");
2821 } else {
2822 request.result = SatelliteManager.SATELLITE_ERROR_NONE;
2823 }
2824 notifyRequester(request);
2825 break;
2826 }
2827
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002828 default:
2829 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2830 break;
2831 }
2832 }
Jake Hambye994d462014-02-03 13:10:13 -08002833
Pengquan Menga1bb6272018-09-06 09:59:22 -07002834 private void notifyRequester(MainThreadRequest request) {
2835 synchronized (request) {
2836 request.notifyAll();
2837 }
2838 }
2839
Jake Hambye994d462014-02-03 13:10:13 -08002840 private void handleNullReturnEvent(Message msg, String command) {
2841 AsyncResult ar = (AsyncResult) msg.obj;
2842 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2843 if (ar.exception == null) {
2844 request.result = true;
2845 } else {
2846 request.result = false;
2847 if (ar.exception instanceof CommandException) {
2848 loge(command + ": CommandException: " + ar.exception);
2849 } else {
2850 loge(command + ": Unknown exception");
2851 }
2852 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002853 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002854 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002855 }
2856
2857 /**
2858 * Posts the specified command to be executed on the main thread,
2859 * waits for the request to complete, and returns the result.
2860 * @see #sendRequestAsync
2861 */
2862 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002863 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2864 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002865 }
2866
2867 /**
2868 * Posts the specified command to be executed on the main thread,
2869 * waits for the request to complete, and returns the result.
2870 * @see #sendRequestAsync
2871 */
2872 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2873 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002874 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002875 }
2876
2877 /**
2878 * Posts the specified command to be executed on the main thread,
2879 * waits for the request to complete, and returns the result.
2880 * @see #sendRequestAsync
2881 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002882 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002883 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2884 }
2885
2886 /**
2887 * Posts the specified command to be executed on the main thread,
2888 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2889 * if not timeout or null otherwise.
2890 * @see #sendRequestAsync
2891 */
2892 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2893 long timeoutInMs) {
2894 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002895 }
2896
2897 /**
2898 * Posts the specified command to be executed on the main thread,
2899 * waits for the request to complete, and returns the result.
2900 * @see #sendRequestAsync
2901 */
Nathan Harold92bed182018-10-12 18:16:49 -07002902 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002903 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002904 }
2905
2906 /**
2907 * Posts the specified command to be executed on the main thread,
2908 * waits for the request to complete, and returns the result.
2909 * @see #sendRequestAsync
2910 */
2911 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002912 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2913 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002914 }
2915
2916 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002917 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2918 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2919 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002920 * @see #sendRequestAsync
2921 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002922 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2923 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002924 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2925 throw new RuntimeException("This method will deadlock if called from the main thread.");
2926 }
2927
Nathan Harold92bed182018-10-12 18:16:49 -07002928 MainThreadRequest request = null;
2929 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2930 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2931 } else if (phone != null) {
2932 request = new MainThreadRequest(argument, phone, workSource);
2933 } else {
2934 request = new MainThreadRequest(argument, subId, workSource);
2935 }
2936
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002937 Message msg = mMainThreadHandler.obtainMessage(command, request);
2938 msg.sendToTarget();
2939
Rambo Wang0f050d82021-02-12 11:43:36 -08002940
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002941 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002942 if (timeoutInMs >= 0) {
2943 // Wait for at least timeoutInMs before returning null request result
2944 long now = SystemClock.elapsedRealtime();
2945 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002946 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002947 try {
2948 request.wait(deadline - now);
2949 } catch (InterruptedException e) {
2950 // Do nothing, go back and check if request is completed or timeout
2951 } finally {
2952 now = SystemClock.elapsedRealtime();
2953 }
2954 }
2955 } else {
2956 // Wait for the request to complete
2957 while (request.result == null) {
2958 try {
2959 request.wait();
2960 } catch (InterruptedException e) {
2961 // Do nothing, go back and wait until the request is complete
2962 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002963 }
2964 }
2965 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002966 if (request.result == null) {
2967 Log.wtf(LOG_TAG,
2968 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2969 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002970 return request.result;
2971 }
2972
2973 /**
2974 * Asynchronous ("fire and forget") version of sendRequest():
2975 * Posts the specified command to be executed on the main thread, and
2976 * returns immediately.
2977 * @see #sendRequest
2978 */
2979 private void sendRequestAsync(int command) {
2980 mMainThreadHandler.sendEmptyMessage(command);
2981 }
2982
2983 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002984 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002985 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002986 */
2987 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002988 sendRequestAsync(command, argument, null, null);
2989 }
2990
2991 /**
2992 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2993 * @see {@link #sendRequest(int,Object)}
2994 */
2995 private void sendRequestAsync(
2996 int command, Object argument, Phone phone, WorkSource workSource) {
2997 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002998 Message msg = mMainThreadHandler.obtainMessage(command, request);
2999 msg.sendToTarget();
3000 }
3001
3002 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003003 * Initialize the singleton PhoneInterfaceManager instance.
3004 * This is only done once, at startup, from PhoneApp.onCreate().
3005 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003006 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003007 synchronized (PhoneInterfaceManager.class) {
3008 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003009 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003010 } else {
3011 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
3012 }
3013 return sInstance;
3014 }
3015 }
3016
3017 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00003018 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003019 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003020 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00003021 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07003022 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003023 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07003024 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003025 mMainThreadHandler = new MainThreadHandler();
Jack Yue37dd262022-12-16 11:53:37 -08003026 if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) {
3027 mSubscriptionController = SubscriptionController.getInstance();
3028 } else {
3029 mSubscriptionController = null;
3030 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003031 mTelephonySharedPreferences =
3032 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07003033 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07003034 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08003035 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08003036 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07003037 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003038 publish();
arunvoddud7401012022-12-15 16:08:12 +00003039 CarrierAllowListInfo.loadInstance(mApp);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08003040 mSatelliteSupportedReceiver = new ResultReceiver(mMainThreadHandler) {
3041 @Override
3042 protected void onReceiveResult(int resultCode, Bundle resultData) {
3043 if (resultCode == SatelliteManager.SATELLITE_ERROR_NONE
3044 && resultData.containsKey(SatelliteManager.KEY_SATELLITE_SUPPORTED)) {
3045 synchronized (mIsSatelliteSupportedLock) {
3046 mIsSatelliteSupported = resultData.getBoolean(
3047 SatelliteManager.KEY_SATELLITE_SUPPORTED);
3048 }
3049 } else {
3050 synchronized (mIsSatelliteSupportedLock) {
3051 mIsSatelliteSupported = null;
3052 }
3053 }
3054 }
3055 };
3056 requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
3057 mSatelliteSupportedReceiver);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003058 }
3059
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003060 @VisibleForTesting
3061 public SharedPreferences getSharedPreferences() {
3062 return mTelephonySharedPreferences;
3063 }
3064
Gil Cukierman92cc7db2023-01-06 19:25:53 +00003065 /**
3066 * Get the default phone for this device.
3067 */
3068 @VisibleForTesting
3069 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003070 Phone thePhone = getPhone(getDefaultSubscription());
3071 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
3072 }
3073
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003074 private void publish() {
3075 if (DBG) log("publish: " + this);
3076
Peter Wangc035ce42020-01-08 21:00:22 -08003077 TelephonyFrameworkInitializer
3078 .getTelephonyServiceManager()
3079 .getTelephonyServiceRegisterer()
3080 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003081 }
3082
Stuart Scott584921c2015-01-15 17:10:34 -08003083 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08003084 if (request.phone != null) {
3085 return request.phone;
3086 } else {
3087 return getPhoneFromSubId(request.subId);
3088 }
3089 }
3090
3091 private Phone getPhoneFromSubId(int subId) {
3092 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
3093 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08003094 }
3095
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00003096 /**
3097 * Get phone object associated with a subscription.
3098 * Return default phone if phone object associated with subscription is null
3099 * @param subId - subscriptionId
3100 * @return phone object associated with a subscription or default phone if null.
3101 */
3102 private Phone getPhoneFromSubIdOrDefault(int subId) {
3103 Phone phone = getPhoneFromSubId(subId);
3104 if (phone == null) {
3105 phone = getDefaultPhone();
3106 }
3107 return phone;
3108 }
3109
Rambo Wange53e07d2022-05-10 13:01:13 -07003110 @Nullable
3111 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003112 Phone phone = getPhoneFromRequest(request);
3113 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00003114 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003115 }
3116
Wink Saville36469e72014-06-11 15:17:00 -07003117 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07003118 private Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08003119 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07003120 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003121
Kai Shif70f46f2021-03-03 13:59:46 -08003122 private void sendEraseModemConfig(@NonNull Phone phone) {
3123 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
3124 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
3125 }
3126
3127 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
3128 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
3129 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07003130 }
3131
Peter Wang44b186e2020-01-13 23:33:09 -08003132 private boolean isImsAvailableOnDevice() {
3133 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
3134 if (pm == null) {
3135 // For some reason package manger is not available.. This will fail internally anyway,
3136 // so do not throw error and allow.
3137 return true;
3138 }
3139 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
3140 }
3141
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003142 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003143 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07003144 }
3145
Wink Savilleb564aae2014-10-23 10:18:09 -07003146 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003147 if (DBG) log("dial: " + number);
3148 // No permission check needed here: This is just a wrapper around the
3149 // ACTION_DIAL intent, which is available to any app since it puts up
3150 // the UI before it does anything.
3151
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003152 final long identity = Binder.clearCallingIdentity();
3153 try {
3154 String url = createTelUrl(number);
3155 if (url == null) {
3156 return;
3157 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003158
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003159 // PENDING: should we just silently fail if phone is offhook or ringing?
3160 PhoneConstants.State state = mCM.getState(subId);
3161 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
3162 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
3163 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3164 mApp.startActivity(intent);
3165 }
3166 } finally {
3167 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003168 }
3169 }
3170
3171 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003172 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07003173 }
3174
Wink Savilleb564aae2014-10-23 10:18:09 -07003175 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003176 if (DBG) log("call: " + number);
3177
3178 // This is just a wrapper around the ACTION_CALL intent, but we still
3179 // need to do a permission check since we're calling startActivity()
3180 // from the context of the phone app.
3181 enforceCallPermission();
3182
Jordan Liu1617b712019-07-10 15:06:26 -07003183 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003184 != AppOpsManager.MODE_ALLOWED) {
3185 return;
3186 }
3187
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003188 final long identity = Binder.clearCallingIdentity();
3189 try {
3190 String url = createTelUrl(number);
3191 if (url == null) {
3192 return;
3193 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003194
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003195 boolean isValid = false;
3196 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
3197 if (slist != null) {
3198 for (SubscriptionInfo subInfoRecord : slist) {
3199 if (subInfoRecord.getSubscriptionId() == subId) {
3200 isValid = true;
3201 break;
3202 }
Wink Saville3ab207e2014-11-20 13:07:20 -08003203 }
Wink Saville08874612014-08-31 19:19:58 -07003204 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003205 if (!isValid) {
3206 return;
3207 }
Wink Saville08874612014-08-31 19:19:58 -07003208
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003209 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
3210 intent.putExtra(SUBSCRIPTION_KEY, subId);
3211 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3212 mApp.startActivity(intent);
3213 } finally {
3214 Binder.restoreCallingIdentity(identity);
3215 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003216 }
3217
Wink Savilleb564aae2014-10-23 10:18:09 -07003218 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003219 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07003220 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
3221 }
3222
Wink Savilleb564aae2014-10-23 10:18:09 -07003223 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003224 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07003225 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
3226 }
3227
Wink Savilleb564aae2014-10-23 10:18:09 -07003228 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003229 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003230
3231 final long identity = Binder.clearCallingIdentity();
3232 try {
Michele Berionne5e411512020-11-13 02:36:59 +00003233 Phone phone = getPhone(subId);
3234 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003235 checkSimPin.start();
3236 return checkSimPin.unlockSim(null, pin);
3237 } finally {
3238 Binder.restoreCallingIdentity(identity);
3239 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003240 }
3241
Wink Savilleb564aae2014-10-23 10:18:09 -07003242 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003243 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003244
3245 final long identity = Binder.clearCallingIdentity();
3246 try {
Michele Berionne5e411512020-11-13 02:36:59 +00003247 Phone phone = getPhone(subId);
3248 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003249 checkSimPuk.start();
3250 return checkSimPuk.unlockSim(puk, pin);
3251 } finally {
3252 Binder.restoreCallingIdentity(identity);
3253 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003254 }
3255
3256 /**
Wink Saville9de0f752013-10-22 19:04:03 -07003257 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003258 * a synchronous one.
3259 */
3260 private static class UnlockSim extends Thread {
3261
3262 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00003263 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003264
3265 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07003266 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
3267 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003268
3269 // For replies from SimCard interface
3270 private Handler mHandler;
3271
3272 // For async handler to identify request type
3273 private static final int SUPPLY_PIN_COMPLETE = 100;
3274
Michele Berionne5e411512020-11-13 02:36:59 +00003275 UnlockSim(int phoneId, IccCard simCard) {
3276 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003277 mSimCard = simCard;
3278 }
3279
3280 @Override
3281 public void run() {
3282 Looper.prepare();
3283 synchronized (UnlockSim.this) {
3284 mHandler = new Handler() {
3285 @Override
3286 public void handleMessage(Message msg) {
3287 AsyncResult ar = (AsyncResult) msg.obj;
3288 switch (msg.what) {
3289 case SUPPLY_PIN_COMPLETE:
3290 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
3291 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07003292 mRetryCount = msg.arg1;
3293 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08003294 CommandException.Error error = null;
3295 if (ar.exception instanceof CommandException) {
3296 error = ((CommandException) (ar.exception))
3297 .getCommandError();
3298 }
3299 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07003300 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08003301 } else if (error == CommandException.Error.ABORTED) {
3302 /* When UiccCardApp dispose, handle message and return
3303 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08003304 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07003305 } else {
3306 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
3307 }
3308 } else {
3309 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
3310 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003311 mDone = true;
3312 UnlockSim.this.notifyAll();
3313 }
3314 break;
3315 }
3316 }
3317 };
3318 UnlockSim.this.notifyAll();
3319 }
3320 Looper.loop();
3321 }
3322
3323 /*
3324 * Use PIN or PUK to unlock SIM card
3325 *
3326 * If PUK is null, unlock SIM card with PIN
3327 *
3328 * If PUK is not null, unlock SIM card with PUK and set PIN code
3329 */
Wink Saville9de0f752013-10-22 19:04:03 -07003330 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003331
3332 while (mHandler == null) {
3333 try {
3334 wait();
3335 } catch (InterruptedException e) {
3336 Thread.currentThread().interrupt();
3337 }
3338 }
3339 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
3340
3341 if (puk == null) {
3342 mSimCard.supplyPin(pin, callback);
3343 } else {
3344 mSimCard.supplyPuk(puk, pin, callback);
3345 }
3346
3347 while (!mDone) {
3348 try {
3349 Log.d(LOG_TAG, "wait for done");
3350 wait();
3351 } catch (InterruptedException e) {
3352 // Restore the interrupted status
3353 Thread.currentThread().interrupt();
3354 }
3355 }
3356 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07003357 int[] resultArray = new int[2];
3358 resultArray[0] = mResult;
3359 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00003360
3361 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00003362 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00003363 }
3364
Wink Saville9de0f752013-10-22 19:04:03 -07003365 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003366 }
3367 }
3368
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003369 /**
3370 * This method has been removed due to privacy and stability concerns.
3371 */
3372 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003373 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003374 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
3375 return;
Wink Saville36469e72014-06-11 15:17:00 -07003376 }
3377
Nathan Harold1f889d82020-06-04 17:05:26 -07003378 @Override
3379 public void updateServiceLocationWithPackageName(String callingPackage) {
3380 mApp.getSystemService(AppOpsManager.class)
3381 .checkPackage(Binder.getCallingUid(), callingPackage);
3382
Nathan Haroldf096d982020-11-18 17:18:06 -08003383 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07003384 if (targetSdk > android.os.Build.VERSION_CODES.R) {
3385 // Callers targeting S have no business invoking this method.
3386 return;
3387 }
3388
3389 LocationAccessPolicy.LocationPermissionResult locationResult =
3390 LocationAccessPolicy.checkLocationPermission(mApp,
3391 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3392 .setCallingPackage(callingPackage)
3393 .setCallingFeatureId(null)
3394 .setCallingPid(Binder.getCallingPid())
3395 .setCallingUid(Binder.getCallingUid())
3396 .setMethod("updateServiceLocation")
3397 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3398 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3399 .build());
3400 // Apps that lack location permission have no business calling this method;
3401 // however, because no permission was declared in the public API, denials must
3402 // all be "soft".
3403 switch (locationResult) {
3404 case DENIED_HARD: /* fall through */
3405 case DENIED_SOFT:
3406 return;
3407 }
3408
3409 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003410 final long identity = Binder.clearCallingIdentity();
3411 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07003412 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003413 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07003414 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003415 }
3416 } finally {
3417 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003418 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003419 }
3420
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003421 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003422 @Override
3423 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003424 return isRadioOnWithFeature(callingPackage, null);
3425 }
3426
3427
3428 @Override
3429 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
3430 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
3431 callingFeatureId);
3432 }
3433
3434 @Deprecated
3435 @Override
3436 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
3437 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07003438 }
3439
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003440 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003441 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
3442 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003443 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003444 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003445 return false;
3446 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003447
3448 final long identity = Binder.clearCallingIdentity();
3449 try {
3450 return isRadioOnForSubscriber(subId);
3451 } finally {
3452 Binder.restoreCallingIdentity(identity);
3453 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003454 }
3455
3456 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003457 final long identity = Binder.clearCallingIdentity();
3458 try {
3459 final Phone phone = getPhone(subId);
3460 if (phone != null) {
3461 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
3462 } else {
3463 return false;
3464 }
3465 } finally {
3466 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003467 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003468 }
3469
3470 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003471 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003472 }
Wink Saville36469e72014-06-11 15:17:00 -07003473
Wink Savilleb564aae2014-10-23 10:18:09 -07003474 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003475 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003476
3477 final long identity = Binder.clearCallingIdentity();
3478 try {
3479 final Phone phone = getPhone(subId);
3480 if (phone != null) {
3481 phone.setRadioPower(!isRadioOnForSubscriber(subId));
3482 }
3483 } finally {
3484 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003485 }
Wink Saville36469e72014-06-11 15:17:00 -07003486 }
3487
3488 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003489 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07003490 }
3491
Wink Savilleb564aae2014-10-23 10:18:09 -07003492 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07003493 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003494
3495 final long identity = Binder.clearCallingIdentity();
3496 try {
3497 final Phone phone = getPhone(subId);
3498 if (phone == null) {
3499 return false;
3500 }
3501 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
3502 toggleRadioOnOffForSubscriber(subId);
3503 }
3504 return true;
3505 } finally {
3506 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003507 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003508 }
Wink Saville36469e72014-06-11 15:17:00 -07003509
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003510 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08003511 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003512 /*
3513 * If any of the Radios are available, it will need to be
3514 * shutdown. So return true if any Radio is available.
3515 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003516 final long identity = Binder.clearCallingIdentity();
3517 try {
3518 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3519 Phone phone = PhoneFactory.getPhone(i);
3520 if (phone != null && phone.isRadioAvailable()) return true;
3521 }
3522 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3523 return false;
3524 } finally {
3525 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003526 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003527 }
3528
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003529 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003530 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003531 enforceModifyPermission();
3532
3533 final long identity = Binder.clearCallingIdentity();
3534 try {
3535 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3536 logv("Shutting down Phone " + i);
3537 shutdownRadioUsingPhoneId(i);
3538 }
3539 } finally {
3540 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003541 }
3542 }
3543
3544 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003545 Phone phone = PhoneFactory.getPhone(phoneId);
3546 if (phone != null && phone.isRadioAvailable()) {
3547 phone.shutdownRadio();
3548 }
3549 }
3550
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003551 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003552 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003553
Ling Ma83dc5ea2023-01-12 15:06:04 -08003554 if (!turnOn) {
3555 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3556 }
3557
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003558 final long identity = Binder.clearCallingIdentity();
3559 try {
3560 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3561 if (defaultPhone != null) {
3562 defaultPhone.setRadioPower(turnOn);
3563 return true;
3564 } else {
3565 loge("There's no default phone.");
3566 return false;
3567 }
3568 } finally {
3569 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003570 }
Wink Saville36469e72014-06-11 15:17:00 -07003571 }
3572
Wink Savilleb564aae2014-10-23 10:18:09 -07003573 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003574 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003575
Ling Ma83dc5ea2023-01-12 15:06:04 -08003576 if (!turnOn) {
3577 log("setRadioPowerForSubscriber off: subId=" + subId
3578 + ",callingPackage=" + getCurrentPackageName());
3579 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003580 final long identity = Binder.clearCallingIdentity();
3581 try {
3582 final Phone phone = getPhone(subId);
3583 if (phone != null) {
3584 phone.setRadioPower(turnOn);
3585 return true;
3586 } else {
3587 return false;
3588 }
3589 } finally {
3590 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003591 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003592 }
3593
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003594 /**
3595 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3596 * no reason to power it off. When any of the voters want to power it off, it will be turned
3597 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3598 * powering it off, and these radio off votes will be cleared.
3599 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3600 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3601 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3602 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3603 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3604 * check its vote.
3605 *
3606 * @param subId The subscription ID.
3607 * @param reason The reason for powering off radio.
3608 * @return true on success and false on failure.
3609 */
3610 public boolean requestRadioPowerOffForReason(int subId,
3611 @TelephonyManager.RadioPowerReason int reason) {
3612 enforceModifyPermission();
3613
Ling Ma83dc5ea2023-01-12 15:06:04 -08003614 log("requestRadioPowerOffForReason: subId=" + subId
3615 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003616 final long identity = Binder.clearCallingIdentity();
3617 try {
3618 final Phone phone = getPhone(subId);
3619 if (phone != null) {
3620 phone.setRadioPowerForReason(false, reason);
3621 return true;
3622 } else {
3623 return false;
3624 }
3625 } finally {
3626 Binder.restoreCallingIdentity(identity);
3627 }
3628 }
3629
3630 /**
3631 * Remove the vote on powering off the radio for a reason, as requested by
3632 * {@link requestRadioPowerOffForReason}.
3633 *
3634 * @param subId The subscription ID.
3635 * @param reason The reason for powering off radio.
3636 * @return true on success and false on failure.
3637 */
3638 public boolean clearRadioPowerOffForReason(int subId,
3639 @TelephonyManager.RadioPowerReason int reason) {
3640 enforceModifyPermission();
3641
3642 final long identity = Binder.clearCallingIdentity();
3643 try {
3644 final Phone phone = getPhone(subId);
3645 if (phone != null) {
3646 phone.setRadioPowerForReason(true, reason);
3647 return true;
3648 } else {
3649 return false;
3650 }
3651 } finally {
3652 Binder.restoreCallingIdentity(identity);
3653 }
3654 }
3655
3656 /**
3657 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3658 *
3659 * @param subId The subscription ID.
3660 * @param callingPackage The package making the call.
3661 * @param callingFeatureId The feature in the package.
3662 * @return List of reasons for powering off radio.
3663 */
3664 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3665 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3666
3667 final long identity = Binder.clearCallingIdentity();
3668 List result = new ArrayList();
3669 try {
3670 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3671 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3672 return result;
3673 }
3674
3675 final Phone phone = getPhone(subId);
3676 if (phone != null) {
3677 result.addAll(phone.getRadioPowerOffReasons());
3678 }
3679 } finally {
3680 Binder.restoreCallingIdentity(identity);
3681 }
3682 return result;
3683 }
3684
Wink Saville36469e72014-06-11 15:17:00 -07003685 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003686 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003687 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003688 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003689
3690 final long identity = Binder.clearCallingIdentity();
3691 try {
Jack Yu285100e2022-12-02 22:48:35 -08003692 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003693 final Phone phone = getPhone(subId);
3694 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003695 phone.getDataSettingsManager().setDataEnabled(
3696 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003697 return true;
3698 } else {
3699 return false;
3700 }
3701 } finally {
3702 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003703 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003704 }
3705
Wink Saville36469e72014-06-11 15:17:00 -07003706 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003707 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003708 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003709 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003710
3711 final long identity = Binder.clearCallingIdentity();
3712 try {
Jack Yu285100e2022-12-02 22:48:35 -08003713 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003714 final Phone phone = getPhone(subId);
3715 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003716 phone.getDataSettingsManager().setDataEnabled(
3717 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003718 return true;
3719 } else {
3720 return false;
3721 }
3722 } finally {
3723 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003724 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003725 }
3726
Sanket Padawe356d7632015-06-22 14:03:32 -07003727 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003728 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003729 final long identity = Binder.clearCallingIdentity();
3730 try {
3731 final Phone phone = getPhone(subId);
3732 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003733 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003734 } else {
3735 return false;
3736 }
3737 } finally {
3738 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003739 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003740 }
3741
3742 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003743 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003744 }
3745
pkanwarae03a6b2016-11-06 20:37:09 -08003746 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003747 enforceCallPermission();
3748
3749 final long identity = Binder.clearCallingIdentity();
3750 try {
3751 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3752 return;
3753 }
3754 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3755 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3756 } finally {
3757 Binder.restoreCallingIdentity(identity);
3758 }
pkanwar32d516d2016-10-14 19:37:38 -07003759 };
3760
Wink Savilleb564aae2014-10-23 10:18:09 -07003761 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003762 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003763
3764 final long identity = Binder.clearCallingIdentity();
3765 try {
3766 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3767 return false;
3768 }
3769 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3770 } finally {
3771 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003772 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003773 }
3774
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003775 /**
3776 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3777 * tag on getCallState Binder call.
3778 */
3779 @Deprecated
3780 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003781 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003782 if (CompatChanges.isChangeEnabled(
3783 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3784 Binder.getCallingUid())) {
3785 // Do not allow this API to be called on API version 31+, it should only be
3786 // called on old apps using this Binder call directly.
3787 throw new SecurityException("This method can only be used for applications "
3788 + "targeting API version 30 or less.");
3789 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003790 final long identity = Binder.clearCallingIdentity();
3791 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003792 Phone phone = getPhone(getDefaultSubscription());
3793 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3794 PhoneConstantConversions.convertCallState(phone.getState());
3795 } finally {
3796 Binder.restoreCallingIdentity(identity);
3797 }
3798 }
3799
3800 @Override
3801 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3802 if (CompatChanges.isChangeEnabled(
3803 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3804 Binder.getCallingUid())) {
3805 // Check READ_PHONE_STATE for API version 31+
3806 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3807 featureId, "getCallStateForSubscription")) {
3808 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3809 + "targeting API level 31+.");
3810 }
3811 }
3812 final long identity = Binder.clearCallingIdentity();
3813 try {
3814 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003815 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3816 PhoneConstantConversions.convertCallState(phone.getState());
3817 } finally {
3818 Binder.restoreCallingIdentity(identity);
3819 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003820 }
3821
Sanket Padawe356d7632015-06-22 14:03:32 -07003822 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003823 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003824 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003825 }
3826
3827 @Override
3828 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003829 final long identity = Binder.clearCallingIdentity();
3830 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003831 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003832 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003833 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003834 } else {
3835 return PhoneConstantConversions.convertDataState(
3836 PhoneConstants.DataState.DISCONNECTED);
3837 }
3838 } finally {
3839 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003840 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003841 }
3842
Sanket Padawe356d7632015-06-22 14:03:32 -07003843 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003844 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003845 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003846 }
3847
3848 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003849 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003850 final long identity = Binder.clearCallingIdentity();
3851 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003852 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003853 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003854 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003855 } else {
3856 return TelephonyManager.DATA_ACTIVITY_NONE;
3857 }
3858 } finally {
3859 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003860 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003861 }
3862
3863 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003864 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003865 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003866 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003867
3868 LocationAccessPolicy.LocationPermissionResult locationResult =
3869 LocationAccessPolicy.checkLocationPermission(mApp,
3870 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3871 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003872 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003873 .setCallingPid(Binder.getCallingPid())
3874 .setCallingUid(Binder.getCallingUid())
3875 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003876 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003877 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3878 .build());
3879 switch (locationResult) {
3880 case DENIED_HARD:
3881 throw new SecurityException("Not allowed to access cell location");
3882 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003883 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3884 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003885 }
3886
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003887 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003888 final long identity = Binder.clearCallingIdentity();
3889 try {
3890 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003891 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003892 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003893 } finally {
3894 Binder.restoreCallingIdentity(identity);
3895 }
Svetoslav64fad262015-04-14 14:35:21 -07003896 }
3897
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003898 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003899 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003900 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3901 // registered cell info, so return a NULL country instead.
3902 final long identity = Binder.clearCallingIdentity();
3903 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003904 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3905 // Get default phone in this case.
3906 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3907 }
Jack Yu285100e2022-12-02 22:48:35 -08003908 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003909 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003910 if (phone == null) return "";
3911 ServiceStateTracker sst = phone.getServiceStateTracker();
3912 if (sst == null) return "";
3913 LocaleTracker lt = sst.getLocaleTracker();
3914 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003915 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003916 } finally {
3917 Binder.restoreCallingIdentity(identity);
3918 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003919 }
3920
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003921 /**
3922 * This method was removed due to potential issues caused by performing partial
3923 * updates of service state, and lack of a credible use case.
3924 *
3925 * This has the ability to break the telephony implementation by disabling notification of
3926 * changes in device connectivity. DO NOT USE THIS!
3927 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003928 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003929 public void enableLocationUpdates() {
3930 mApp.enforceCallingOrSelfPermission(
3931 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003932 }
3933
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003934 /**
3935 * This method was removed due to potential issues caused by performing partial
3936 * updates of service state, and lack of a credible use case.
3937 *
3938 * This has the ability to break the telephony implementation by disabling notification of
3939 * changes in device connectivity. DO NOT USE THIS!
3940 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003941 @Override
3942 public void disableLocationUpdates() {
3943 mApp.enforceCallingOrSelfPermission(
3944 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003945 }
3946
3947 @Override
3948 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003949 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3950 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003951 try {
3952 mApp.getSystemService(AppOpsManager.class)
3953 .checkPackage(Binder.getCallingUid(), callingPackage);
3954 } catch (SecurityException e) {
3955 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3956 throw e;
3957 }
3958
Nathan Haroldf096d982020-11-18 17:18:06 -08003959 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003960 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3961 throw new SecurityException(
3962 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3963 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003964
Jordan Liu1617b712019-07-10 15:06:26 -07003965 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003966 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3967 return null;
3968 }
Svetoslav64fad262015-04-14 14:35:21 -07003969
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003970 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003971
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003972 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003973 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003974
Nathan Haroldf180aac2018-06-01 18:43:55 -07003975 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3976 for (CellInfo ci : info) {
3977 if (ci instanceof CellInfoGsm) {
3978 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3979 } else if (ci instanceof CellInfoWcdma) {
3980 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3981 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003982 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003983 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003984 }
3985
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003986 private List<CellInfo> getCachedCellInfo() {
3987 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3988 for (Phone phone : PhoneFactory.getPhones()) {
3989 List<CellInfo> info = phone.getAllCellInfo();
3990 if (info != null) cellInfos.addAll(info);
3991 }
3992 return cellInfos;
3993 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003994
3995 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003996 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003997 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003998 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003999
4000 LocationAccessPolicy.LocationPermissionResult locationResult =
4001 LocationAccessPolicy.checkLocationPermission(mApp,
4002 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4003 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004004 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004005 .setCallingPid(Binder.getCallingPid())
4006 .setCallingUid(Binder.getCallingUid())
4007 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08004008 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08004009 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4010 .build());
4011 switch (locationResult) {
4012 case DENIED_HARD:
4013 throw new SecurityException("Not allowed to access cell info");
4014 case DENIED_SOFT:
4015 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004016 }
4017
Nathan Haroldf096d982020-11-18 17:18:06 -08004018 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004019 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
4020 return getCachedCellInfo();
4021 }
4022
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07004023 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004024 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004025 final long identity = Binder.clearCallingIdentity();
4026 try {
4027 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
4028 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07004029 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07004030 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004031 if (info != null) cellInfos.addAll(info);
4032 }
4033 return cellInfos;
4034 } finally {
4035 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004036 }
4037 }
4038
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07004039 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004040 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
4041 String callingFeatureId) {
4042 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
4043 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004044 }
4045
4046 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004047 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
4048 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004049 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004050 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004051 }
4052
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004053 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
4054 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004055 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004056 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08004057
4058 LocationAccessPolicy.LocationPermissionResult locationResult =
4059 LocationAccessPolicy.checkLocationPermission(mApp,
4060 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4061 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004062 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004063 .setCallingPid(Binder.getCallingPid())
4064 .setCallingUid(Binder.getCallingUid())
4065 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07004066 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
4067 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08004068 .build());
4069 switch (locationResult) {
4070 case DENIED_HARD:
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 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004076 throw new SecurityException("Not allowed to access cell info");
4077 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08004078 if (TelephonyPermissions
4079 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07004080 // Safetynet logging for b/154934934
4081 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
4082 }
Nathan Harold5320c422019-05-09 10:26:08 -07004083 try {
4084 cb.onCellInfo(new ArrayList<CellInfo>());
4085 } catch (RemoteException re) {
4086 // Drop without consequences
4087 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004088 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004089 }
4090
Nathan Harolda939a962019-05-09 10:13:47 -07004091
4092 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004093 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
4094
4095 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
4096 }
4097
4098 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00004099 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08004100 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004101 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004102
4103 final long identity = Binder.clearCallingIdentity();
4104 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00004105 Phone phone = getPhone(subId);
4106 if (phone == null) {
4107 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
4108 } else {
4109 phone.setCellInfoListRate(rateInMillis, workSource);
4110 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004111 } finally {
4112 Binder.restoreCallingIdentity(identity);
4113 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004114 }
4115
Shishir Agrawala9f32182016-04-12 12:00:16 -07004116 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004117 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004118 Phone phone = PhoneFactory.getPhone(slotIndex);
4119 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004120 return null;
4121 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004122 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07004123 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07004124 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004125 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004126 return null;
4127 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004128
4129 final long identity = Binder.clearCallingIdentity();
4130 try {
4131 return phone.getImei();
4132 } finally {
4133 Binder.restoreCallingIdentity(identity);
4134 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07004135 }
4136
4137 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00004138 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
4139 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
4140 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
4141 callingFeatureId, "getPrimaryImei")) {
4142 throw new SecurityException("Caller does not have permission");
4143 }
4144 final long identity = Binder.clearCallingIdentity();
4145 try {
4146 for (Phone phone : PhoneFactory.getPhones()) {
4147 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
4148 return phone.getImei();
4149 }
4150 }
4151 throw new UnsupportedOperationException("Operation not supported");
4152 } finally {
4153 Binder.restoreCallingIdentity(identity);
4154 }
4155 }
4156
4157 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00004158 public String getTypeAllocationCodeForSlot(int slotIndex) {
4159 Phone phone = PhoneFactory.getPhone(slotIndex);
4160 String tac = null;
4161 if (phone != null) {
4162 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07004163 try {
4164 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
4165 } catch (IndexOutOfBoundsException e) {
4166 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
4167 return null;
4168 }
David Kelly5e06a7f2018-03-12 14:10:59 +00004169 }
4170 return tac;
4171 }
4172
4173 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004174 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004175 try {
4176 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4177 } catch (SecurityException se) {
4178 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
4179 throw new SecurityException("Package " + callingPackage + " does not belong to "
4180 + Binder.getCallingUid());
4181 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004182 Phone phone = PhoneFactory.getPhone(slotIndex);
4183 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07004184 return null;
4185 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004186
Jeff Davidson913390f2018-02-23 17:11:49 -08004187 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07004188 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004189 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004190 return null;
4191 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004192
4193 final long identity = Binder.clearCallingIdentity();
4194 try {
4195 return phone.getMeid();
4196 } finally {
4197 Binder.restoreCallingIdentity(identity);
4198 }
Jack Yu2af8d712017-03-15 17:14:14 -07004199 }
4200
4201 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00004202 public String getManufacturerCodeForSlot(int slotIndex) {
4203 Phone phone = PhoneFactory.getPhone(slotIndex);
4204 String manufacturerCode = null;
4205 if (phone != null) {
4206 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07004207 try {
4208 manufacturerCode =
4209 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
4210 } catch (IndexOutOfBoundsException e) {
4211 Log.e(LOG_TAG, "MEID length shorter than upper index.");
4212 return null;
4213 }
David Kelly5e06a7f2018-03-12 14:10:59 +00004214 }
4215 return manufacturerCode;
4216 }
4217
4218 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004219 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
4220 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004221 Phone phone = PhoneFactory.getPhone(slotIndex);
4222 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004223 return null;
4224 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004225 int subId = phone.getSubId();
4226 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004227 mApp, subId, callingPackage, callingFeatureId,
4228 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004229 return null;
4230 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004231
4232 final long identity = Binder.clearCallingIdentity();
4233 try {
4234 return phone.getDeviceSvn();
4235 } finally {
4236 Binder.restoreCallingIdentity(identity);
4237 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07004238 }
4239
fionaxu43304da2017-11-27 22:51:16 -08004240 @Override
4241 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004242 final long identity = Binder.clearCallingIdentity();
4243 try {
4244 final Phone phone = getPhone(subId);
4245 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
4246 } finally {
4247 Binder.restoreCallingIdentity(identity);
4248 }
fionaxu43304da2017-11-27 22:51:16 -08004249 }
4250
4251 @Override
4252 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004253 final long identity = Binder.clearCallingIdentity();
4254 try {
4255 final Phone phone = getPhone(subId);
4256 return phone == null ? null : phone.getCarrierName();
4257 } finally {
4258 Binder.restoreCallingIdentity(identity);
4259 }
fionaxu43304da2017-11-27 22:51:16 -08004260 }
4261
calvinpanffe225e2018-11-01 19:43:06 +08004262 @Override
chen xu0026ca62019-03-06 15:28:50 -08004263 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08004264 final long identity = Binder.clearCallingIdentity();
4265 try {
4266 final Phone phone = getPhone(subId);
4267 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08004268 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08004269 } finally {
4270 Binder.restoreCallingIdentity(identity);
4271 }
4272 }
4273
4274 @Override
chen xu0026ca62019-03-06 15:28:50 -08004275 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08004276 final long identity = Binder.clearCallingIdentity();
4277 try {
4278 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08004279 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08004280 } finally {
4281 Binder.restoreCallingIdentity(identity);
4282 }
4283 }
4284
chen xu651eec72018-11-11 19:03:44 -08004285 @Override
chen xu864e11c2018-12-06 22:10:03 -08004286 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
4287 if (!isSubscriptionMccMnc) {
4288 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
4289 }
chen xu651eec72018-11-11 19:03:44 -08004290 final Phone phone = PhoneFactory.getPhone(slotIndex);
4291 if (phone == null) {
4292 return TelephonyManager.UNKNOWN_CARRIER_ID;
4293 }
4294 final long identity = Binder.clearCallingIdentity();
4295 try {
4296 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
4297 } finally {
4298 Binder.restoreCallingIdentity(identity);
4299 }
4300 }
4301
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004302 //
4303 // Internal helper methods.
4304 //
4305
Sanket Padaweee13a9b2016-03-08 17:30:28 -08004306 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07004307 * Make sure the caller is the calling package itself
4308 *
4309 * @throws SecurityException if the caller is not the calling package
4310 */
4311 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
4312 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07004313 PackageManager pm = mApp.getBaseContext().createContextAsUser(
4314 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07004315 try {
Grace Jiadbefca02021-04-26 15:13:31 -07004316 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07004317 } catch (PackageManager.NameNotFoundException e) {
4318 // packageUid is -1
4319 }
4320 if (packageUid != callingUid) {
4321 throw new SecurityException(message + ": Package " + callingPackage
4322 + " does not belong to " + callingUid);
4323 }
4324 }
4325
4326 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004327 * Make sure the caller has the MODIFY_PHONE_STATE permission.
4328 *
4329 * @throws SecurityException if the caller does not have the required permission
4330 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004331 @VisibleForTesting
4332 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004333 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
4334 }
4335
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004336 /**
arunvoddud7401012022-12-15 16:08:12 +00004337 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004338 *
4339 * @throws SecurityException if the caller does not have the required permission
4340 */
4341 @VisibleForTesting
4342 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00004343 enforceReadPermission(null);
4344 }
4345
4346 /**
4347 * Make sure the caller has the READ_PHONE_STATE permissions.
4348 *
4349 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
4350 */
4351 @VisibleForTesting
4352 public void enforceReadPermission(String msg) {
4353 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004354 }
4355
Shuo Qian3b6ee772019-11-13 17:43:31 -08004356 private void enforceActiveEmergencySessionPermission() {
4357 mApp.enforceCallingOrSelfPermission(
4358 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
4359 }
4360
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004361 /**
4362 * Make sure the caller has the CALL_PHONE permission.
4363 *
4364 * @throws SecurityException if the caller does not have the required permission
4365 */
4366 private void enforceCallPermission() {
4367 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
4368 }
4369
paulhu5a773602019-08-23 19:17:33 +08004370 private void enforceSettingsPermission() {
4371 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004372 }
4373
Michele Berionne5e411512020-11-13 02:36:59 +00004374 private void enforceRebootPermission() {
4375 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
4376 }
4377
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00004378 /**
4379 * Make sure the caller has SATELLITE_COMMUNICATION permission.
4380 * @param message - log message to print.
4381 * @throws SecurityException if the caller does not have the required permission
4382 */
4383 private void enforceSatelliteCommunicationPermission(String message) {
4384 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
4385 }
4386
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004387 private String createTelUrl(String number) {
4388 if (TextUtils.isEmpty(number)) {
4389 return null;
4390 }
4391
Jake Hambye994d462014-02-03 13:10:13 -08004392 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004393 }
4394
Ihab Awadf9e92732013-12-05 18:02:52 -08004395 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08004396 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004397 }
4398
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07004399 private static void logv(String msg) {
4400 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
4401 }
4402
Ihab Awadf9e92732013-12-05 18:02:52 -08004403 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004404 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
4405 }
4406
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004407 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004408 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07004409 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07004410 }
4411
Sanket Padawe356d7632015-06-22 14:03:32 -07004412 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004413 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004414 final long identity = Binder.clearCallingIdentity();
4415 try {
4416 final Phone phone = PhoneFactory.getPhone(slotIndex);
4417 if (phone == null) {
4418 return PhoneConstants.PHONE_TYPE_NONE;
4419 } else {
4420 return phone.getPhoneType();
4421 }
4422 } finally {
4423 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004424 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004425 }
4426
4427 /**
4428 * Returns the CDMA ERI icon index to display
4429 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004430 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004431 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
4432 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4433 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004434 }
4435
Sanket Padawe356d7632015-06-22 14:03:32 -07004436 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004437 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4438 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004439 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004440 mApp, subId, callingPackage, callingFeatureId,
4441 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004442 return -1;
4443 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004444
4445 final long identity = Binder.clearCallingIdentity();
4446 try {
4447 final Phone phone = getPhone(subId);
4448 if (phone != null) {
4449 return phone.getCdmaEriIconIndex();
4450 } else {
4451 return -1;
4452 }
4453 } finally {
4454 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004455 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004456 }
4457
4458 /**
4459 * Returns the CDMA ERI icon mode,
4460 * 0 - ON
4461 * 1 - FLASHING
4462 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004463 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004464 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4465 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4466 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004467 }
4468
Sanket Padawe356d7632015-06-22 14:03:32 -07004469 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004470 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4471 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004472 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004473 mApp, subId, callingPackage, callingFeatureId,
4474 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004475 return -1;
4476 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004477
4478 final long identity = Binder.clearCallingIdentity();
4479 try {
4480 final Phone phone = getPhone(subId);
4481 if (phone != null) {
4482 return phone.getCdmaEriIconMode();
4483 } else {
4484 return -1;
4485 }
4486 } finally {
4487 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004488 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004489 }
4490
4491 /**
4492 * Returns the CDMA ERI text,
4493 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004494 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004495 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4496 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4497 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004498 }
4499
Sanket Padawe356d7632015-06-22 14:03:32 -07004500 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004501 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4502 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004503 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004504 mApp, subId, callingPackage, callingFeatureId,
4505 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004506 return null;
4507 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004508
4509 final long identity = Binder.clearCallingIdentity();
4510 try {
4511 final Phone phone = getPhone(subId);
4512 if (phone != null) {
4513 return phone.getCdmaEriText();
4514 } else {
4515 return null;
4516 }
4517 } finally {
4518 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004519 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004520 }
4521
4522 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004523 * Returns the CDMA MDN.
4524 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004525 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004526 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004527 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4528 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004529
4530 final long identity = Binder.clearCallingIdentity();
4531 try {
4532 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004533 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004534 return phone.getLine1Number();
4535 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004536 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004537 return null;
4538 }
4539 } finally {
4540 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004541 }
4542 }
4543
4544 /**
4545 * Returns the CDMA MIN.
4546 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004547 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004548 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004549 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4550 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004551
4552 final long identity = Binder.clearCallingIdentity();
4553 try {
4554 final Phone phone = getPhone(subId);
4555 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4556 return phone.getCdmaMin();
4557 } else {
4558 return null;
4559 }
4560 } finally {
4561 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004562 }
4563 }
4564
Hall Liud892bec2018-11-30 14:51:45 -08004565 @Override
4566 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4567 INumberVerificationCallback callback, String callingPackage) {
4568 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4569 != PERMISSION_GRANTED) {
4570 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4571 }
4572 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4573
4574 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4575 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004576 throw new SecurityException("Calling package must be configured in the device config: "
4577 + "calling package: " + callingPackage
4578 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004579 }
4580
4581 if (range == null) {
4582 throw new NullPointerException("Range must be non-null");
4583 }
4584
4585 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004586 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004587
4588 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4589 }
4590
Junda Liuca05d5d2014-08-14 22:36:34 -07004591 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004592 * Returns true if CDMA provisioning needs to run.
4593 */
4594 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004595 final long identity = Binder.clearCallingIdentity();
4596 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004597 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004598 } finally {
4599 Binder.restoreCallingIdentity(identity);
4600 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004601 }
4602
4603 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004604 * Sets the voice mail number of a given subId.
4605 */
4606 @Override
4607 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004608 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4609 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004610
4611 final long identity = Binder.clearCallingIdentity();
4612 try {
4613 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4614 new Pair<String, String>(alphaTag, number), new Integer(subId));
4615 return success;
4616 } finally {
4617 Binder.restoreCallingIdentity(identity);
4618 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004619 }
4620
Ta-wei Yen87c49842016-05-13 21:19:52 -07004621 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004622 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4623 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004624 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4625 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004626 if (!TextUtils.equals(callingPackage, systemDialer)) {
4627 throw new SecurityException("caller must be system dialer");
4628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004629
4630 final long identity = Binder.clearCallingIdentity();
4631 try {
4632 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4633 if (phoneAccountHandle == null) {
4634 return null;
4635 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004636 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004637 } finally {
4638 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004639 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004640 }
4641
4642 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004643 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4644 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004645 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004646 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004647 mApp, subId, callingPackage, callingFeatureId,
4648 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004649 return null;
4650 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004651
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004652 final long identity = Binder.clearCallingIdentity();
4653 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004654 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004655 } finally {
4656 Binder.restoreCallingIdentity(identity);
4657 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004658 }
4659
4660 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004661 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4662 VisualVoicemailSmsFilterSettings settings) {
4663 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004664
4665 final long identity = Binder.clearCallingIdentity();
4666 try {
4667 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004668 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004669 } finally {
4670 Binder.restoreCallingIdentity(identity);
4671 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004672 }
4673
4674 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004675 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4676 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004677
4678 final long identity = Binder.clearCallingIdentity();
4679 try {
4680 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004681 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004682 } finally {
4683 Binder.restoreCallingIdentity(identity);
4684 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004685 }
4686
4687 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004688 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4689 String callingPackage, int subId) {
4690 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004691
4692 final long identity = Binder.clearCallingIdentity();
4693 try {
4694 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004695 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004696 } finally {
4697 Binder.restoreCallingIdentity(identity);
4698 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004699 }
4700
4701 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004702 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004703 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004704
4705 final long identity = Binder.clearCallingIdentity();
4706 try {
4707 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004708 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004709 } finally {
4710 Binder.restoreCallingIdentity(identity);
4711 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004712 }
4713
4714 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004715 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4716 String callingAttributionTag, int subId, String number, int port, String text,
4717 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004718 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004719 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004720 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004721 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004722 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4723 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004724 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004725
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004726 /**
fionaxu0152e512016-11-14 13:36:14 -08004727 * Sets the voice activation state of a given subId.
4728 */
4729 @Override
4730 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004731 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4732 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004733
4734 final long identity = Binder.clearCallingIdentity();
4735 try {
4736 final Phone phone = getPhone(subId);
4737 if (phone != null) {
4738 phone.setVoiceActivationState(activationState);
4739 } else {
4740 loge("setVoiceActivationState fails with invalid subId: " + subId);
4741 }
4742 } finally {
4743 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004744 }
4745 }
4746
4747 /**
4748 * Sets the data activation state of a given subId.
4749 */
4750 @Override
4751 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004752 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4753 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004754
4755 final long identity = Binder.clearCallingIdentity();
4756 try {
4757 final Phone phone = getPhone(subId);
4758 if (phone != null) {
4759 phone.setDataActivationState(activationState);
4760 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004761 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004762 }
4763 } finally {
4764 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004765 }
4766 }
4767
4768 /**
4769 * Returns the voice activation state of a given subId.
4770 */
4771 @Override
4772 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004773 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004774
fionaxu0152e512016-11-14 13:36:14 -08004775 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004776 final long identity = Binder.clearCallingIdentity();
4777 try {
4778 if (phone != null) {
4779 return phone.getVoiceActivationState();
4780 } else {
4781 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4782 }
4783 } finally {
4784 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004785 }
4786 }
4787
4788 /**
4789 * Returns the data activation state of a given subId.
4790 */
4791 @Override
4792 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004793 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004794
fionaxu0152e512016-11-14 13:36:14 -08004795 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004796 final long identity = Binder.clearCallingIdentity();
4797 try {
4798 if (phone != null) {
4799 return phone.getDataActivationState();
4800 } else {
4801 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4802 }
4803 } finally {
4804 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004805 }
4806 }
4807
4808 /**
Wink Saville36469e72014-06-11 15:17:00 -07004809 * Returns the unread count of voicemails for a subId
4810 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004811 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004812 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4813 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004814 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004815 mApp, subId, callingPackage, callingFeatureId,
4816 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004817 return 0;
4818 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004819 final long identity = Binder.clearCallingIdentity();
4820 try {
4821 final Phone phone = getPhone(subId);
4822 if (phone != null) {
4823 return phone.getVoiceMessageCount();
4824 } else {
4825 return 0;
4826 }
4827 } finally {
4828 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004829 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004830 }
4831
4832 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004833 * returns true, if the device is in a state where both voice and data
4834 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004835 */
4836 @Override
4837 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004838 final long identity = Binder.clearCallingIdentity();
4839 try {
4840 final Phone phone = getPhone(subId);
4841 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4842 } finally {
4843 Binder.restoreCallingIdentity(identity);
4844 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004845 }
4846
4847 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004848 * Send the dialer code if called from the current default dialer or the caller has
4849 * carrier privilege.
4850 * @param inputCode The dialer code to send
4851 */
4852 @Override
4853 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004854 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004855 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004856 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4857 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004858 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004859 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004860 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004861 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004862
4863 final long identity = Binder.clearCallingIdentity();
4864 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004865 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004866 } finally {
4867 Binder.restoreCallingIdentity(identity);
4868 }
fionaxu235cc5e2017-03-06 22:25:57 -08004869 }
4870
Pengquan Menga1bb6272018-09-06 09:59:22 -07004871 @Override
4872 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004873 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004874 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4875 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08004876 final long identity = Binder.clearCallingIdentity();
4877 try {
4878 if (!isActiveSubscription(subId)) {
4879 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4880 }
4881 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4882 } finally {
4883 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004884 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004885 }
4886
Brad Ebinger35c841c2018-10-01 10:40:55 -07004887 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004888 public boolean isInEmergencySmsMode() {
4889 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4890 final long identity = Binder.clearCallingIdentity();
4891 try {
4892 for (Phone phone : PhoneFactory.getPhones()) {
4893 if (phone.isInEmergencySmsMode()) {
4894 return true;
4895 }
4896 }
4897 } finally {
4898 Binder.restoreCallingIdentity(identity);
4899 }
4900 return false;
4901 }
4902
shilu366312e2019-12-17 09:28:10 -08004903 /**
4904 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4905 * @param subId The subscription to use to check the configuration.
4906 * @param c The callback that will be used to send the result.
4907 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004908 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004909 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4910 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004911 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004912 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004913
4914 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4915 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4916 "IMS not available on device.");
4917 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004918 final long token = Binder.clearCallingIdentity();
4919 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004920 int slotId = getSlotIndexOrException(subId);
4921 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004922
4923 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4924 if (controller != null) {
4925 ImsManager imsManager = controller.getImsManager(subId);
4926 if (imsManager != null) {
4927 imsManager.addRegistrationCallbackForSubscription(c, subId);
4928 } else {
4929 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4930 }
4931 } else {
4932 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4933 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004934 } catch (ImsException e) {
4935 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004936 } finally {
4937 Binder.restoreCallingIdentity(token);
4938 }
4939 }
4940
shilu366312e2019-12-17 09:28:10 -08004941 /**
4942 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4943 * @param subId The subscription to use to check the configuration.
4944 * @param c The callback that will be used to send the result.
4945 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004946 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004947 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004948 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004949 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004950 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4951 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4952 }
Meng Wangafbc5852019-09-19 17:37:13 -07004953 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004954
Meng Wangafbc5852019-09-19 17:37:13 -07004955 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004956 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4957 if (controller != null) {
4958 ImsManager imsManager = controller.getImsManager(subId);
4959 if (imsManager != null) {
4960 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4961 } else {
4962 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4963 + "is inactive, ignoring unregister.");
4964 // If the ImsManager is not valid, just return, since the callback
4965 // will already have been removed internally.
4966 }
4967 }
Meng Wangafbc5852019-09-19 17:37:13 -07004968 } finally {
4969 Binder.restoreCallingIdentity(token);
4970 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004971 }
4972
Brad Ebingera34a6c22019-10-22 17:36:18 -07004973 /**
4974 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4975 */
4976 @Override
4977 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4978 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4979 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4980 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4981 "IMS not available on device.");
4982 }
4983 final long token = Binder.clearCallingIdentity();
4984 try {
4985 Phone phone = getPhone(subId);
4986 if (phone == null) {
4987 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4988 + subId + "'");
4989 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4990 }
4991 phone.getImsRegistrationState(regState -> {
4992 try {
4993 consumer.accept((regState == null)
4994 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4995 } catch (RemoteException e) {
4996 // Ignore if the remote process is no longer available to call back.
4997 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4998 }
4999 });
5000 } finally {
5001 Binder.restoreCallingIdentity(token);
5002 }
5003 }
5004
5005 /**
5006 * Get the transport type for the IMS service registration state.
5007 */
5008 @Override
5009 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07005010 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005011 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07005012 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5013 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5014 "IMS not available on device.");
5015 }
5016 final long token = Binder.clearCallingIdentity();
5017 try {
5018 Phone phone = getPhone(subId);
5019 if (phone == null) {
5020 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
5021 + subId + "'");
5022 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5023 }
5024 phone.getImsRegistrationTech(regTech -> {
5025 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
5026 int regTechConverted = (regTech == null)
5027 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
5028 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
5029 regTechConverted);
5030 try {
5031 consumer.accept(regTechConverted);
5032 } catch (RemoteException e) {
5033 // Ignore if the remote process is no longer available to call back.
5034 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
5035 }
5036 });
5037 } finally {
5038 Binder.restoreCallingIdentity(token);
5039 }
5040 }
5041
shilu366312e2019-12-17 09:28:10 -08005042 /**
5043 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5044 * @param subId The subscription to use to check the configuration.
5045 * @param c The callback that will be used to send the result.
5046 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005047 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005048 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
5049 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07005050 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005051 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00005052 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5053 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5054 "IMS not available on device.");
5055 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07005056 final long token = Binder.clearCallingIdentity();
5057 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005058 int slotId = getSlotIndexOrException(subId);
5059 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005060
5061 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5062 if (controller != null) {
5063 ImsManager imsManager = controller.getImsManager(subId);
5064 if (imsManager != null) {
5065 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
5066 } else {
5067 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5068 }
5069 } else {
5070 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5071 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005072 } catch (ImsException e) {
5073 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005074 } finally {
5075 Binder.restoreCallingIdentity(token);
5076 }
5077 }
5078
shilu366312e2019-12-17 09:28:10 -08005079 /**
5080 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5081 * @param subId The subscription to use to check the configuration.
5082 * @param c The callback that will be used to send the result.
5083 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005084 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005085 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07005086 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005087 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005088 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5089 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5090 }
Meng Wangafbc5852019-09-19 17:37:13 -07005091
5092 final long token = Binder.clearCallingIdentity();
5093 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005094 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5095 if (controller != null) {
5096 ImsManager imsManager = controller.getImsManager(subId);
5097 if (imsManager != null) {
5098 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
5099 } else {
5100 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
5101 + " is inactive, ignoring unregister.");
5102 // If the ImsManager is not valid, just return, since the callback
5103 // will already have been removed internally.
5104 }
5105 }
Meng Wangafbc5852019-09-19 17:37:13 -07005106 } finally {
5107 Binder.restoreCallingIdentity(token);
5108 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07005109 }
5110
5111 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005112 public boolean isCapable(int subId, int capability, int regTech) {
5113 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005114 final long token = Binder.clearCallingIdentity();
5115 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005116 int slotId = getSlotIndexOrException(subId);
5117 verifyImsMmTelConfiguredOrThrow(slotId);
5118 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
5119 } catch (com.android.ims.ImsException e) {
5120 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
5121 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005122 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08005123 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
5124 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07005125 } finally {
5126 Binder.restoreCallingIdentity(token);
5127 }
5128 }
5129
5130 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005131 public boolean isAvailable(int subId, int capability, int regTech) {
5132 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005133 final long token = Binder.clearCallingIdentity();
5134 try {
5135 Phone phone = getPhone(subId);
5136 if (phone == null) return false;
5137 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07005138 } catch (com.android.ims.ImsException e) {
5139 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
5140 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07005141 } finally {
5142 Binder.restoreCallingIdentity(token);
5143 }
5144 }
5145
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005146 /**
5147 * Determines if the MmTel feature capability is supported by the carrier configuration for this
5148 * subscription.
5149 * @param subId The subscription to use to check the configuration.
5150 * @param callback The callback that will be used to send the result.
5151 * @param capability The MmTelFeature capability that will be used to send the result.
5152 * @param transportType The transport type of the MmTelFeature capability.
5153 */
5154 @Override
5155 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
5156 int transportType) {
5157 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00005158 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5159 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5160 "IMS not available on device.");
5161 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005162 final long token = Binder.clearCallingIdentity();
5163 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005164 int slotId = getSlotIndex(subId);
5165 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5166 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
5167 + subId + "'");
5168 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5169 }
5170 verifyImsMmTelConfiguredOrThrow(slotId);
5171 ImsManager.getInstance(mApp, slotId).isSupported(capability,
5172 transportType, aBoolean -> {
5173 try {
5174 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
5175 } catch (RemoteException e) {
5176 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
5177 + "running. Ignore");
5178 }
5179 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005180 } catch (ImsException e) {
5181 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005182 } finally {
5183 Binder.restoreCallingIdentity(token);
5184 }
5185 }
5186
shilu366312e2019-12-17 09:28:10 -08005187 /**
5188 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5189 * @param subId The subscription to use to check the configuration.
5190 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005191 @Override
5192 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005193 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005194 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08005195
Brad Ebinger35c841c2018-10-01 10:40:55 -07005196 final long token = Binder.clearCallingIdentity();
5197 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005198 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005199 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005200 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005201 } catch (ImsException e) {
5202 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005203 } finally {
5204 Binder.restoreCallingIdentity(token);
5205 }
5206 }
5207
5208 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005209 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005211 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005212 final long identity = Binder.clearCallingIdentity();
5213 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005214 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005215 // This setting doesn't require an active ImsService connection, so do not verify. The
5216 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005217 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005218 } catch (ImsException e) {
5219 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005220 } finally {
5221 Binder.restoreCallingIdentity(identity);
5222 }
5223 }
5224
shilu366312e2019-12-17 09:28:10 -08005225 /**
5226 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5227 * @param subId The subscription to use to check the configuration.
5228 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005229 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005230 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005231 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005232 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005233 final long identity = Binder.clearCallingIdentity();
5234 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005235 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005236 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005237 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005238 } catch (ImsException e) {
5239 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005240 } finally {
5241 Binder.restoreCallingIdentity(identity);
5242 }
5243 }
5244
5245 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005246 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005247 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005248 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005249 final long identity = Binder.clearCallingIdentity();
5250 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005251 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005252 // This setting doesn't require an active ImsService connection, so do not verify. The
5253 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005254 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005255 } catch (ImsException e) {
5256 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005257 } finally {
5258 Binder.restoreCallingIdentity(identity);
5259 }
5260 }
5261
shilu366312e2019-12-17 09:28:10 -08005262 /**
5263 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5264 * @param subId The subscription to use to check the configuration.
5265 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005266 @Override
5267 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005268 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005269 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005270 final long identity = Binder.clearCallingIdentity();
5271 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005272 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005273 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005274 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005275 } catch (ImsException e) {
5276 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005277 } finally {
5278 Binder.restoreCallingIdentity(identity);
5279 }
5280 }
5281
5282 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005283 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005284 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005285 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005286 final long identity = Binder.clearCallingIdentity();
5287 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005288 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005289 // This setting doesn't require an active ImsService connection, so do not verify. The
5290 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005291 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005292 } catch (ImsException e) {
5293 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005294 } finally {
5295 Binder.restoreCallingIdentity(identity);
5296 }
5297 }
5298
shilu366312e2019-12-17 09:28:10 -08005299 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005300 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5301 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5302 * @param subId The subscription to use to check the configuration.
5303 */
5304 @Override
5305 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005306 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005307 mApp, subId, "isCrossSimCallingEnabledByUser");
5308 final long identity = Binder.clearCallingIdentity();
5309 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005310 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005311 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005312 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005313 } catch (ImsException e) {
5314 throw new ServiceSpecificException(e.getCode());
5315 } finally {
5316 Binder.restoreCallingIdentity(identity);
5317 }
5318 }
5319
5320 /**
5321 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5322 * Requires MODIFY_PHONE_STATE permission.
5323 * @param subId The subscription to use to check the configuration.
5324 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5325 * false otherwise
5326 */
5327 @Override
5328 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5330 "setCrossSimCallingEnabled");
5331 final long identity = Binder.clearCallingIdentity();
5332 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005333 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005334 // This setting doesn't require an active ImsService connection, so do not verify. The
5335 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005336 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005337 } catch (ImsException e) {
5338 throw new ServiceSpecificException(e.getCode());
5339 } finally {
5340 Binder.restoreCallingIdentity(identity);
5341 }
5342 }
5343
5344 /**
shilu366312e2019-12-17 09:28:10 -08005345 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5346 * @param subId The subscription to use to check the configuration.
5347 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005348 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005349
Brad Ebinger35c841c2018-10-01 10:40:55 -07005350 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005351 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005352 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005353 final long identity = Binder.clearCallingIdentity();
5354 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005355 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005356 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005357 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005358 } catch (ImsException e) {
5359 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005360 } finally {
5361 Binder.restoreCallingIdentity(identity);
5362 }
5363 }
5364
5365 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005366 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005367 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005368 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005369 final long identity = Binder.clearCallingIdentity();
5370 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005371 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005372 // This setting doesn't require an active ImsService connection, so do not verify. The
5373 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005374 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005375 } catch (ImsException e) {
5376 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005377 } finally {
5378 Binder.restoreCallingIdentity(identity);
5379 }
5380 }
5381
5382 @Override
5383 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5384 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5385 "setVoWiFiNonPersistent");
5386 final long identity = Binder.clearCallingIdentity();
5387 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005388 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005389 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005390 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005391 } catch (ImsException e) {
5392 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005393 } finally {
5394 Binder.restoreCallingIdentity(identity);
5395 }
5396 }
5397
shilu366312e2019-12-17 09:28:10 -08005398 /**
5399 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5400 * @param subId The subscription to use to check the configuration.
5401 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005402 @Override
5403 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005404 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005405 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005406 final long identity = Binder.clearCallingIdentity();
5407 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005408 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005409 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005410 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005411 } catch (ImsException e) {
5412 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005413 } finally {
5414 Binder.restoreCallingIdentity(identity);
5415 }
5416 }
5417
5418 @Override
5419 public void setVoWiFiModeSetting(int subId, int mode) {
5420 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5421 "setVoWiFiModeSetting");
5422 final long identity = Binder.clearCallingIdentity();
5423 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005424 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005425 // This setting doesn't require an active ImsService connection, so do not verify. The
5426 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005427 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005428 } catch (ImsException e) {
5429 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005430 } finally {
5431 Binder.restoreCallingIdentity(identity);
5432 }
5433 }
5434
5435 @Override
5436 public int getVoWiFiRoamingModeSetting(int subId) {
5437 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
5438 final long identity = Binder.clearCallingIdentity();
5439 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005440 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005441 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005442 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005443 } catch (ImsException e) {
5444 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005445 } finally {
5446 Binder.restoreCallingIdentity(identity);
5447 }
5448 }
5449
5450 @Override
5451 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5452 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5453 "setVoWiFiRoamingModeSetting");
5454 final long identity = Binder.clearCallingIdentity();
5455 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005456 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005457 // This setting doesn't require an active ImsService connection, so do not verify. The
5458 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005459 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005460 } catch (ImsException e) {
5461 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005462 } finally {
5463 Binder.restoreCallingIdentity(identity);
5464 }
5465 }
5466
5467 @Override
5468 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5469 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5470 "setRttCapabilityEnabled");
5471 final long identity = Binder.clearCallingIdentity();
5472 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005473 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005474 // This setting doesn't require an active ImsService connection, so do not verify. The
5475 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005476 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005477 } catch (ImsException e) {
5478 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005479 } finally {
5480 Binder.restoreCallingIdentity(identity);
5481 }
5482 }
5483
shilu366312e2019-12-17 09:28:10 -08005484 /**
5485 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5486 * @param subId The subscription to use to check the configuration.
5487 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005488 @Override
5489 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005490 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005491 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005492 final long identity = Binder.clearCallingIdentity();
5493 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005494 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005495 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005496 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005497 } catch (ImsException e) {
5498 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005499 } finally {
5500 Binder.restoreCallingIdentity(identity);
5501 }
5502 }
5503
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005504 @Override
5505 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5506 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005507
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005508 final long identity = Binder.clearCallingIdentity();
5509 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005510 if (!isImsAvailableOnDevice()) {
5511 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5512 "IMS not available on device.");
5513 }
5514 int slotId = getSlotIndexOrException(subId);
5515 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005516
5517 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5518 if (controller != null) {
5519 ImsManager imsManager = controller.getImsManager(subId);
5520 if (imsManager != null) {
5521 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5522 } else {
5523 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5524 }
5525 } else {
5526 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5527 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005528 } catch (ImsException e) {
5529 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005530 } finally {
5531 Binder.restoreCallingIdentity(identity);
5532 }
5533 }
5534
5535 @Override
5536 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5537 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005538
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005539 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005540 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5541 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5542 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005543 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005544 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5545 if (controller != null) {
5546 ImsManager imsManager = controller.getImsManager(subId);
5547 if (imsManager != null) {
5548 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5549 } else {
5550 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5551 + " is inactive, ignoring unregister.");
5552 // If the ImsManager is not valid, just return, since the callback will already
5553 // have been removed internally.
5554 }
5555 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005556 } finally {
5557 Binder.restoreCallingIdentity(identity);
5558 }
5559 }
5560
joonhunshincffb7fc2021-11-28 07:32:01 +00005561 @Override
5562 public void registerFeatureProvisioningChangedCallback(int subId,
5563 IFeatureProvisioningCallback callback) {
5564 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5565 mApp, subId, "registerFeatureProvisioningChangedCallback");
5566
5567 final long identity = Binder.clearCallingIdentity();
5568 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5569 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5570 }
5571
joonhunshin91bc1952022-04-29 08:47:15 +00005572 try {
5573 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5574 if (controller == null) {
5575 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5576 "Device does not support IMS");
5577 }
5578 controller.addFeatureProvisioningChangedCallback(subId, callback);
5579 } finally {
5580 Binder.restoreCallingIdentity(identity);
5581 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005582 }
5583
5584 @Override
5585 public void unregisterFeatureProvisioningChangedCallback(int subId,
5586 IFeatureProvisioningCallback callback) {
5587 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5588 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5589
5590 final long identity = Binder.clearCallingIdentity();
5591 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5592 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5593 }
5594
joonhunshin91bc1952022-04-29 08:47:15 +00005595 try {
5596 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5597 if (controller == null) {
5598 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5599 return;
5600 }
5601 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5602 } finally {
5603 Binder.restoreCallingIdentity(identity);
5604 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005605 }
allenwtsu99c623b2020-01-03 18:24:23 +08005606
5607 private void checkModifyPhoneStatePermission(int subId, String message) {
5608 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5609 message);
5610 }
5611
allenwtsu99c623b2020-01-03 18:24:23 +08005612 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005613 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005614 boolean isProvisioned) {
5615 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5616
5617 final long identity = Binder.clearCallingIdentity();
5618 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005619 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5620 if (controller == null) {
5621 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5622 return;
5623 }
5624 controller.setRcsProvisioningStatusForCapability(
5625 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005626 } finally {
5627 Binder.restoreCallingIdentity(identity);
5628 }
allenwtsu99c623b2020-01-03 18:24:23 +08005629 }
5630
5631
5632 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005633 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5634 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5635 mApp, subId, "getRcsProvisioningStatusForCapability");
5636
allenwtsu99c623b2020-01-03 18:24:23 +08005637 final long identity = Binder.clearCallingIdentity();
5638 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005639 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5640 if (controller == null) {
5641 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5642
5643 // device does not support IMS, this method will return true always.
5644 return true;
5645 }
5646 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005647 } finally {
5648 Binder.restoreCallingIdentity(identity);
5649 }
5650 }
5651
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005652 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005653 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5654 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005655 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005656
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005657 final long identity = Binder.clearCallingIdentity();
5658 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005659 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5660 if (controller == null) {
5661 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5662 return;
5663 }
5664 controller.setImsProvisioningStatusForCapability(
5665 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005666 } finally {
5667 Binder.restoreCallingIdentity(identity);
5668 }
5669 }
5670
5671 @Override
5672 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005673 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5674 mApp, subId, "getProvisioningStatusForCapability");
5675
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005676 final long identity = Binder.clearCallingIdentity();
5677 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005678 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5679 if (controller == null) {
5680 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005681
joonhunshin91bc1952022-04-29 08:47:15 +00005682 // device does not support IMS, this method will return true always.
5683 return true;
5684 }
5685 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005686 } finally {
5687 Binder.restoreCallingIdentity(identity);
5688 }
5689 }
5690
5691 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005692 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5693 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5694 mApp, subId, "isProvisioningRequiredForCapability");
5695
5696 final long identity = Binder.clearCallingIdentity();
5697 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005698 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5699 if (controller == null) {
5700 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5701
5702 // device does not support IMS, this method will return false
5703 return false;
5704 }
5705 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005706 } finally {
5707 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005708 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005709 }
5710
5711 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005712 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5713 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5714 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005715
joonhunshincffb7fc2021-11-28 07:32:01 +00005716 final long identity = Binder.clearCallingIdentity();
5717 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005718 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5719 if (controller == null) {
5720 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5721
5722 // device does not support IMS, this method will return false
5723 return false;
5724 }
5725 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005726 } finally {
5727 Binder.restoreCallingIdentity(identity);
5728 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005729 }
5730
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005731 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005732 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005733 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5734 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5735 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005736 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5737 mApp, subId, "getImsProvisioningInt");
5738
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005739 final long identity = Binder.clearCallingIdentity();
5740 try {
5741 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005742 int slotId = getSlotIndex(subId);
5743 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5744 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5745 + subId + "' for key:" + key);
5746 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5747 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005748
joonhunshin91bc1952022-04-29 08:47:15 +00005749 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5750 if (controller == null) {
5751 loge("getImsProvisioningInt: Device does not support IMS");
5752
5753 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5754 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5755 }
5756 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005757 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5758 return retVal;
5759 }
5760
calvinpanb5a34062021-02-08 19:59:36 +08005761 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005762 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005763 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5764 + subId + "' for key:" + key);
5765 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005766 } finally {
5767 Binder.restoreCallingIdentity(identity);
5768 }
5769 }
5770
5771 @Override
5772 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005773 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5774 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5775 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005776 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5777 mApp, subId, "getImsProvisioningString");
5778
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005779 final long identity = Binder.clearCallingIdentity();
5780 try {
5781 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005782 int slotId = getSlotIndex(subId);
5783 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5784 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5785 + subId + "' for key:" + key);
5786 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5787 }
calvinpanb5a34062021-02-08 19:59:36 +08005788 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005789 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005790 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5791 + subId + "' for key:" + key);
5792 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005793 } finally {
5794 Binder.restoreCallingIdentity(identity);
5795 }
5796 }
5797
5798 @Override
5799 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005800 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5801 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5802 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5804 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005805
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005806 final long identity = Binder.clearCallingIdentity();
5807 try {
5808 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005809 int slotId = getSlotIndex(subId);
5810 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5811 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5812 + subId + "' for key:" + key);
5813 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5814 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005815
joonhunshin91bc1952022-04-29 08:47:15 +00005816 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5817 if (controller == null) {
5818 loge("setImsProvisioningInt: Device does not support IMS");
5819
5820 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5821 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5822 }
5823 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005824 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5825 return retVal;
5826 }
5827
calvinpanb5a34062021-02-08 19:59:36 +08005828 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5829 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005830 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005831 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005832 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005833 } finally {
5834 Binder.restoreCallingIdentity(identity);
5835 }
5836 }
5837
5838 @Override
5839 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005840 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5841 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5842 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5844 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005845 final long identity = Binder.clearCallingIdentity();
5846 try {
5847 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005848 int slotId = getSlotIndex(subId);
5849 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5850 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5851 + subId + "' for key:" + key);
5852 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5853 }
calvinpanb5a34062021-02-08 19:59:36 +08005854 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5855 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005856 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005857 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005858 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005859 } finally {
5860 Binder.restoreCallingIdentity(identity);
5861 }
5862 }
5863
Brad Ebinger919631e2021-06-02 17:46:35 -07005864 /**
5865 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5866 * for the given slot ID or no ImsResolver instance has been created.
5867 * @param slotId The slot ID that the IMS service is created for.
5868 * @throws ImsException If there is no ImsService configured for this slot.
5869 */
5870 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5871 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5872 ImsFeature.FEATURE_MMTEL)) {
5873 throw new ImsException("This subscription does not support MMTEL over IMS",
5874 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5875 }
5876 }
5877
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005878 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005879 int slotId = SubscriptionManager.getSlotIndex(subId);
5880 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005881 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5882 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005883 }
5884 return slotId;
5885 }
5886
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005887 private int getSlotIndex(int subId) {
5888 int slotId = SubscriptionManager.getSlotIndex(subId);
5889 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5890 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5891 }
5892 return slotId;
5893 }
5894
Wink Saville36469e72014-06-11 15:17:00 -07005895 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005896 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005897 */
5898 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005899 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5900 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005901 try {
5902 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5903 } catch (SecurityException se) {
5904 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5905 throw new SecurityException("Package " + callingPackage + " does not belong to "
5906 + Binder.getCallingUid());
5907 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005908 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005909 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005910 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005911 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005912 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005913 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005914 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005915 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5916 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005917
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005918 final long identity = Binder.clearCallingIdentity();
5919 try {
5920 final Phone phone = getPhone(subId);
5921 if (phone != null) {
5922 return phone.getServiceState().getDataNetworkType();
5923 } else {
5924 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5925 }
5926 } finally {
5927 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005928 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005929 }
5930
5931 /**
5932 * Returns the data network type
5933 */
5934 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005935 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005936 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005937 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005938 }
5939
5940 /**
5941 * Returns the data network type for a subId
5942 */
5943 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005944 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5945 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005946 String functionName = "getDataNetworkTypeForSubscriber";
5947 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5948 mApp, functionName)) {
5949 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5950 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5951 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5952 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005953 }
5954
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005955 final long identity = Binder.clearCallingIdentity();
5956 try {
5957 final Phone phone = getPhone(subId);
5958 if (phone != null) {
5959 return phone.getServiceState().getDataNetworkType();
5960 } else {
5961 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5962 }
5963 } finally {
5964 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005965 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005966 }
5967
5968 /**
Wink Saville36469e72014-06-11 15:17:00 -07005969 * Returns the Voice network type for a subId
5970 */
5971 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005972 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5973 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005974 String functionName = "getVoiceNetworkTypeForSubscriber";
5975 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5976 mApp, functionName)) {
5977 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5978 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5979 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5980 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005981 }
5982
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005983 final long identity = Binder.clearCallingIdentity();
5984 try {
5985 final Phone phone = getPhone(subId);
5986 if (phone != null) {
5987 return phone.getServiceState().getVoiceNetworkType();
5988 } else {
5989 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5990 }
5991 } finally {
5992 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005993 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005994 }
5995
5996 /**
5997 * @return true if a ICC card is present
5998 */
5999 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07006000 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08006001 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006002 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07006003 }
6004
6005 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006006 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07006007 */
Sanket Padawe356d7632015-06-22 14:03:32 -07006008 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006009 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006010 final long identity = Binder.clearCallingIdentity();
6011 try {
6012 final Phone phone = PhoneFactory.getPhone(slotIndex);
6013 if (phone != null) {
6014 return phone.getIccCard().hasIccCard();
6015 } else {
6016 return false;
6017 }
6018 } finally {
6019 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08006020 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006021 }
6022
6023 /**
6024 * Return if the current radio is LTE on CDMA. This
6025 * is a tri-state return value as for a period of time
6026 * the mode may be unknown.
6027 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006028 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006029 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08006030 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006031 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006032 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006033 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
6034 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
6035 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07006036 }
6037
Sanket Padawe356d7632015-06-22 14:03:32 -07006038 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006039 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
6040 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08006041 try {
6042 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
6043 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006044 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
6045 }
6046
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006047 final long identity = Binder.clearCallingIdentity();
6048 try {
6049 final Phone phone = getPhone(subId);
6050 if (phone == null) {
6051 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
6052 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07006053 return TelephonyProperties.lte_on_cdma_device()
6054 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006055 }
6056 } finally {
6057 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006058 }
Wink Saville36469e72014-06-11 15:17:00 -07006059 }
6060
Wink Saville36469e72014-06-11 15:17:00 -07006061 /**
6062 * {@hide}
6063 * Returns Default subId, 0 in the case of single standby.
6064 */
Wink Savilleb564aae2014-10-23 10:18:09 -07006065 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08006066 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07006067 }
6068
Shishir Agrawala9f32182016-04-12 12:00:16 -07006069 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08006070 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07006071 }
6072
Wink Savilleb564aae2014-10-23 10:18:09 -07006073 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08006074 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006075 }
Ihab Awadf2177b72013-11-25 13:33:23 -08006076
Pengquan Menge92a50d2018-09-21 15:54:48 -07006077 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08006078 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08006079 return getSubscriptionManagerService().isActiveSubId(subId,
Jack Yu285100e2022-12-02 22:48:35 -08006080 mApp.getOpPackageName(), mApp.getFeatureId());
6081 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07006082 return mSubscriptionController.isActiveSubId(subId);
6083 }
6084
Ihab Awadf2177b72013-11-25 13:33:23 -08006085 /**
6086 * @see android.telephony.TelephonyManager.WifiCallingChoices
6087 */
6088 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006089 final long identity = Binder.clearCallingIdentity();
6090 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006091 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006092 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
6093 getWhenToMakeWifiCallsDefaultPreference());
6094 } finally {
6095 Binder.restoreCallingIdentity(identity);
6096 }
Ihab Awadf2177b72013-11-25 13:33:23 -08006097 }
6098
6099 /**
6100 * @see android.telephony.TelephonyManager.WifiCallingChoices
6101 */
6102 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006103 final long identity = Binder.clearCallingIdentity();
6104 try {
6105 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006106 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
6108 } finally {
6109 Binder.restoreCallingIdentity(identity);
6110 }
Ihab Awadf9e92732013-12-05 18:02:52 -08006111 }
6112
Sailesh Nepald1e68152013-12-12 19:08:02 -08006113 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07006114 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08006115 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08006116 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08006117
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006118 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
6119 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
6120 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08006121 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006122 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006123 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08006124 }
6125 return PhoneFactory.getPhone(phoneId);
6126 }
6127
Shishir Agrawal566b7612013-10-28 14:41:00 -07006128 @Override
Derek Tan740e1672017-06-27 14:56:27 -07006129 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08006130 @NonNull IccLogicalChannelRequest request) {
6131 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6132 /*message=*/ "iccOpenLogicalChannel");
6133
6134 if (DBG) log("iccOpenLogicalChannel: request=" + request);
6135 // Verify that the callingPackage in the request belongs to the calling UID
6136 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
6137
6138 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006139 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006140
Rambo Wanga1782702021-11-10 20:15:19 -08006141 private Phone getPhoneFromValidIccLogicalChannelRequest(
6142 @NonNull IccLogicalChannelRequest request, String message) {
6143 Phone phone;
6144 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
6145 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6146 mApp, request.subId, message);
6147 phone = getPhoneFromSubId(request.subId);
6148 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6149 enforceModifyPermission();
6150 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
6151 } else {
6152 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08006153 }
Rambo Wanga1782702021-11-10 20:15:19 -08006154 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08006155 }
6156
6157 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08006158 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006159 final long identity = Binder.clearCallingIdentity();
6160 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006161 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006162 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006163 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6164 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08006165 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
6166 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006167 loge("The calling package is not allowed to access ISD-R.");
6168 throw new SecurityException(
6169 "The calling package is not allowed to access ISD-R.");
6170 }
Derek Tan740e1672017-06-27 14:56:27 -07006171 }
Derek Tan740e1672017-06-27 14:56:27 -07006172
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006173 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006174 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6175 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006176 return response;
6177 } finally {
6178 Binder.restoreCallingIdentity(identity);
6179 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006180 }
6181
6182 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006183 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
6184 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6185 /*message=*/"iccCloseLogicalChannel");
6186
6187 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6188
6189 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006190 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006191
Rambo Wanga1782702021-11-10 20:15:19 -08006192 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6193 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006194 // before this feature is enabled, this API should only return false if
6195 // the operation fails instead of throwing runtime exception for
6196 // backward-compatibility.
6197 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6198 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006199 final long identity = Binder.clearCallingIdentity();
6200 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006201 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006202 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006203 }
Chen Xue9d737e2022-01-01 23:41:31 -08006204 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006205 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006206 Boolean success = false;
6207 if (result instanceof RuntimeException) {
6208 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006209 if (shouldThrowExceptionOnFailure) {
6210 throw (RuntimeException) result;
6211 } else {
6212 return false;
6213 }
Chen Xue9d737e2022-01-01 23:41:31 -08006214 } else if (result instanceof Boolean) {
6215 success = (Boolean) result;
6216 } else {
6217 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6218 }
Rambo Wanga1782702021-11-10 20:15:19 -08006219 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006220 return success;
6221 } finally {
6222 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006223 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006224 }
6225
6226 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006227 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006228 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006229 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6230 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08006231 if (DBG) {
6232 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6233 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6234 + p3 + " data=" + data);
6235 }
6236 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6237 command, p1, p2, p3, data);
6238 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006239
Jordan Liu4c733742019-02-28 12:03:40 -08006240 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006241 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006242 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006243 enforceModifyPermission();
6244 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006245 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006246 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6247 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006248 }
6249 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006250 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6251 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006252 }
6253
6254 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6255 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006256 final long identity = Binder.clearCallingIdentity();
6257 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006258 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006259 return "";
6260 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006261
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006262 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006263 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6264 null /* workSource */);
6265 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006266
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006267 // Append the returned status code to the end of the response payload.
6268 String s = Integer.toHexString(
6269 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6270 if (response.payload != null) {
6271 s = IccUtils.bytesToHexString(response.payload) + s;
6272 }
6273 return s;
6274 } finally {
6275 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006276 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006277 }
Jake Hambye994d462014-02-03 13:10:13 -08006278
Evan Charltonc66da362014-05-16 14:06:40 -07006279 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006280 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6281 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006282 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6283 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006284 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08006285 if (DBG) {
6286 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6287 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6288 }
6289 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6290 cla, command, p1, p2, p3, data);
6291 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006292
Jordan Liu4c733742019-02-28 12:03:40 -08006293 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006294 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006295 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006296 enforceModifyPermission();
6297 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6298 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006299 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006300 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6301 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006302 }
6303
6304 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006305 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6306 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006307 }
6308
6309 // open APDU basic channel assuming the caller has sufficient permissions
6310 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6311 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006312 final long identity = Binder.clearCallingIdentity();
6313 try {
6314 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6315 && TextUtils.equals(ISDR_AID, data)) {
6316 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006317 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6318 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006319 if (bestComponent == null
6320 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6321 loge("The calling package is not allowed to select ISD-R.");
6322 throw new SecurityException(
6323 "The calling package is not allowed to select ISD-R.");
6324 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006325 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006326
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006327 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006328 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6329 null /* workSource */);
6330 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006331
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332 // Append the returned status code to the end of the response payload.
6333 String s = Integer.toHexString(
6334 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6335 if (response.payload != null) {
6336 s = IccUtils.bytesToHexString(response.payload) + s;
6337 }
6338 return s;
6339 } finally {
6340 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006341 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006342 }
6343
6344 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006345 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006346 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6348 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006349
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006350 final long identity = Binder.clearCallingIdentity();
6351 try {
6352 if (DBG) {
6353 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6354 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6355 }
6356
6357 IccIoResult response =
6358 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6359 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6360 subId);
6361
6362 if (DBG) {
6363 log("Exchange SIM_IO [R]" + response);
6364 }
6365
6366 byte[] result = null;
6367 int length = 2;
6368 if (response.payload != null) {
6369 length = 2 + response.payload.length;
6370 result = new byte[length];
6371 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6372 } else {
6373 result = new byte[length];
6374 }
6375
6376 result[length - 1] = (byte) response.sw2;
6377 result[length - 2] = (byte) response.sw1;
6378 return result;
6379 } finally {
6380 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006381 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006382 }
6383
Nathan Haroldb3014052017-01-25 15:57:32 -08006384 /**
6385 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6386 * on a particular subscription
6387 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006388 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6389 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006390 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006391 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006392 return null;
6393 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006394
6395 final long identity = Binder.clearCallingIdentity();
6396 try {
6397 if (appType != TelephonyManager.APPTYPE_USIM
6398 && appType != TelephonyManager.APPTYPE_SIM) {
6399 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6400 return null;
6401 }
6402 Object response = sendRequest(
6403 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6404 if (response instanceof String[]) {
6405 return (String[]) response;
6406 }
yincheng zhao2737e882019-09-06 17:06:54 -07006407 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006408 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006409 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006410 } finally {
6411 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006412 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006413 }
6414
yincheng zhao2737e882019-09-06 17:06:54 -07006415 /**
6416 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6417 * subscription.
6418 *
6419 * @param subId the id of the subscription.
6420 * @param appType the uicc app type, must be USIM or SIM.
6421 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6422 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006423 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006424 * @return number of fplmns that is successfully written to the SIM.
6425 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006426 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6427 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006428 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6429 mApp, subId, "setForbiddenPlmns");
6430
yincheng zhao2737e882019-09-06 17:06:54 -07006431 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6432 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6433 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6434 }
6435 if (fplmns == null) {
6436 throw new IllegalArgumentException("Fplmn List provided is null");
6437 }
6438 for (String fplmn : fplmns) {
6439 if (!CellIdentity.isValidPlmn(fplmn)) {
6440 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6441 }
6442 }
6443 final long identity = Binder.clearCallingIdentity();
6444 try {
6445 Object response = sendRequest(
6446 CMD_SET_FORBIDDEN_PLMNS,
6447 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6448 subId);
6449 return (int) response;
6450 } finally {
6451 Binder.restoreCallingIdentity(identity);
6452 }
6453 }
6454
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006455 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006456 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006457 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6458 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006459
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006460 final long identity = Binder.clearCallingIdentity();
6461 try {
6462 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6463 if (response.payload == null) {
6464 return "";
6465 }
Evan Charltonc66da362014-05-16 14:06:40 -07006466
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006467 // Append the returned status code to the end of the response payload.
6468 String s = Integer.toHexString(
6469 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6470 s = IccUtils.bytesToHexString(response.payload) + s;
6471 return s;
6472 } finally {
6473 Binder.restoreCallingIdentity(identity);
6474 }
Evan Charltonc66da362014-05-16 14:06:40 -07006475 }
6476
Jake Hambye994d462014-02-03 13:10:13 -08006477 /**
6478 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6479 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6480 *
6481 * @param itemID the ID of the item to read
6482 * @return the NV item as a String, or null on error.
6483 */
6484 @Override
6485 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006486 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6488 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006489
6490 final long identity = Binder.clearCallingIdentity();
6491 try {
6492 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006493 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006494 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6495 return value;
6496 } finally {
6497 Binder.restoreCallingIdentity(identity);
6498 }
Jake Hambye994d462014-02-03 13:10:13 -08006499 }
6500
6501 /**
6502 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6503 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6504 *
6505 * @param itemID the ID of the item to read
6506 * @param itemValue the value to write, as a String
6507 * @return true on success; false on any failure
6508 */
6509 @Override
6510 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006511 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006512 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6513 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006514
6515 final long identity = Binder.clearCallingIdentity();
6516 try {
6517 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6518 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006519 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006520 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6521 return success;
6522 } finally {
6523 Binder.restoreCallingIdentity(identity);
6524 }
Jake Hambye994d462014-02-03 13:10:13 -08006525 }
6526
6527 /**
6528 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6529 * Used for device configuration by some CDMA operators.
6530 *
6531 * @param preferredRoamingList byte array containing the new PRL
6532 * @return true on success; false on any failure
6533 */
6534 @Override
6535 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006536 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6537 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006538
6539 final long identity = Binder.clearCallingIdentity();
6540 try {
6541 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6542 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6543 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6544 return success;
6545 } finally {
6546 Binder.restoreCallingIdentity(identity);
6547 }
Jake Hambye994d462014-02-03 13:10:13 -08006548 }
6549
6550 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006551 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006552 * Used for device configuration by some CDMA operators.
6553 *
chen xu6dac5ab2018-10-26 17:39:23 -07006554 * @param slotIndex - device slot.
6555 *
Jake Hambye994d462014-02-03 13:10:13 -08006556 * @return true on success; false on any failure
6557 */
6558 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006559 public boolean resetModemConfig(int slotIndex) {
6560 Phone phone = PhoneFactory.getPhone(slotIndex);
6561 if (phone != null) {
6562 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6563 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006564
chen xu6dac5ab2018-10-26 17:39:23 -07006565 final long identity = Binder.clearCallingIdentity();
6566 try {
6567 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6568 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6569 return success;
6570 } finally {
6571 Binder.restoreCallingIdentity(identity);
6572 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006573 }
chen xu6dac5ab2018-10-26 17:39:23 -07006574 return false;
6575 }
6576
6577 /**
6578 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6579 *
6580 * @param slotIndex - device slot.
6581 *
6582 * @return true on success; false on any failure
6583 */
6584 @Override
6585 public boolean rebootModem(int slotIndex) {
6586 Phone phone = PhoneFactory.getPhone(slotIndex);
6587 if (phone != null) {
6588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6589 mApp, phone.getSubId(), "rebootModem");
6590
6591 final long identity = Binder.clearCallingIdentity();
6592 try {
6593 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6594 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6595 return success;
6596 } finally {
6597 Binder.restoreCallingIdentity(identity);
6598 }
6599 }
6600 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006601 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006602
Brad Ebinger51f743a2017-01-23 13:50:20 -08006603 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006604 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6605 * {@link #disableIms(int)}.
6606 * @param slotIndex device slot.
6607 */
6608 public void resetIms(int slotIndex) {
6609 enforceModifyPermission();
6610
6611 final long identity = Binder.clearCallingIdentity();
6612 try {
6613 if (mImsResolver == null) {
6614 // may happen if the does not support IMS.
6615 return;
6616 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006617 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006618 } finally {
6619 Binder.restoreCallingIdentity(identity);
6620 }
6621 }
6622
6623 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006624 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6625 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006626 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006627 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006628 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006629
6630 final long identity = Binder.clearCallingIdentity();
6631 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006632 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006633 // may happen if the device does not support IMS.
6634 return;
6635 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006636 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006637 } finally {
6638 Binder.restoreCallingIdentity(identity);
6639 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006640 }
6641
6642 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006643 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6644 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006645 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006646 public void disableIms(int slotId) {
6647 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006648
6649 final long identity = Binder.clearCallingIdentity();
6650 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006651 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006652 // may happen if the device does not support IMS.
6653 return;
6654 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006655 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006656 } finally {
6657 Binder.restoreCallingIdentity(identity);
6658 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006659 }
6660
6661 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006662 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6663 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006664 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006665 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006666 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006667 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006668
6669 final long identity = Binder.clearCallingIdentity();
6670 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006671 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006672 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6673 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006674 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006675 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006676 } finally {
6677 Binder.restoreCallingIdentity(identity);
6678 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006679 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006680 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006681 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6682 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006683 @Override
6684 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006685 enforceModifyPermission();
6686
6687 final long identity = Binder.clearCallingIdentity();
6688 try {
6689 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006690 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006691 } finally {
6692 Binder.restoreCallingIdentity(identity);
6693 }
6694 }
6695
6696 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006697 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006698 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006699 */
6700 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6701 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006702
6703 final long identity = Binder.clearCallingIdentity();
6704 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006705 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006706 // may happen if the device does not support IMS.
6707 return null;
6708 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006709 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006710 } finally {
6711 Binder.restoreCallingIdentity(identity);
6712 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006713 }
6714
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006715 /**
6716 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006717 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006718 */
6719 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6720 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006721
6722 final long identity = Binder.clearCallingIdentity();
6723 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006724 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006725 // may happen if the device does not support IMS.
6726 return null;
6727 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006728 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006729 } finally {
6730 Binder.restoreCallingIdentity(identity);
6731 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006732 }
6733
Brad Ebinger884c07b2018-02-15 16:17:40 -08006734 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006735 * Sets the ImsService Package Name that Telephony will bind to.
6736 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006737 * @param slotIndex the slot ID that the ImsService should bind for.
6738 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006739 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006740 * @param featureTypes An integer array of feature types associated with a packageName.
6741 * @param packageName The name of the package that the current configuration will be replaced
6742 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006743 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006744 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006745 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6746 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006747 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006749 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006750
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006751 final long identity = Binder.clearCallingIdentity();
6752 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006753 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006754 // may happen if the device does not support IMS.
6755 return false;
6756 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006757 Map<Integer, String> featureConfig = new HashMap<>();
6758 for (int featureType : featureTypes) {
6759 featureConfig.put(featureType, packageName);
6760 }
6761 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6762 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006763 } finally {
6764 Binder.restoreCallingIdentity(identity);
6765 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006766 }
6767
6768 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006769 * Clears any carrier ImsService overrides for the slot index specified that were previously
6770 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6771 *
6772 * This should only be used for testing.
6773 *
6774 * @param slotIndex the slot ID that the ImsService should bind for.
6775 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6776 */
6777 @Override
6778 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006779 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6780 "clearCarrierImsServiceOverride");
6781 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006782 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006783
6784 final long identity = Binder.clearCallingIdentity();
6785 try {
6786 if (mImsResolver == null) {
6787 // may happen if the device does not support IMS.
6788 return false;
6789 }
6790 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6791 } finally {
6792 Binder.restoreCallingIdentity(identity);
6793 }
6794 }
6795
6796 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006797 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006798 *
6799 * @param slotId The slot that the ImsService is associated with.
6800 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6801 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006802 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006803 * @return the package name of the ImsService configuration.
6804 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006805 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6806 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006807 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006808 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6809 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006810
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006811 final long identity = Binder.clearCallingIdentity();
6812 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006813 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006814 // may happen if the device does not support IMS.
6815 return "";
6816 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006817 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006818 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6819 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006820 } finally {
6821 Binder.restoreCallingIdentity(identity);
6822 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006823 }
6824
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006825 /**
6826 * Get the MmTelFeature state associated with the requested subscription id.
6827 * @param subId The subscription that the MmTelFeature is associated with.
6828 * @param callback A callback with an integer containing the
6829 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6830 */
6831 @Override
6832 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6833 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006834 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6835 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6836 "IMS not available on device.");
6837 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006838 final long token = Binder.clearCallingIdentity();
6839 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006840 int slotId = getSlotIndex(subId);
6841 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6842 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6843 + subId + "'");
6844 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6845 }
6846 verifyImsMmTelConfiguredOrThrow(slotId);
6847 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6848 try {
6849 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6850 } catch (RemoteException e) {
6851 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6852 + "Ignore");
6853 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006854 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006855 } catch (ImsException e) {
6856 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006857 } finally {
6858 Binder.restoreCallingIdentity(token);
6859 }
6860 }
6861
Daniel Brightbb5840b2021-01-12 15:48:18 -08006862 /**
6863 * Sets the ims registration state on all valid {@link Phone}s.
6864 */
6865 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006866 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006867
6868 final long identity = Binder.clearCallingIdentity();
6869 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006870 // NOTE: Before S, this method only set the default phone.
6871 for (final Phone phone : PhoneFactory.getPhones()) {
6872 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6873 phone.setImsRegistrationState(registered);
6874 }
6875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006876 } finally {
6877 Binder.restoreCallingIdentity(identity);
6878 }
Wink Saville36469e72014-06-11 15:17:00 -07006879 }
6880
6881 /**
Stuart Scott54788802015-03-30 13:18:01 -07006882 * Set the network selection mode to automatic.
6883 *
6884 */
6885 @Override
6886 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6888 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006889
6890 final long identity = Binder.clearCallingIdentity();
6891 try {
shilufc958392020-01-20 11:36:01 -08006892 if (!isActiveSubscription(subId)) {
6893 return;
6894 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006895 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006896 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6897 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006898 } finally {
6899 Binder.restoreCallingIdentity(identity);
6900 }
Stuart Scott54788802015-03-30 13:18:01 -07006901 }
6902
Jack Yud10cdd42020-09-28 20:28:01 -07006903 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006904 * Ask the radio to connect to the input network and change selection mode to manual.
6905 *
6906 * @param subId the id of the subscription.
6907 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6908 * the operator to attach to.
6909 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6910 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6911 * normal network selection next time.
6912 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006913 */
6914 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006915 public boolean setNetworkSelectionModeManual(
6916 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006917 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6918 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006919
Jack Yu285100e2022-12-02 22:48:35 -08006920 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006921 if (!isActiveSubscription(subId)) {
6922 return false;
6923 }
6924
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006925 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006926 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006927 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006928 if (DBG) {
6929 log("setNetworkSelectionModeManual: subId: " + subId
6930 + " operator: " + operatorInfo);
6931 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006932 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6933 } finally {
6934 Binder.restoreCallingIdentity(identity);
6935 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006936 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006937 /**
shilu84f6e8b2019-12-19 13:58:01 -08006938 * Get the manual network selection
6939 *
6940 * @param subId the id of the subscription.
6941 *
6942 * @return the previously saved user selected PLMN
6943 */
6944 @Override
6945 public String getManualNetworkSelectionPlmn(int subId) {
6946 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006947 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6948 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006949
6950 final long identity = Binder.clearCallingIdentity();
6951 try {
6952 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006953 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006954 }
6955
6956 final Phone phone = getPhone(subId);
6957 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006958 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006959 }
6960 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6961 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006962 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006963 } finally {
6964 Binder.restoreCallingIdentity(identity);
6965 }
6966 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006967
6968 /**
6969 * Scans for available networks.
6970 */
6971 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006972 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6973 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006974 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6975 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006976 LocationAccessPolicy.LocationPermissionResult locationResult =
6977 LocationAccessPolicy.checkLocationPermission(mApp,
6978 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6979 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006980 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006981 .setCallingPid(Binder.getCallingPid())
6982 .setCallingUid(Binder.getCallingUid())
6983 .setMethod("getCellNetworkScanResults")
6984 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006985 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6986 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006987 .build());
6988 switch (locationResult) {
6989 case DENIED_HARD:
6990 throw new SecurityException("Not allowed to access scan results -- location");
6991 case DENIED_SOFT:
6992 return null;
6993 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006994
Pengquan Menga1bb6272018-09-06 09:59:22 -07006995 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006996 try {
6997 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006998 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006999 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007000 } finally {
7001 Binder.restoreCallingIdentity(identity);
7002 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07007003 }
7004
7005 /**
Shuo Qian4a594052020-01-23 11:59:30 -08007006 * Get the call forwarding info, given the call forwarding reason.
7007 */
7008 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007009 public void getCallForwarding(int subId, int callForwardingReason,
7010 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007011 enforceReadPrivilegedPermission("getCallForwarding");
7012 long identity = Binder.clearCallingIdentity();
7013 try {
7014 if (DBG) {
7015 log("getCallForwarding: subId " + subId
7016 + " callForwardingReason" + callForwardingReason);
7017 }
Hall Liu27d24262020-09-18 19:04:59 -07007018
7019 Phone phone = getPhone(subId);
7020 if (phone == null) {
7021 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07007022 callback.onError(
7023 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07007024 } catch (RemoteException e) {
7025 // ignore
7026 }
7027 return;
7028 }
7029
7030 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
7031 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
7032 @Override
7033 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
7034 try {
7035 callback.onCallForwardingInfoAvailable(info);
7036 } catch (RemoteException e) {
7037 // ignore
7038 }
7039 }
7040
7041 @Override
7042 public void onError(int error) {
7043 try {
7044 callback.onError(error);
7045 } catch (RemoteException e) {
7046 // ignore
7047 }
7048 }
7049 });
7050 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08007051 } finally {
7052 Binder.restoreCallingIdentity(identity);
7053 }
7054 }
7055
7056 /**
7057 * Sets the voice call forwarding info including status (enable/disable), call forwarding
7058 * reason, the number to forward, and the timeout before the forwarding is attempted.
7059 */
7060 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007061 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
7062 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007063 enforceModifyPermission();
7064 long identity = Binder.clearCallingIdentity();
7065 try {
7066 if (DBG) {
7067 log("setCallForwarding: subId " + subId
7068 + " callForwardingInfo" + callForwardingInfo);
7069 }
Hall Liu27d24262020-09-18 19:04:59 -07007070
7071 Phone phone = getPhone(subId);
7072 if (phone == null) {
7073 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07007074 callback.accept(
7075 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07007076 } catch (RemoteException e) {
7077 // ignore
7078 }
7079 return;
7080 }
7081
7082 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
7083 FunctionalUtils.ignoreRemoteException(callback::accept));
7084
7085 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08007086 } finally {
7087 Binder.restoreCallingIdentity(identity);
7088 }
7089 }
7090
7091 /**
Hall Liu27d24262020-09-18 19:04:59 -07007092 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007093 */
7094 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007095 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08007096 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08007097 long identity = Binder.clearCallingIdentity();
7098 try {
Hall Liu27d24262020-09-18 19:04:59 -07007099 Phone phone = getPhone(subId);
7100 if (phone == null) {
7101 try {
7102 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7103 } catch (RemoteException e) {
7104 // ignore
7105 }
7106 return;
7107 }
SongFerngWang0e767992021-03-31 22:08:45 +08007108 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7109 PersistableBundle c = configManager.getConfigForSubId(subId);
7110 boolean requireUssd = c.getBoolean(
7111 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007112
Shuo Qian4a594052020-01-23 11:59:30 -08007113 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007114 if (requireUssd) {
7115 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7116 getSubscriptionCarrierId(subId));
7117 String newUssdCommand = "";
7118 try {
7119 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007120 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007121 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7122 } catch (NullPointerException e) {
7123 loge("Failed to generate USSD number" + e);
7124 }
7125 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7126 mMainThreadHandler, callback, carrierXmlParser,
7127 CarrierXmlParser.SsEntry.SSAction.QUERY);
7128 final String ussdCommand = newUssdCommand;
7129 Executors.newSingleThreadExecutor().execute(() -> {
7130 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7131 });
7132 } else {
7133 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7134 callback::accept);
7135 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7136 }
Shuo Qian4a594052020-01-23 11:59:30 -08007137 } finally {
7138 Binder.restoreCallingIdentity(identity);
7139 }
7140 }
7141
7142 /**
Hall Liu27d24262020-09-18 19:04:59 -07007143 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007144 */
7145 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007146 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007147 enforceModifyPermission();
7148 long identity = Binder.clearCallingIdentity();
7149 try {
Hall Liu27d24262020-09-18 19:04:59 -07007150 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7151
7152 Phone phone = getPhone(subId);
7153 if (phone == null) {
7154 try {
7155 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7156 } catch (RemoteException e) {
7157 // ignore
7158 }
7159 return;
7160 }
7161
SongFerngWang0e767992021-03-31 22:08:45 +08007162 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7163 PersistableBundle c = configManager.getConfigForSubId(subId);
7164 boolean requireUssd = c.getBoolean(
7165 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007166
SongFerngWang0e767992021-03-31 22:08:45 +08007167 if (DBG) log("getCallWaitingStatus: subId " + subId);
7168 if (requireUssd) {
7169 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7170 getSubscriptionCarrierId(subId));
7171 CarrierXmlParser.SsEntry.SSAction ssAction =
7172 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7173 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7174 String newUssdCommand = "";
7175 try {
7176 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007177 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007178 .makeCommand(ssAction, null);
7179 } catch (NullPointerException e) {
7180 loge("Failed to generate USSD number" + e);
7181 }
7182 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7183 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7184 final String ussdCommand = newUssdCommand;
7185 Executors.newSingleThreadExecutor().execute(() -> {
7186 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7187 });
7188 } else {
7189 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7190 FunctionalUtils.ignoreRemoteException(callback::accept));
7191
7192 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7193 }
Shuo Qian4a594052020-01-23 11:59:30 -08007194 } finally {
7195 Binder.restoreCallingIdentity(identity);
7196 }
7197 }
7198
7199 /**
yinxub1bed742017-04-17 11:45:04 -07007200 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007201 *
yinxub1bed742017-04-17 11:45:04 -07007202 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007203 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7204 * location related information which will be sent if the caller already possess
7205 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007206 * @param request contains the radio access networks with bands/channels to scan
7207 * @param messenger callback messenger for scan results or errors
7208 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007209 * @return the id of the requested scan which can be used to stop the scan.
7210 */
7211 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007212 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7213 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007214 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007215 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7216 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007217 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007218 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7219 if (!renounceFineLocationAccess) {
7220 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007221 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7222 .setCallingPackage(callingPackage)
7223 .setCallingFeatureId(callingFeatureId)
7224 .setCallingPid(Binder.getCallingPid())
7225 .setCallingUid(Binder.getCallingUid())
7226 .setMethod("requestNetworkScan")
7227 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7228 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7229 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7230 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007231 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007232 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007233 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7234 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007235 if (e != null) {
7236 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7237 throw e;
7238 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007239 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007240 return TelephonyScanManager.INVALID_SCAN_ID;
7241 }
7242 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007243 }
Hall Liu912dfd32019-04-25 14:02:26 -07007244 int callingUid = Binder.getCallingUid();
7245 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007246 final long identity = Binder.clearCallingIdentity();
7247 try {
7248 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007249 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007250 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007251 } finally {
7252 Binder.restoreCallingIdentity(identity);
7253 }
yinxu504e1392017-04-12 16:03:22 -07007254 }
7255
Hall Liub2ac8ef2019-02-28 15:56:23 -08007256 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007257 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007258 boolean hasCarrierPriv;
7259 final long identity = Binder.clearCallingIdentity();
7260 try {
7261 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7262 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7263 } finally {
7264 Binder.restoreCallingIdentity(identity);
7265 }
Hall Liu558027f2019-05-15 19:14:05 -07007266 boolean hasNetworkScanPermission =
7267 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007268 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007269
7270 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7271 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7272 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007273 }
7274
7275 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7276 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007277 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7278 return new SecurityException("Specific channels must not be"
7279 + " scanned without location access.");
7280 }
7281 }
7282 }
7283
Hall Liub2ac8ef2019-02-28 15:56:23 -08007284 return null;
7285 }
7286
yinxu504e1392017-04-12 16:03:22 -07007287 /**
7288 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007289 *
7290 * @param subId id of the subscription
7291 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007292 */
7293 @Override
7294 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7296 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007297
Hall Liu912dfd32019-04-25 14:02:26 -07007298 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007299 final long identity = Binder.clearCallingIdentity();
7300 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007301 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007302 } finally {
7303 Binder.restoreCallingIdentity(identity);
7304 }
yinxu504e1392017-04-12 16:03:22 -07007305 }
7306
7307 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007308 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007309 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007310 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007311 */
7312 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007313 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007314 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007315 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007316 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007317
7318 final long identity = Binder.clearCallingIdentity();
7319 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007320 if (DBG) log("getAllowedNetworkTypesBitmask");
7321 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7322 int networkTypesBitmask = (result != null ? result[0] : -1);
7323 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7324 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007325 } finally {
7326 Binder.restoreCallingIdentity(identity);
7327 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007328 }
7329
7330 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007331 * Get the allowed network types for certain reason.
7332 *
7333 * @param subId the id of the subscription.
7334 * @param reason the reason the allowed network type change is taking place
7335 * @return the allowed network types.
7336 */
7337 @Override
7338 public long getAllowedNetworkTypesForReason(int subId,
7339 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007340 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007341 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007342 final long identity = Binder.clearCallingIdentity();
7343 try {
7344 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
7345 } finally {
7346 Binder.restoreCallingIdentity(identity);
7347 }
7348 }
7349
7350 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007351 * Enable/Disable E-UTRA-NR Dual Connectivity
7352 * @param subId subscription id of the sim card
7353 * @param nrDualConnectivityState expected NR dual connectivity state
7354 * This can be passed following states
7355 * <ol>
7356 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7357 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7358 * <li>Disable NR dual connectivity and force secondary cell to be released
7359 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7360 * </ol>
7361 * @return operation result.
7362 */
7363 @Override
7364 public int setNrDualConnectivityState(int subId,
7365 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7367 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007368 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007369 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7370 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7371 }
7372
Sooraj Sasindran37444802020-08-11 10:40:43 -07007373 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7374 final long identity = Binder.clearCallingIdentity();
7375 try {
7376 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7377 nrDualConnectivityState, subId,
7378 workSource);
7379 if (DBG) log("enableNRDualConnectivity result: " + result);
7380 return result;
7381 } finally {
7382 Binder.restoreCallingIdentity(identity);
7383 }
7384 }
7385
7386 /**
7387 * Is E-UTRA-NR Dual Connectivity enabled
7388 * @return true if dual connectivity is enabled else false
7389 */
7390 @Override
7391 public boolean isNrDualConnectivityEnabled(int subId) {
7392 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007393 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007394 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007395 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007396 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7397 return false;
7398 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007399 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7400 final long identity = Binder.clearCallingIdentity();
7401 try {
7402 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7403 null, subId, workSource);
7404 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7405 return isEnabled;
7406 } finally {
7407 Binder.restoreCallingIdentity(identity);
7408 }
7409 }
7410
7411 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007412 * Set the allowed network types of the device and
7413 * provide the reason triggering the allowed network change.
7414 *
7415 * @param subId the id of the subscription.
7416 * @param reason the reason the allowed network type change is taking place
7417 * @param allowedNetworkTypes the allowed network types.
7418 * @return true on success; false on any failure.
7419 */
7420 @Override
7421 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007422 @TelephonyManager.AllowedNetworkTypesReason int reason,
7423 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7425 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007426 // If the caller only has carrier privileges, then they should not be able to override
7427 // any network types which were set for security reasons.
7428 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7429 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007430 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007431 throw new SecurityException(
7432 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007433 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007434 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08007435 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007436 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007437 return false;
7438 }
7439 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7440 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007441 return false;
7442 }
7443
Jack Yu5b494332023-01-23 18:18:04 +00007444 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7445 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007446
Jack Yue37dd262022-12-16 11:53:37 -08007447 Phone phone = getPhone(subId);
7448 if (phone == null) {
7449 return false;
7450 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007451
Jack Yue37dd262022-12-16 11:53:37 -08007452 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007453 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007454 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007455 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007456
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007457 final long identity = Binder.clearCallingIdentity();
7458 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007459 Boolean success = (Boolean) sendRequest(
7460 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7461 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7462
7463 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7464 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007465 } finally {
7466 Binder.restoreCallingIdentity(identity);
7467 }
7468 }
7469
7470 /**
Miaoa84611c2019-03-15 09:21:10 +08007471 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007472 *
Miaoa84611c2019-03-15 09:21:10 +08007473 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007474 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007475 * @hide
7476 */
7477 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007478 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007479 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007480 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007481 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007482 try {
Miaoa84611c2019-03-15 09:21:10 +08007483 if (phone != null) {
7484 return phone.hasMatchedTetherApnSetting();
7485 } else {
7486 return false;
7487 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007488 } finally {
7489 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007490 }
Junda Liu475951f2014-11-07 16:45:03 -08007491 }
7492
7493 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007494 * Get the user enabled state of Mobile Data.
7495 *
7496 * TODO: remove and use isUserDataEnabled.
7497 * This can't be removed now because some vendor codes
7498 * calls through ITelephony directly while they should
7499 * use TelephonyManager.
7500 *
7501 * @return true on enabled
7502 */
7503 @Override
7504 public boolean getDataEnabled(int subId) {
7505 return isUserDataEnabled(subId);
7506 }
7507
7508 /**
7509 * Get whether mobile data is enabled per user setting.
7510 *
7511 * There are other factors deciding whether mobile data is actually enabled, but they are
7512 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007513 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007514 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7515 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007516 *
7517 * @return {@code true} if data is enabled else {@code false}
7518 */
7519 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007520 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007521 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007522 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007523 try {
7524 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7525 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007526 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007527 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7528 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007529 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007530 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007531 mApp, subId, functionName);
7532
Robert Greenwalt646120a2014-05-23 11:54:03 -07007533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007534
7535 final long identity = Binder.clearCallingIdentity();
7536 try {
Jack Yu285100e2022-12-02 22:48:35 -08007537 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007538 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7539 Phone phone = PhoneFactory.getPhone(phoneId);
7540 if (phone != null) {
7541 boolean retVal = phone.isUserDataEnabled();
7542 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7543 return retVal;
7544 } else {
7545 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7546 return false;
7547 }
7548 } finally {
7549 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007550 }
7551 }
7552
7553 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007554 * Checks if the device is capable of mobile data by considering whether whether the
7555 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7556 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007557 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007558 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007559 */
7560 @Override
7561 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007562 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007563 try {
7564 try {
7565 mApp.enforceCallingOrSelfPermission(
7566 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007567 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007568 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007569 try {
7570 mApp.enforceCallingOrSelfPermission(
7571 android.Manifest.permission.READ_PHONE_STATE,
7572 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007573 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007574 mApp.enforceCallingOrSelfPermission(
7575 permission.READ_BASIC_PHONE_STATE, functionName);
7576 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007577 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007578 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007579 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007580 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007581
7582 final long identity = Binder.clearCallingIdentity();
7583 try {
Jack Yu285100e2022-12-02 22:48:35 -08007584 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007585 Phone phone = PhoneFactory.getPhone(phoneId);
7586 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007587 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007588 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007589 return retVal;
7590 } else {
7591 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7592 return false;
7593 }
7594 } finally {
7595 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007596 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007597 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007598
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007599 /**
7600 * Check if data is enabled for a specific reason
7601 * @param subId Subscription index
7602 * @param reason the reason the data enable change is taking place
7603 * @return {@code true} if the overall data is enabled; {@code false} if not.
7604 */
7605 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007606 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007607 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007608 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007609 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007610 try {
7611 mApp.enforceCallingOrSelfPermission(
7612 android.Manifest.permission.ACCESS_NETWORK_STATE,
7613 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007614 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007615 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7616 functionName);
7617 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007618 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007619 try {
7620 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007621 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007622 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007623 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007624 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007625 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007626 }
7627
7628
7629 final long identity = Binder.clearCallingIdentity();
7630 try {
Jack Yu285100e2022-12-02 22:48:35 -08007631 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007632 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007633 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007634 + " reason=" + reason);
7635 }
7636 Phone phone = PhoneFactory.getPhone(phoneId);
7637 if (phone != null) {
7638 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007639 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007640 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007641 return retVal;
7642 } else {
7643 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007644 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007645 + subId + " retVal=false");
7646 }
7647 return false;
7648 }
7649 } finally {
7650 Binder.restoreCallingIdentity(identity);
7651 }
7652 }
7653
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007654 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007655 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007656 // No permission needed; this only lets the caller inspect their own status.
7657 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007658 }
Junda Liu29340342014-07-10 15:23:27 -07007659
7660 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007661 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007662 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007663 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7664 }
7665
7666 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7667 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007668 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007669 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007670 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7671 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007672 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7673 if (cpt == null) {
7674 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007675 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7676 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007677 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007678 }
7679
7680 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007681 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007682 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007683 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007684 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007685 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007686 Phone phone = getPhone(subId);
7687 if (phone == null) {
7688 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7689 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7690 }
7691 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7692 if (cpt == null) {
7693 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007694 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7695 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007696 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007697 }
7698
7699 @Override
7700 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007701 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007702 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7703 }
7704
7705 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007706 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007707 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007708 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007709 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007710 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7711 Phone phone = PhoneFactory.getPhone(phoneId);
7712 if (phone == null) {
7713 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007714 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007715 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7716 if (cpt == null) {
7717 continue;
7718 }
7719 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007720 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7721 break;
7722 }
7723 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007724 return result;
Junda Liu29340342014-07-10 15:23:27 -07007725 }
Derek Tan89e89d42014-07-08 17:00:10 -07007726
7727 @Override
Junda Liue64de782015-04-16 17:19:16 -07007728 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007729 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007730 Phone phone = PhoneFactory.getPhone(phoneId);
7731 if (phone == null) {
7732 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007733 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007734 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7735 if (cpt == null) {
7736 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007737 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007738 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007739 }
7740
Amith Yamasani6e118872016-02-19 12:53:51 -08007741 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007742 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007743 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007744 Phone phone = PhoneFactory.getPhone(phoneId);
7745 if (phone == null) {
7746 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007747 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007748 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7749 if (cpt == null) {
7750 return Collections.emptyList();
7751 }
7752 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007753 }
7754
chen xuf7e9fe82019-05-09 19:31:02 -07007755 @Override
7756 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007757 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007758 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007759 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007760 try {
7761 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7762 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7763 }
7764 } finally {
7765 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007766 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007767 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007768 }
7769
Rambo Wang6812ffb2022-03-15 16:54:17 -07007770 @Override
7771 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7772 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7773
7774 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7775 if (phone == null) {
7776 return null;
7777 }
7778 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7779 if (cpt == null) {
7780 return null;
7781 }
7782 return cpt.getCarrierServicePackageName();
7783 }
7784
Wink Savilleb564aae2014-10-23 10:18:09 -07007785 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007786 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007787 UiccPort port = phone == null ? null : phone.getUiccPort();
7788 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007789 return null;
7790 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007791 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007792 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007793 return null;
7794 }
7795 return iccId;
7796 }
7797
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007798 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007799 public void setCallComposerStatus(int subId, int status) {
7800 enforceModifyPermission();
7801
7802 final long identity = Binder.clearCallingIdentity();
7803 try {
7804 Phone phone = getPhone(subId);
7805 if (phone != null) {
7806 Phone defaultPhone = phone.getImsPhone();
7807 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7808 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7809 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007810 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7811 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007812 }
7813 }
Shuo Qian284ae752020-12-22 19:10:14 -08007814 } catch (ImsException e) {
7815 throw new ServiceSpecificException(e.getCode());
7816 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007817 Binder.restoreCallingIdentity(identity);
7818 }
7819 }
7820
7821 @Override
7822 public int getCallComposerStatus(int subId) {
7823 enforceReadPrivilegedPermission("getCallComposerStatus");
7824
7825 final long identity = Binder.clearCallingIdentity();
7826 try {
7827 Phone phone = getPhone(subId);
7828 if (phone != null) {
7829 Phone defaultPhone = phone.getImsPhone();
7830 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7831 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7832 return imsPhone.getCallComposerStatus();
7833 }
7834 }
7835 } finally {
7836 Binder.restoreCallingIdentity(identity);
7837 }
7838 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7839 }
7840
7841 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007842 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7843 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007844 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007845 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007846
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007847 final long identity = Binder.clearCallingIdentity();
7848 try {
7849 final String iccId = getIccId(subId);
7850 final Phone phone = getPhone(subId);
7851 if (phone == null) {
7852 return false;
7853 }
7854 final String subscriberId = phone.getSubscriberId();
7855
7856 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007857 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007858 + subscriberId + " to " + number);
7859 }
7860
7861 if (TextUtils.isEmpty(iccId)) {
7862 return false;
7863 }
7864
7865 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7866
7867 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7868 if (alphaTag == null) {
7869 editor.remove(alphaTagPrefKey);
7870 } else {
7871 editor.putString(alphaTagPrefKey, alphaTag);
7872 }
7873
7874 // Record both the line number and IMSI for this ICCID, since we need to
7875 // track all merged IMSIs based on line number
7876 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7877 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7878 if (number == null) {
7879 editor.remove(numberPrefKey);
7880 editor.remove(subscriberPrefKey);
7881 } else {
7882 editor.putString(numberPrefKey, number);
7883 editor.putString(subscriberPrefKey, subscriberId);
7884 }
7885
7886 editor.commit();
7887 return true;
7888 } finally {
7889 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007890 }
Derek Tan7226c842014-07-02 17:42:23 -07007891 }
7892
7893 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007894 public String getLine1NumberForDisplay(int subId, String callingPackage,
7895 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007896 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007897 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007898 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007899 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007900 return null;
7901 }
Derek Tan97ebb422014-09-05 16:55:38 -07007902
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007903 final long identity = Binder.clearCallingIdentity();
7904 try {
7905 String iccId = getIccId(subId);
7906 if (iccId != null) {
7907 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7908 if (DBG_MERGE) {
7909 log("getLine1NumberForDisplay returning "
7910 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7911 }
7912 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007913 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007914 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7915 return null;
7916 } finally {
7917 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007918 }
Derek Tan7226c842014-07-02 17:42:23 -07007919 }
7920
7921 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007922 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7923 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007924 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007925 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007926 return null;
7927 }
Derek Tan97ebb422014-09-05 16:55:38 -07007928
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007929 final long identity = Binder.clearCallingIdentity();
7930 try {
7931 String iccId = getIccId(subId);
7932 if (iccId != null) {
7933 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7934 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7935 }
7936 return null;
7937 } finally {
7938 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007939 }
Derek Tan7226c842014-07-02 17:42:23 -07007940 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007941
7942 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007943 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7944 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007945 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7946 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007947 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007948 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007949 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007950 return null;
7951 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007952
Jordan Liub49b04b2019-05-06 14:45:15 -07007953 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7954 // the process, where TelephonyManager was instantiated.
7955 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007956 final long identity = Binder.clearCallingIdentity();
7957 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007958 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007959 final TelephonyManager tele = TelephonyManager.from(context);
7960 final SubscriptionManager sub = SubscriptionManager.from(context);
7961
7962 // Figure out what subscribers are currently active
7963 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007964
Jordan Liub49b04b2019-05-06 14:45:15 -07007965 // Only consider subs which match the current subId
7966 // This logic can be simplified. See b/131189269 for progress.
7967 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007968 activeSubscriberIds.add(tele.getSubscriberId(subId));
7969 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007970
7971 // First pass, find a number override for an active subscriber
7972 String mergeNumber = null;
7973 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7974 for (String key : prefs.keySet()) {
7975 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7976 final String subscriberId = (String) prefs.get(key);
7977 if (activeSubscriberIds.contains(subscriberId)) {
7978 final String iccId = key.substring(
7979 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7980 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7981 mergeNumber = (String) prefs.get(numberKey);
7982 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007983 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007984 + " for active subscriber " + subscriberId);
7985 }
7986 if (!TextUtils.isEmpty(mergeNumber)) {
7987 break;
7988 }
7989 }
7990 }
7991 }
7992
7993 // Shortcut when no active merged subscribers
7994 if (TextUtils.isEmpty(mergeNumber)) {
7995 return null;
7996 }
7997
7998 // Second pass, find all subscribers under that line override
7999 final ArraySet<String> result = new ArraySet<>();
8000 for (String key : prefs.keySet()) {
8001 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
8002 final String number = (String) prefs.get(key);
8003 if (mergeNumber.equals(number)) {
8004 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
8005 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
8006 final String subscriberId = (String) prefs.get(subscriberKey);
8007 if (!TextUtils.isEmpty(subscriberId)) {
8008 result.add(subscriberId);
8009 }
8010 }
8011 }
8012 }
8013
8014 final String[] resultArray = result.toArray(new String[result.size()]);
8015 Arrays.sort(resultArray);
8016 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008017 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008018 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
8019 }
8020 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008021 } finally {
8022 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08008023 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008024 }
8025
8026 @Override
zoey chen38003472019-12-13 17:16:31 +08008027 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
8028 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07008029
8030 final long identity = Binder.clearCallingIdentity();
8031 try {
8032 final TelephonyManager telephonyManager = mApp.getSystemService(
8033 TelephonyManager.class);
8034 String subscriberId = telephonyManager.getSubscriberId(subId);
8035 if (subscriberId == null) {
8036 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008037 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008038 + subId);
8039 }
8040 return null;
8041 }
8042
Jack Yu285100e2022-12-02 22:48:35 -08008043 ParcelUuid groupUuid;
8044 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008045 final SubscriptionInfo info = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08008046 .getSubscriptionInfo(subId);
8047 groupUuid = info.getGroupUuid();
8048 } else {
8049 final SubscriptionInfo info = mSubscriptionController
8050 .getSubscriptionInfo(subId);
8051 groupUuid = info.getGroupUuid();
8052 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07008053 // If it doesn't belong to any group, return just subscriberId of itself.
8054 if (groupUuid == null) {
8055 return new String[]{subscriberId};
8056 }
8057
8058 // Get all subscriberIds from the group.
8059 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08008060 List<SubscriptionInfo> groupInfos;
8061 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008062 groupInfos = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08008063 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8064 mApp.getAttributionTag());
8065 } else {
8066 groupInfos = mSubscriptionController
8067 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8068 mApp.getAttributionTag());
8069 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07008070 for (SubscriptionInfo subInfo : groupInfos) {
8071 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8072 if (subscriberId != null) {
8073 mergedSubscriberIds.add(subscriberId);
8074 }
8075 }
8076
8077 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8078 } finally {
8079 Binder.restoreCallingIdentity(identity);
8080
8081 }
8082 }
8083
8084 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008085 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008086 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008087 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008088
8089 final long identity = Binder.clearCallingIdentity();
8090 try {
8091 final Phone phone = getPhone(subId);
8092 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8093 } finally {
8094 Binder.restoreCallingIdentity(identity);
8095 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008096 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008097
8098 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008099 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008100 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8101 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008102 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8103 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008104
8105 final long identity = Binder.clearCallingIdentity();
8106 try {
8107 final Phone phone = getPhone(subId);
8108 if (phone == null) {
8109 return false;
8110 }
8111 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8112 cdmaNonRoamingList);
8113 } finally {
8114 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008115 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008116 }
8117
8118 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00008119 @Deprecated
8120 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
8121 enforceModifyPermission();
8122
8123 int returnValue = 0;
8124 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07008125 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00008126 if(result.exception == null) {
8127 if (result.result != null) {
8128 byte[] responseData = (byte[])(result.result);
8129 if(responseData.length > oemResp.length) {
8130 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
8131 responseData.length + "bytes. Buffer Size is " +
8132 oemResp.length + "bytes.");
8133 }
8134 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
8135 returnValue = responseData.length;
8136 }
8137 } else {
8138 CommandException ex = (CommandException) result.exception;
8139 returnValue = ex.getCommandError().ordinal();
8140 if(returnValue > 0) returnValue *= -1;
8141 }
8142 } catch (RuntimeException e) {
8143 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
8144 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
8145 if(returnValue > 0) returnValue *= -1;
8146 }
8147
8148 return returnValue;
8149 }
8150
8151 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008152 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008153 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07008154 try {
8155 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008156 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008157 mApp, phone.getSubId(), "getRadioAccessFamily");
8158 } catch (SecurityException e) {
8159 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8160 throw e;
8161 }
chen xub97461a2018-10-26 14:17:57 -07008162 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008163 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07008164 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08008165 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008166 final long identity = Binder.clearCallingIdentity();
8167 try {
chen xub97461a2018-10-26 14:17:57 -07008168 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008169 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07008170 mApp, phone.getSubId(), "getRadioAccessFamily");
8171 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008172 } finally {
8173 Binder.restoreCallingIdentity(identity);
8174 }
chen xub97461a2018-10-26 14:17:57 -07008175 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008176 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008177
8178 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008179 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008180 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008181 try {
8182 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8183 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008184 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008185 }
8186 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008187 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008188 }
8189 RoleManager rm = mApp.getSystemService(RoleManager.class);
8190 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8191 if (!dialerRoleHolders.contains(callingPackage)) {
8192 throw new SecurityException("App must be the dialer role holder to"
8193 + " upload a call composer pic");
8194 }
8195
8196 Executors.newSingleThreadExecutor().execute(() -> {
8197 ByteArrayOutputStream output = new ByteArrayOutputStream(
8198 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8199 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8200 boolean readUntilEnd = false;
8201 int totalBytesRead = 0;
8202 byte[] buffer = new byte[16 * 1024];
8203 while (true) {
8204 int numRead;
8205 try {
8206 numRead = input.read(buffer);
8207 } catch (IOException e) {
8208 try {
8209 fd.checkError();
8210 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8211 null);
8212 } catch (IOException e1) {
8213 // This means that the other side closed explicitly with an error. If this
8214 // happens, log and ignore.
8215 loge("Remote end of call composer picture pipe closed: " + e1);
8216 }
8217 break;
8218 }
8219 if (numRead == -1) {
8220 readUntilEnd = true;
8221 break;
8222 }
8223 totalBytesRead += numRead;
8224 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8225 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8226 try {
8227 input.close();
8228 } catch (IOException e) {
8229 // ignore
8230 }
8231 break;
8232 }
8233 output.write(buffer, 0, numRead);
8234 }
8235 // Generally, the remote end will close the file descriptors. The only case where we
8236 // close is above, where the picture size is too big.
8237
8238 try {
8239 fd.checkError();
8240 } catch (IOException e) {
8241 loge("Remote end for call composer closed with an error: " + e);
8242 return;
8243 }
8244
Hall Liuaa4211e2021-01-20 15:43:39 -08008245 if (!readUntilEnd) {
8246 loge("Did not finish reading entire image; aborting");
8247 return;
8248 }
Hall Liu82694d52020-12-11 18:22:04 -08008249
Hall Liuaa4211e2021-01-20 15:43:39 -08008250 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8251 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8252 new CallComposerPictureTransfer.Factory() {},
8253 imageData,
8254 (result) -> {
8255 if (result.first != null) {
8256 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8257 Bundle outputResult = new Bundle();
8258 outputResult.putParcelable(
8259 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8260 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8261 outputResult);
8262 } else {
8263 callback.send(result.second, null);
8264 }
8265 }
8266 );
Hall Liu82694d52020-12-11 18:22:04 -08008267 });
8268 }
8269
8270 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008271 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008272 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008273 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008274
8275 final long identity = Binder.clearCallingIdentity();
8276 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008277 ImsManager.getInstance(defaultPhone.getContext(),
8278 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008279 } finally {
8280 Binder.restoreCallingIdentity(identity);
8281 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008282 }
8283
8284 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008285 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008286 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008287 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8288 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008289 return false;
8290 }
Svet Ganovb320e182015-04-16 12:30:10 -07008291
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008292 final long identity = Binder.clearCallingIdentity();
8293 try {
8294 // Check the user preference and the system-level IMS setting. Even if the user has
8295 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8296 // In the long run, we may instead need to check if there exists a connection service
8297 // which can support video calling.
8298 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008299 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008300 return imsManager.isVtEnabledByPlatform()
8301 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8302 && imsManager.isVtEnabledByUser();
8303 } finally {
8304 Binder.restoreCallingIdentity(identity);
8305 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008306 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008307
Andrew Leea1239f22015-03-02 17:44:07 -08008308 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008309 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8310 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008311 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008312 mApp, subId, callingPackage, callingFeatureId,
8313 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008314 return false;
8315 }
8316
8317 final long identity = Binder.clearCallingIdentity();
8318 try {
8319 CarrierConfigManager configManager =
8320 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008321 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008322 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8323 } finally {
8324 Binder.restoreCallingIdentity(identity);
8325 }
Andrew Leea1239f22015-03-02 17:44:07 -08008326 }
8327
8328 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008329 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008330 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008331 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008332 return false;
8333 }
8334
8335 final long identity = Binder.clearCallingIdentity();
8336 try {
8337 CarrierConfigManager configManager =
8338 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008339 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008340 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8341 } finally {
8342 Binder.restoreCallingIdentity(identity);
8343 }
Andrew Leea1239f22015-03-02 17:44:07 -08008344 }
8345
Andrew Lee9431b832015-03-09 18:46:45 -07008346 @Override
8347 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008348 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008349 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008350 }
8351
8352 @Override
8353 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008354 final long identity = Binder.clearCallingIdentity();
8355 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008356 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008357 } finally {
8358 Binder.restoreCallingIdentity(identity);
8359 }
Andrew Lee9431b832015-03-09 18:46:45 -07008360 }
8361
Hall Liuf6668912018-10-31 17:05:23 -07008362 /**
8363 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8364 * support for the feature and device firmware support.
8365 *
8366 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8367 */
8368 @Override
8369 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008370 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008371 final Phone phone = getPhone(subscriptionId);
8372 if (phone == null) {
8373 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8374 return false;
8375 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008376 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008377 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008378 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
8379 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008380 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008381 return isCarrierSupported && isDeviceSupported;
8382 } finally {
8383 Binder.restoreCallingIdentity(identity);
8384 }
Hall Liu98187582018-01-22 19:15:32 -08008385 }
8386
Hall Liuf6668912018-10-31 17:05:23 -07008387 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008388 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8389 * RTT setting, will return true if the device and carrier both support RTT.
8390 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008391 */
8392 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008393 final long identity = Binder.clearCallingIdentity();
8394 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00008395 boolean isRttSupported = isRttSupported(subscriptionId);
8396 boolean isUserRttSettingOn = Settings.Secure.getInt(
8397 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8398 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8399 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8400 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008401 } finally {
8402 Binder.restoreCallingIdentity(identity);
8403 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008404 }
8405
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008406 @Deprecated
8407 @Override
8408 public String getDeviceId(String callingPackage) {
8409 return getDeviceIdWithFeature(callingPackage, null);
8410 }
8411
Sanket Padawe7310cc72015-01-14 09:53:20 -08008412 /**
8413 * Returns the unique device ID of phone, for example, the IMEI for
8414 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8415 *
8416 * <p>Requires Permission:
8417 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8418 */
8419 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008420 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008421 try {
8422 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8423 } catch (SecurityException se) {
8424 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8425 throw new SecurityException("Package " + callingPackage + " does not belong to "
8426 + Binder.getCallingUid());
8427 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008428 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008429 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008430 return null;
8431 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008432 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008433 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008434 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008435 return null;
8436 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008437
8438 final long identity = Binder.clearCallingIdentity();
8439 try {
8440 return phone.getDeviceId();
8441 } finally {
8442 Binder.restoreCallingIdentity(identity);
8443 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008444 }
8445
Ping Sunc67b7c22016-03-02 19:16:45 +08008446 /**
8447 * {@hide}
8448 * Returns the IMS Registration Status on a particular subid
8449 *
8450 * @param subId
8451 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008452 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008453 Phone phone = getPhone(subId);
8454 if (phone != null) {
8455 return phone.isImsRegistered();
8456 } else {
8457 return false;
8458 }
8459 }
8460
Santos Cordon7a1885b2015-02-03 11:15:19 -08008461 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008462 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008463 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008464 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008465 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008466 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8467 }
8468 final long identity = Binder.clearCallingIdentity();
8469 try {
8470 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8471 } finally {
8472 Binder.restoreCallingIdentity(identity);
8473 }
8474 }
8475
8476 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008477 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008478 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008479 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008480 mApp,
8481 subscriptionId,
8482 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8483 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07008484 final long identity = Binder.clearCallingIdentity();
8485 try {
8486 Phone phone = getPhone(subscriptionId);
8487 if (phone == null) {
8488 return null;
8489 }
8490 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8491 } finally {
8492 Binder.restoreCallingIdentity(identity);
8493 }
8494 }
8495
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008496 /**
8497 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008498 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008499 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008500 final long identity = Binder.clearCallingIdentity();
8501 try {
8502 Phone phone = getPhone(subId);
8503 if (phone != null) {
8504 return phone.isWifiCallingEnabled();
8505 } else {
8506 return false;
8507 }
8508 } finally {
8509 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008510 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008511 }
8512
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008513 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008514 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008515 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008516 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008517 final long identity = Binder.clearCallingIdentity();
8518 try {
8519 Phone phone = getPhone(subId);
8520 if (phone != null) {
8521 return phone.isVideoEnabled();
8522 } else {
8523 return false;
8524 }
8525 } finally {
8526 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008527 }
8528 }
8529
8530 /**
8531 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8532 * defined in {@link ImsRegistrationImplBase}.
8533 */
8534 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008535 final long identity = Binder.clearCallingIdentity();
8536 try {
8537 Phone phone = getPhone(subId);
8538 if (phone != null) {
8539 return phone.getImsRegistrationTech();
8540 } else {
8541 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8542 }
8543 } finally {
8544 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008545 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008546 }
8547
Stuart Scott8eef64f2015-04-08 15:13:54 -07008548 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008549 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008550 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07008551 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8552 return;
8553 }
Kai Shif70f46f2021-03-03 13:59:46 -08008554 Phone defaultPhone = getDefaultPhone();
8555 if (defaultPhone != null) {
8556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8557 mApp, getDefaultPhone().getSubId(), "factoryReset");
8558 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008559 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008560
Svet Ganovcc087f82015-05-12 20:35:54 -07008561 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008562 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8563 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008564 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008565 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008566 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008567 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008568 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008569 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08008570 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008571 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008572 // There has been issues when Sms raw table somehow stores orphan
8573 // fragments. They lead to garbled message when new fragments come
8574 // in and combined with those stale ones. In case this happens again,
8575 // user can reset all network settings which will clean up this table.
8576 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008577 // Clean up IMS settings as well here.
8578 int slotId = getSlotIndex(subId);
8579 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8580 ImsManager.getInstance(mApp, slotId).factoryReset();
8581 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008582
Kai Shif70f46f2021-03-03 13:59:46 -08008583 if (defaultPhone == null) {
8584 return;
8585 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008586 // Erase modem config if erase modem on network setting is enabled.
8587 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8588 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8589 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008590 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008591 }
Kai Shif70f46f2021-03-03 13:59:46 -08008592
8593 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008594 } finally {
8595 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008596 }
8597 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008598
SongFerngWangfd89b102021-05-27 22:44:54 +08008599 @VisibleForTesting
8600 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8601 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8602 return;
8603 }
8604 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8605 RILConstants.PREFERRED_NETWORK_MODE);
8606 SubscriptionManager.setSubscriptionProperty(subId,
8607 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8608 "user=" + defaultNetworkType);
8609 phone.loadAllowedNetworksFromSubscriptionDatabase();
8610 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8611 defaultNetworkType, null);
8612 }
8613
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008614 private void cleanUpSmsRawTable(Context context) {
8615 ContentResolver resolver = context.getContentResolver();
8616 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8617 resolver.delete(uri, null, null);
8618 }
8619
Narayan Kamath1c496c22015-04-16 14:40:19 +01008620 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008621 public String getSimLocaleForSubscriber(int subId) {
8622 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
8623 final Phone phone = getPhone(subId);
8624 if (phone == null) {
8625 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008626 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008627 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008628 final long identity = Binder.clearCallingIdentity();
8629 try {
Jack Yu285100e2022-12-02 22:48:35 -08008630 SubscriptionInfo info;
8631 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008632 info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
Jack Yu285100e2022-12-02 22:48:35 -08008633 phone.getContext().getOpPackageName(),
8634 phone.getContext().getAttributionTag());
8635 if (info == null) {
8636 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8637 return null;
8638 }
8639 } else {
8640 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
8641 phone.getContext().getOpPackageName(),
8642 phone.getContext().getAttributionTag());
8643 if (info == null) {
8644 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8645 return null;
8646 }
chen xu6291c472019-02-04 12:55:53 -08008647 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008648 // Try and fetch the locale from the carrier properties or from the SIM language
8649 // preferences (EF-PL and EF-LI)...
8650 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008651 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008652 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8653 if (localeFromDefaultSim != null) {
8654 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8655 if (DBG) log("Using locale from subId: " + subId + " locale: "
8656 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008657 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008658 } else {
8659 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008660 }
8661 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008662
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008663 // The SIM language preferences only store a language (e.g. fr = French), not an
8664 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8665 // the SIM and carrier preferences does not include a country we add the country
8666 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008667 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008668 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008669 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008670 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008671 }
8672
8673 if (DBG) log("No locale found - returning null");
8674 return null;
8675 } finally {
8676 Binder.restoreCallingIdentity(identity);
8677 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008678 }
8679
tom hsu0b59d292022-09-29 23:49:21 +08008680 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008681 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008682 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008683 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008684 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008685 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8686 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008687 Locale.forLanguageTag(localeTag).getCountry())) {
8688 return localeTag;
8689 }
8690 }
8691 return inputLocale.toLanguageTag();
8692 }
8693
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008694 /**
8695 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8696 */
8697 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08008698 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008699 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Jack Yu285100e2022-12-02 22:48:35 -08008700 mApp.getOpPackageName(), mApp.getAttributionTag());
8701 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008702 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08008703 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008704 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008705
Gary Jian3aa9a762022-01-24 16:41:19 +08008706 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8707 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008708
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008709 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008710 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8711 * representing the state of the modem.
8712 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008713 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8714 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008715 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008716 */
8717 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008718 public void requestModemActivityInfo(ResultReceiver result) {
8719 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008720 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008721
8722 final long identity = Binder.clearCallingIdentity();
8723 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008724 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008725 } finally {
8726 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008727 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008728 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008729
Gary Jian76280a42022-12-07 16:18:33 +08008730 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008731 // less than total activity duration.
8732 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8733 if (info == null) {
8734 return false;
8735 }
8736 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008737 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008738 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8739
Hall Liu49656c02020-10-09 19:00:11 -07008740 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8741
Siddharth Rayb8114062018-06-17 15:02:38 -07008742 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008743 && (info.getSleepTimeMillis() <= activityDurationMs)
8744 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008745 }
8746
Gary Jian3aa9a762022-01-24 16:41:19 +08008747 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8748 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8749 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8750 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8751
8752 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8753 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8754 }
8755
8756 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8757 mLastModemActivityInfo.setReceiveTimeMillis(
8758 rat,
8759 freq,
8760 info.getReceiveTimeMillis(rat, freq)
8761 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8762 }
8763
8764 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8765 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8766 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8767 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8768
8769 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8770 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8771 }
8772 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8773 mLastModemActivityInfo.setReceiveTimeMillis(
8774 rat,
8775 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8776 }
8777
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008778 /**
8779 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8780 * @param info recent ModemActivityInfo
8781 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008782 private void mergeModemActivityInfo(ModemActivityInfo info) {
8783 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008784 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008785 boolean matched;
8786 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8787 matched = false;
8788 int rat = info.getSpecificInfoRat(i);
8789 int freq = info.getSpecificInfoFrequencyRange(i);
8790 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8791 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8792 //if it already exists
8793 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8794 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8795 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8796 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8797 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8798 updateLastModemActivityInfo(info, rat, freq);
8799 matched = true;
8800 }
8801 } else {
8802 updateLastModemActivityInfo(info, rat);
8803 matched = true;
8804 }
8805 }
8806 }
8807
8808 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008809 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008810 new ActivityStatsTechSpecificInfo(
8811 rat,
8812 freq,
8813 info.getTransmitTimeMillis(rat, freq),
8814 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008815 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008816 }
8817 }
8818 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8819 mLastModemActivitySpecificInfo =
8820 new ActivityStatsTechSpecificInfo[merged.size()];
8821 merged.toArray(mLastModemActivitySpecificInfo);
8822
8823 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8824 mLastModemActivityInfo.setSleepTimeMillis(
8825 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008826 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008827 mLastModemActivityInfo.setIdleTimeMillis(
8828 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008829 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008830
8831 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008832 new ModemActivityInfo(
8833 mLastModemActivityInfo.getTimestampMillis(),
8834 mLastModemActivityInfo.getSleepTimeMillis(),
8835 mLastModemActivityInfo.getIdleTimeMillis(),
8836 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008837 }
8838
8839 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8840 ActivityStatsTechSpecificInfo[] info) {
8841 int infoSize = info.length;
8842 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8843 for (int i = 0; i < infoSize; i++) {
8844 ret[i] = new ActivityStatsTechSpecificInfo(
8845 info[i].getRat(), info[i].getFrequencyRange(),
8846 info[i].getTransmitTimeMillis(),
8847 (int) info[i].getReceiveTimeMillis());
8848 }
8849 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008850 }
8851
Jack Yu85bd38a2015-11-09 11:34:32 -08008852 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008853 * Returns the service state information on specified subscription.
8854 */
8855 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008856 public ServiceState getServiceStateForSubscriber(int subId,
8857 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8858 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008859 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008860 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008861 return null;
8862 }
8863
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008864 boolean hasFinePermission = false;
8865 boolean hasCoarsePermission = false;
8866 if (!renounceFineLocationAccess) {
8867 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8868 LocationAccessPolicy.checkLocationPermission(mApp,
8869 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8870 .setCallingPackage(callingPackage)
8871 .setCallingFeatureId(callingFeatureId)
8872 .setCallingPid(Binder.getCallingPid())
8873 .setCallingUid(Binder.getCallingUid())
8874 .setMethod("getServiceStateForSubscriber")
8875 .setLogAsInfo(true)
8876 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8877 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8878 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8879 .build());
8880 hasFinePermission =
8881 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8882 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008883
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008884 if (!renounceCoarseLocationAccess) {
8885 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8886 LocationAccessPolicy.checkLocationPermission(mApp,
8887 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8888 .setCallingPackage(callingPackage)
8889 .setCallingFeatureId(callingFeatureId)
8890 .setCallingPid(Binder.getCallingPid())
8891 .setCallingUid(Binder.getCallingUid())
8892 .setMethod("getServiceStateForSubscriber")
8893 .setLogAsInfo(true)
8894 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8895 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8896 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8897 .build());
8898 hasCoarsePermission =
8899 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8900 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008901
Jack Yu479f40e2020-10-27 21:29:25 -07008902 final Phone phone = getPhone(subId);
8903 if (phone == null) {
8904 return null;
8905 }
8906
Jordan Liu0f2bc442020-11-18 16:47:37 -08008907 final long identity = Binder.clearCallingIdentity();
8908
Jack Yu479f40e2020-10-27 21:29:25 -07008909 boolean isCallingPackageDataService = phone.getDataServicePackages()
8910 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008911 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008912 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008913 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008914 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08008915 .getSubscriptionInfoInternal(subId);
8916 if (subInfo == null || !subInfo.isActive()) {
8917 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8918 + "subId=" + subId);
8919 return null;
8920 }
8921 } else {
8922 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8923 callingFeatureId)) {
8924 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8925 + "subId=" + subId);
8926 return null;
8927 }
Jordan Liuc437b192020-08-17 10:59:12 -07008928 }
8929
Hall Liuf19c44f2018-11-27 14:38:17 -08008930 ServiceState ss = phone.getServiceState();
8931
8932 // Scrub out the location info in ServiceState depending on what level of access
8933 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008934 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008935 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8936 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008937 } finally {
8938 Binder.restoreCallingIdentity(identity);
8939 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008940 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008941
8942 /**
8943 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8944 *
8945 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8946 * voicemail ringtone.
8947 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8948 * PhoneAccount.
8949 */
8950 @Override
8951 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008952 final long identity = Binder.clearCallingIdentity();
8953 try {
8954 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8955 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008956 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008957 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008958
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008959 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8960 } finally {
8961 Binder.restoreCallingIdentity(identity);
8962 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008963 }
8964
8965 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008966 * Sets the per-account voicemail ringtone.
8967 *
8968 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8969 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8970 *
8971 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8972 * voicemail ringtone.
8973 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8974 * PhoneAccount.
8975 */
8976 @Override
8977 public void setVoicemailRingtoneUri(String callingPackage,
8978 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008979 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008980 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008981 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8982 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8984 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8985 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008986 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008987
8988 final long identity = Binder.clearCallingIdentity();
8989 try {
8990 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8991 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008992 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008993 }
8994 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8995 } finally {
8996 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008997 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008998 }
8999
9000 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08009001 * Returns whether vibration is set for voicemail notification in Phone settings.
9002 *
9003 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
9004 * voicemail vibration setting.
9005 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
9006 */
9007 @Override
9008 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009009 final long identity = Binder.clearCallingIdentity();
9010 try {
9011 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9012 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009013 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009014 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009015
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009016 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
9017 } finally {
9018 Binder.restoreCallingIdentity(identity);
9019 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009020 }
9021
Youhan Wange64578a2016-05-02 15:32:42 -07009022 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009023 * Sets the per-account voicemail vibration.
9024 *
9025 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9026 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9027 *
9028 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9029 * voicemail vibration setting.
9030 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9031 * specific PhoneAccount.
9032 */
9033 @Override
9034 public void setVoicemailVibrationEnabled(String callingPackage,
9035 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009036 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009037 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009038 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9039 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009040 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9041 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9042 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009043 }
9044
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009045 final long identity = Binder.clearCallingIdentity();
9046 try {
9047 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9048 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009049 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009050 }
9051 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9052 } finally {
9053 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009054 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009055 }
9056
9057 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009058 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9059 *
9060 * @throws SecurityException if the caller does not have the required permission
9061 */
arunvoddud7401012022-12-15 16:08:12 +00009062 @VisibleForTesting
9063 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009064 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009065 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009066 }
9067
9068 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009069 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9070 * permission.
9071 *
9072 * @throws SecurityException if the caller does not have the required permission
9073 */
9074 private void enforceSendSmsPermission() {
9075 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9076 }
9077
9078 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009079 * Make sure either called from same process as self (phone) or IPC caller has interact across
9080 * users permission.
9081 *
9082 * @throws SecurityException if the caller does not have the required permission
9083 */
9084 private void enforceInteractAcrossUsersPermission(String message) {
9085 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9086 }
9087
9088 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009089 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009090 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009091 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009092 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009093 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009094 final long identity = Binder.clearCallingIdentity();
9095 try {
9096 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009097 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009098 if (componentName == null) {
9099 throw new SecurityException(
9100 "Caller not current active visual voicemail package[null]");
9101 }
9102 String vvmPackage = componentName.getPackageName();
9103 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009104 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009105 }
9106 } finally {
9107 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009108 }
9109 }
9110
9111 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009112 * Return the application ID for the app type.
9113 *
9114 * @param subId the subscription ID that this request applies to.
9115 * @param appType the uicc app type.
9116 * @return Application ID for specificied app type, or null if no uicc.
9117 */
9118 @Override
9119 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009120 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07009121 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009122
9123 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009124 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009125 if (phone == null) {
9126 return null;
9127 }
9128 String aid = null;
9129 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009130 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009131 .getApplicationByType(appType).getAid();
9132 } catch (Exception e) {
9133 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9134 }
9135 return aid;
9136 } finally {
9137 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009138 }
Youhan Wange64578a2016-05-02 15:32:42 -07009139 }
9140
Youhan Wang4001d252016-05-11 10:29:41 -07009141 /**
9142 * Return the Electronic Serial Number.
9143 *
9144 * @param subId the subscription ID that this request applies to.
9145 * @return ESN or null if error.
9146 */
9147 @Override
9148 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009149 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009150 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009151
9152 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009153 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009154 if (phone == null) {
9155 return null;
9156 }
9157 String esn = null;
9158 try {
9159 esn = phone.getEsn();
9160 } catch (Exception e) {
9161 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9162 }
9163 return esn;
9164 } finally {
9165 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009166 }
Youhan Wang4001d252016-05-11 10:29:41 -07009167 }
9168
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009169 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009170 * Return the Preferred Roaming List Version.
9171 *
9172 * @param subId the subscription ID that this request applies to.
9173 * @return PRLVersion or null if error.
9174 */
9175 @Override
9176 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009177 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07009178 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009179
9180 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009181 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009182 if (phone == null) {
9183 return null;
9184 }
9185 String cdmaPrlVersion = null;
9186 try {
9187 cdmaPrlVersion = phone.getCdmaPrlVersion();
9188 } catch (Exception e) {
9189 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9190 }
9191 return cdmaPrlVersion;
9192 } finally {
9193 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009194 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009195 }
9196
9197 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009198 * Get snapshot of Telephony histograms
9199 * @return List of Telephony histograms
9200 * @hide
9201 */
9202 @Override
9203 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9205 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009206
9207 final long identity = Binder.clearCallingIdentity();
9208 try {
9209 return RIL.getTelephonyRILTimingHistograms();
9210 } finally {
9211 Binder.restoreCallingIdentity(identity);
9212 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009213 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009214
9215 /**
9216 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009217 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9218 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009219 * Require system privileges. In the future we may add this to carrier APIs.
9220 *
Michele Berionne482f8202018-11-27 18:57:59 -08009221 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009222 */
9223 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009224 @TelephonyManager.SetCarrierRestrictionResult
9225 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009226 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07009227 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009228
Michele Berionne482f8202018-11-27 18:57:59 -08009229 if (carrierRestrictionRules == null) {
9230 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009231 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009232
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009233 final long identity = Binder.clearCallingIdentity();
9234 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009235 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009236 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009237 } finally {
9238 Binder.restoreCallingIdentity(identity);
9239 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009240 }
9241
9242 /**
9243 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009244 * Get the allowed carrier list and the excluded carrier list, including the priority between
9245 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009246 * Require system privileges. In the future we may add this to carrier APIs.
9247 *
Michele Berionne482f8202018-11-27 18:57:59 -08009248 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009249 */
9250 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009251 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009252 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07009253 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009254
9255 final long identity = Binder.clearCallingIdentity();
9256 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009257 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9258 if (response instanceof CarrierRestrictionRules) {
9259 return (CarrierRestrictionRules) response;
9260 }
9261 // Response is an Exception of some kind,
9262 // which is signalled to the user as a NULL retval
9263 return null;
9264 } catch (Exception e) {
9265 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9266 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009267 } finally {
9268 Binder.restoreCallingIdentity(identity);
9269 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009270 }
9271
fionaxu59545b42016-05-25 15:53:37 -07009272 /**
arunvoddud7401012022-12-15 16:08:12 +00009273 * Fetches the carrier restriction status of the device and sends the status to the caller
9274 * through the callback.
9275 *
9276 * @param callback The callback that will be used to send the result.
9277 * @throws SecurityException if the caller does not have the required permission/privileges or
9278 * the caller is not allowlisted.
9279 */
9280 @Override
9281 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9282 enforceReadPermission("getCarrierRestrictionStatus");
9283 int carrierId = validateCallerAndGetCarrierId(packageName);
9284 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
9285 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9286 throw new SecurityException("Not an authorized caller");
9287 }
9288 final long identity = Binder.clearCallingIdentity();
9289 try {
9290 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
9291 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
9292 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9293 } finally {
9294 Binder.restoreCallingIdentity(identity);
9295 }
9296 }
9297
9298 @VisibleForTesting
9299 public int validateCallerAndGetCarrierId(String packageName) {
9300 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9301 return allowListInfo.validateCallerAndGetCarrierId(packageName);
9302 }
9303
9304 /**
fionaxu59545b42016-05-25 15:53:37 -07009305 * Action set from carrier signalling broadcast receivers to enable/disable radio
9306 * @param subId the subscription ID that this action applies to.
9307 * @param enabled control enable or disable radio.
9308 * {@hide}
9309 */
9310 @Override
9311 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9312 enforceModifyPermission();
9313 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009314
9315 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009316 if (phone == null) {
9317 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9318 return;
9319 }
9320 try {
9321 phone.carrierActionSetRadioEnabled(enabled);
9322 } catch (Exception e) {
9323 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009324 } finally {
9325 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009326 }
9327 }
9328
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009329 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009330 * Enable or disable Voice over NR (VoNR)
9331 * @param subId the subscription ID that this action applies to.
9332 * @param enabled enable or disable VoNR.
9333 * @return operation result.
9334 */
9335 @Override
9336 public int setVoNrEnabled(int subId, boolean enabled) {
9337 enforceModifyPermission();
9338 final Phone phone = getPhone(subId);
9339
9340 final long identity = Binder.clearCallingIdentity();
9341 if (phone == null) {
9342 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9343 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9344 }
9345
9346 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9347 try {
9348 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9349 workSource);
9350 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009351
9352 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9353 if (DBG) {
9354 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9355 }
9356 SubscriptionManager.setSubscriptionProperty(
9357 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9358 (enabled ? "1" : "0"));
9359 }
9360
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009361 return result;
9362 } finally {
9363 Binder.restoreCallingIdentity(identity);
9364 }
9365 }
9366
9367 /**
9368 * Is voice over NR enabled
9369 * @return true if VoNR is enabled else false
9370 */
9371 @Override
9372 public boolean isVoNrEnabled(int subId) {
9373 enforceReadPrivilegedPermission("isVoNrEnabled");
9374 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9375 final long identity = Binder.clearCallingIdentity();
9376 try {
9377 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9378 null, subId, workSource);
9379 if (DBG) log("isVoNrEnabled: " + isEnabled);
9380 return isEnabled;
9381 } finally {
9382 Binder.restoreCallingIdentity(identity);
9383 }
9384 }
9385
9386 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009387 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9388 * network status based on which carrier apps could apply actions accordingly,
9389 * enable/disable default url handler for example.
9390 *
9391 * @param subId the subscription ID that this action applies to.
9392 * @param report control start/stop reporting the default network status.
9393 * {@hide}
9394 */
9395 @Override
9396 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9397 enforceModifyPermission();
9398 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009399
9400 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009401 if (phone == null) {
9402 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9403 return;
9404 }
9405 try {
9406 phone.carrierActionReportDefaultNetworkStatus(report);
9407 } catch (Exception e) {
9408 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009409 } finally {
9410 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009411 }
9412 }
9413
9414 /**
fionaxud9622282017-07-17 17:51:30 -07009415 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9416 * @param subId the subscription ID that this action applies to.
9417 * {@hide}
9418 */
9419 @Override
9420 public void carrierActionResetAll(int subId) {
9421 enforceModifyPermission();
9422 final Phone phone = getPhone(subId);
9423 if (phone == null) {
9424 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9425 return;
9426 }
9427 try {
9428 phone.carrierActionResetAll();
9429 } catch (Exception e) {
9430 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9431 }
9432 }
9433
9434 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009435 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9436 * bug report is being generated.
9437 */
9438 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009439 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009440 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9441 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009442 writer.println("Permission Denial: can't dump Phone from pid="
9443 + Binder.getCallingPid()
9444 + ", uid=" + Binder.getCallingUid()
9445 + "without permission "
9446 + android.Manifest.permission.DUMP);
9447 return;
9448 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009449 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009450 }
Jack Yueb89b242016-06-22 13:27:47 -07009451
Brad Ebingerdac2f002018-04-03 15:17:52 -07009452 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009453 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9454 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9455 @NonNull String[] args) {
9456 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9457 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009458 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009459 }
9460
Jack Yueb89b242016-06-22 13:27:47 -07009461 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009462 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009463 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009464 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009465 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009466 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009467 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009468 */
9469 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009470 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009471 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009472 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9473 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9474 try {
9475 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009476 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009477 } catch (SecurityException se) {
9478 enforceModifyPermission();
9479 }
9480 } else {
9481 enforceModifyPermission();
9482 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009483
9484 final long identity = Binder.clearCallingIdentity();
9485 try {
9486 Phone phone = getPhone(subId);
9487 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009488 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9489 phone.carrierActionSetMeteredApnsEnabled(enabled);
9490 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009491 phone.getDataSettingsManager().setDataEnabled(
9492 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009493 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009494 }
9495 } finally {
9496 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009497 }
9498 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009499
9500 /**
9501 * Get Client request stats
9502 * @return List of Client Request Stats
9503 * @hide
9504 */
9505 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009506 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9507 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009508 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009509 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009510 return null;
9511 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009512 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009513
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009514 final long identity = Binder.clearCallingIdentity();
9515 try {
9516 if (phone != null) {
9517 return phone.getClientRequestStats();
9518 }
9519
9520 return null;
9521 } finally {
9522 Binder.restoreCallingIdentity(identity);
9523 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009524 }
9525
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009526 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009527 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009528 if (uid == Process.ROOT_UID && packageName == null) {
9529 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9530 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9531 // exception. ROOT_UID seems not to have a valid package name returned by
9532 // PackageManager, so just fake it here to avoid issues when running telephony shell
9533 // commands that plumb through the RIL as root, like so:
9534 // $ adb root
9535 // $ adb shell cmd phone ...
9536 packageName = "root";
9537 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009538 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009539 }
Jack Yueb4124c2017-02-16 15:32:43 -08009540
9541 /**
Grace Chen70990072017-03-24 17:21:30 -07009542 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009543 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009544 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009545 * @param state State of SIM (power down, power up, pass through)
9546 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9547 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9548 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009549 *
9550 **/
9551 @Override
Grace Chen70990072017-03-24 17:21:30 -07009552 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009553 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009554 Phone phone = PhoneFactory.getPhone(slotIndex);
9555
vagdeviaf9a5b92018-08-15 16:01:53 -07009556 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9557
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009558 final long identity = Binder.clearCallingIdentity();
9559 try {
9560 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009561 phone.setSimPowerState(state, null, workSource);
9562 }
9563 } finally {
9564 Binder.restoreCallingIdentity(identity);
9565 }
9566 }
9567
9568 /**
9569 * Set SIM card power state.
9570 *
9571 * @param slotIndex SIM slot id.
9572 * @param state State of SIM (power down, power up, pass through)
9573 * @param callback callback to trigger after success or failure
9574 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9575 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9576 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9577 *
9578 **/
9579 @Override
9580 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9581 IIntegerConsumer callback) {
9582 enforceModifyPermission();
9583 Phone phone = PhoneFactory.getPhone(slotIndex);
9584
9585 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9586
9587 final long identity = Binder.clearCallingIdentity();
9588 try {
9589 if (phone != null) {
9590 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9591 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009592 }
9593 } finally {
9594 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009595 }
9596 }
Shuo Qiandd210312017-04-12 22:11:33 +00009597
Tyler Gunn65d45c22017-06-05 11:22:26 -07009598 private boolean isUssdApiAllowed(int subId) {
9599 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009600 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009601 if (configManager == null) {
9602 return false;
9603 }
9604 PersistableBundle pb = configManager.getConfigForSubId(subId);
9605 if (pb == null) {
9606 return false;
9607 }
9608 return pb.getBoolean(
9609 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9610 }
9611
Shuo Qiandd210312017-04-12 22:11:33 +00009612 /**
9613 * Check if phone is in emergency callback mode
9614 * @return true if phone is in emergency callback mode
9615 * @param subId sub id
9616 */
goneil9c5f4872017-12-05 14:07:56 -08009617 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009618 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009619 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00009620 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009621
9622 final long identity = Binder.clearCallingIdentity();
9623 try {
9624 if (phone != null) {
9625 return phone.isInEcm();
9626 } else {
9627 return false;
9628 }
9629 } finally {
9630 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009631 }
9632 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009633
9634 /**
9635 * Get the current signal strength information for the given subscription.
9636 * Because this information is not updated when the device is in a low power state
9637 * it should not be relied-upon to be current.
9638 * @param subId Subscription index
9639 * @return the most recent cached signal strength info from the modem
9640 */
9641 @Override
9642 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009643 final long identity = Binder.clearCallingIdentity();
9644 try {
9645 Phone p = getPhone(subId);
9646 if (p == null) {
9647 return null;
9648 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009649
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009650 return p.getSignalStrength();
9651 } finally {
9652 Binder.restoreCallingIdentity(identity);
9653 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009654 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009655
Pengquan Meng77b7f132018-08-22 14:49:57 -07009656 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009657 * Get the current modem radio state for the given slot.
9658 * @param slotIndex slot index.
9659 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009660 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009661 * @return the current radio power state from the modem
9662 */
9663 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009664 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009665 Phone phone = PhoneFactory.getPhone(slotIndex);
9666 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009667 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9668 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009669 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9670 }
9671
9672 final long identity = Binder.clearCallingIdentity();
9673 try {
9674 return phone.getRadioPowerState();
9675 } finally {
9676 Binder.restoreCallingIdentity(identity);
9677 }
9678 }
9679 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9680 }
9681
9682 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009683 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9684 *
9685 * <p>Requires one of the following permissions:
9686 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009687 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009688 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9689 * privileges.
9690 *
9691 * @param subId subscription id
9692 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9693 * {@code false}.
9694 */
9695 @Override
9696 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009697 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009698 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009699 try {
9700 mApp.enforceCallingOrSelfPermission(
9701 android.Manifest.permission.ACCESS_NETWORK_STATE,
9702 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009703 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009704 mApp.enforceCallingOrSelfPermission(
9705 permission.READ_BASIC_PHONE_STATE, functionName);
9706 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009707 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009708 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009709 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009710 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009711
Pengquan Menga1bb6272018-09-06 09:59:22 -07009712 boolean isEnabled = false;
9713 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009714 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009715 Phone phone = getPhone(subId);
9716 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009717 } finally {
9718 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009719 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009720 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009721 }
9722
9723
9724 /**
9725 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9726 *
9727 * <p> Requires permission:
9728 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9729 * privileges.
9730 *
9731 * @param subId subscription id
9732 * @param isEnabled {@code true} means enable, {@code false} means disable.
9733 */
9734 @Override
9735 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009736 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9737 mApp, subId, "setDataRoamingEnabled");
9738
Pengquan Menga1bb6272018-09-06 09:59:22 -07009739 final long identity = Binder.clearCallingIdentity();
9740 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009741 Phone phone = getPhone(subId);
9742 if (phone != null) {
9743 phone.setDataRoamingEnabled(isEnabled);
9744 }
9745 } finally {
9746 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009747 }
9748 }
9749
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009750 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009751 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009752 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009753 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009754 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009755
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009756 boolean isAllowed = true;
9757 final long identity = Binder.clearCallingIdentity();
9758 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009759 Phone phone = getPhone(subId);
9760 if (phone != null) {
9761 isAllowed = phone.isCspPlmnEnabled();
9762 }
9763 } finally {
9764 Binder.restoreCallingIdentity(identity);
9765 }
9766 return isAllowed;
9767 }
9768
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009769 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9770 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009771 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009772 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009773 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009774 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9775 if (phone == null) {
9776 return false;
9777 }
9778 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9779 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9780 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009781 }
9782
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009783 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009784 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009785 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009786 mApp.getSystemService(AppOpsManager.class)
9787 .checkPackage(Binder.getCallingUid(), callingPackage);
9788
Jordan Liu1e142fc2019-04-22 15:10:43 -07009789 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009790 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009791 try {
9792 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009793 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009794 } catch (SecurityException e) {
9795 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9796 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009797 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009798 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009799 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009800 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009801 }
sandeepjsb6c87872021-09-27 15:34:44 +00009802 // checking compatibility, if calling app's target SDK is T and beyond.
9803 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9804 Binder.getCallingUid())) {
9805 isIccIdAccessRestricted = true;
9806 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009807 final long identity = Binder.clearCallingIdentity();
9808 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009809 UiccController uiccController = UiccController.getInstance();
9810 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009811 if (hasReadPermission) {
9812 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009813 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009814
9815 // Remove private info if the caller doesn't have access
9816 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9817 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009818 //setting the value after compatibility check
9819 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009820 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9821 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009822 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009823 if (card == null) {
9824 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009825 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009826 continue;
9827 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009828 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9829 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009830 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009831 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009832 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009833 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9834 for (UiccPortInfo portInfo : portInfos) {
9835 UiccPort port = uiccController.getUiccPortForSlot(
9836 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9837 if (port == null) {
9838 // assume no access if port is null
9839 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9840 continue;
9841 }
9842 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9843 uiccPortInfos.add(portInfo);
9844 } else {
9845 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9846 }
9847 }
9848 filteredInfos.add(new UiccCardInfo(
9849 cardInfo.isEuicc(),
9850 cardInfo.getCardId(),
9851 null,
9852 cardInfo.getPhysicalSlotIndex(),
9853 cardInfo.isRemovable(),
9854 cardInfo.isMultipleEnabledProfilesSupported(),
9855 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009856 }
9857 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009858 } finally {
9859 Binder.restoreCallingIdentity(identity);
9860 }
9861 }
9862
sandeepjsb6c87872021-09-27 15:34:44 +00009863 /**
9864 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9865 * generally private and require carrier privileges to view.
9866 *
9867 * @hide
9868 */
9869 @NonNull
9870 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9871 List<UiccPortInfo> portinfo = new ArrayList<>();
9872 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9873 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9874 }
9875 return new UiccCardInfo(
9876 cardInfo.isEuicc(),
9877 cardInfo.getCardId(),
9878 null,
9879 cardInfo.getPhysicalSlotIndex(),
9880 cardInfo.isRemovable(),
9881 cardInfo.isMultipleEnabledProfilesSupported(),
9882 portinfo
9883 );
9884 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009885
sandeepjsb6c87872021-09-27 15:34:44 +00009886 /**
9887 * @hide
9888 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9889 * These values are generally private and require carrier privileges to view.
9890 */
9891 @NonNull
9892 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9893 return new UiccPortInfo(
9894 UiccPortInfo.ICCID_REDACTED,
9895 portInfo.getPortIndex(),
9896 portInfo.getLogicalSlotIndex(),
9897 portInfo.isActive()
9898 );
9899 }
9900 @Override
9901 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009902 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009903 mApp.getSystemService(AppOpsManager.class)
9904 .checkPackage(Binder.getCallingUid(), callingPackage);
9905
sandeepjsb6c87872021-09-27 15:34:44 +00009906 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009907
Aman Guptaf3c90b32022-03-17 04:54:16 +00009908 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9909 // we are reading iccId which is PII data.
9910 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009911
9912 // checking compatibility, if calling app's target SDK is T and beyond.
9913 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9914 Binder.getCallingUid())) {
9915 isLogicalSlotAccessRestricted = true;
9916 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009917 final long identity = Binder.clearCallingIdentity();
9918 try {
9919 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009920 if (slots == null || slots.length == 0) {
9921 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009922 return null;
9923 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009924 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9925 for (int i = 0; i < slots.length; i++) {
9926 UiccSlot slot = slots[i];
9927 if (slot == null) {
9928 continue;
9929 }
9930
Jordan Liu7be7e652019-05-06 18:55:02 +00009931 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009932 UiccCard card = slot.getUiccCard();
9933 if (card != null) {
9934 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009935 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009936 cardId = slot.getEid();
9937 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009938 // If cardId is null, use iccId of default port as cardId.
9939 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009940 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009941 }
9942
Jordan Liu857451f2019-05-09 16:35:35 -07009943 if (cardId != null) {
9944 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9945 // if cardId is an EID, it's all digits so this is fine
9946 cardId = IccUtils.stripTrailingFs(cardId);
9947 }
9948
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009949 int cardState = 0;
9950 switch (slot.getCardState()) {
9951 case CARDSTATE_ABSENT:
9952 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9953 break;
9954 case CARDSTATE_PRESENT:
9955 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9956 break;
9957 case CARDSTATE_ERROR:
9958 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9959 break;
9960 case CARDSTATE_RESTRICTED:
9961 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9962 break;
9963 default:
9964 break;
9965
9966 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009967 List<UiccPortInfo> portInfos = new ArrayList<>();
9968 int[] portIndexes = slot.getPortList();
9969 for (int portIdx : portIndexes) {
9970 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009971 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009972 portInfos.add(new UiccPortInfo(iccId, portIdx,
9973 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009974 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009975 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009976 slot.isEuicc(),
9977 cardId,
9978 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009979 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009980 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009981 //setting the value after compatibility check
9982 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009983 }
9984 return infos;
9985 } finally {
9986 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009987 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009988 }
9989
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009990 /* Returns null if doesn't have read permission or carrier privilege access. */
9991 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9992 boolean hasReadPermission) {
9993 String iccId = slot.getIccId(portIndex);
9994 if (hasReadPermission) { // if has read permission
9995 return iccId;
9996 } else {
9997 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9998 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9999 // if no read permission, checking carrier privilege access
10000 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10001 return iccId;
10002 }
10003 }
10004 }
10005 // No read permission or carrier privilege access.
10006 return UiccPortInfo.ICCID_REDACTED;
10007 }
10008
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010009 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010010 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010011 public boolean switchSlots(int[] physicalSlots) {
10012 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010013
10014 final long identity = Binder.clearCallingIdentity();
10015 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010016 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10017 for (int i = 0; i < physicalSlots.length; i++) {
10018 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10019 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10020 physicalSlots[i], i));
10021 }
10022 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010023 } finally {
10024 Binder.restoreCallingIdentity(identity);
10025 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010026 }
Jack Yu4c988042018-02-27 15:30:01 -080010027
10028 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010029 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10030 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10031 enforceModifyPermission();
10032
10033 final long identity = Binder.clearCallingIdentity();
10034 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010035 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010036 } finally {
10037 Binder.restoreCallingIdentity(identity);
10038 }
10039 }
10040
10041 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010042 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -080010043 final long identity = Binder.clearCallingIdentity();
10044 try {
10045 return UiccController.getInstance().getCardIdForDefaultEuicc();
10046 } finally {
10047 Binder.restoreCallingIdentity(identity);
10048 }
10049 }
10050
Pengquan Meng85728fb2018-03-12 16:31:21 -070010051 /**
goneil47ffb6e2018-04-06 15:40:58 -070010052 * A test API to reload the UICC profile.
10053 *
10054 * <p>Requires that the calling app has permission
10055 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10056 * @hide
10057 */
10058 @Override
10059 public void refreshUiccProfile(int subId) {
10060 enforceModifyPermission();
10061
10062 final long identity = Binder.clearCallingIdentity();
10063 try {
10064 Phone phone = getPhone(subId);
10065 if (phone == null) {
10066 return;
10067 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010068 UiccPort uiccPort = phone.getUiccPort();
10069 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010070 return;
10071 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010072 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010073 if (uiccProfile == null) {
10074 return;
10075 }
10076 uiccProfile.refresh();
10077 } finally {
10078 Binder.restoreCallingIdentity(identity);
10079 }
10080 }
10081
10082 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010083 * Returns false if the mobile data is disabled by default, otherwise return true.
10084 */
10085 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010086 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010087 }
10088
10089 /**
10090 * Returns true if the data roaming is enabled by default, i.e the system property
10091 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
10092 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
10093 */
10094 private boolean getDefaultDataRoamingEnabled(int subId) {
10095 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010096 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -070010097 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010098 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
10099 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
10100 return isDataRoamingEnabled;
10101 }
10102
10103 /**
10104 * Returns the default network type for the given {@code subId}, if the default network type is
10105 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10106 */
10107 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010108 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010109 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010110 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10111 return list.get(phoneId);
10112 }
10113 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010114 }
fionaxua13278b2018-03-21 00:08:13 -070010115
10116 @Override
10117 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010118 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010119 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010120
10121 final long identity = Binder.clearCallingIdentity();
10122 try {
10123 final Phone phone = getPhone(subId);
10124 if (phone == null) {
10125 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10126 return;
10127 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010128 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10129 if (cpt != null) {
10130 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10131 }
10132 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010133 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10134 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010135 if (carrierPrivilegeRules == null) {
10136 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10137 } else {
10138 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10139 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010140 } finally {
10141 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010142 }
fionaxua13278b2018-03-21 00:08:13 -070010143 }
10144
10145 @Override
10146 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010147 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010148
10149 final long identity = Binder.clearCallingIdentity();
10150 try {
10151 final Phone phone = getPhone(subId);
10152 if (phone == null) {
10153 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10154 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10155 }
10156 return phone.getCarrierIdListVersion();
10157 } finally {
10158 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010159 }
fionaxua13278b2018-03-21 00:08:13 -070010160 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010161
10162 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010163 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10164 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010165 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010166 mApp, subId, callingPackage, callingFeatureId,
10167 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010168 return -1;
10169 }
10170
10171 final long identity = Binder.clearCallingIdentity();
10172 try {
10173 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10174 } finally {
10175 Binder.restoreCallingIdentity(identity);
10176 }
10177 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010178
10179 @Override
10180 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010181 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010182 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010183 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010184
10185 final long identity = Binder.clearCallingIdentity();
10186 try {
10187 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10188 } finally {
10189 Binder.restoreCallingIdentity(identity);
10190 }
10191 }
10192
10193 @Override
10194 public boolean setCdmaRoamingMode(int subId, int mode) {
10195 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10196 mApp, subId, "setCdmaRoamingMode");
10197
10198 final long identity = Binder.clearCallingIdentity();
10199 try {
10200 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10201 } finally {
10202 Binder.restoreCallingIdentity(identity);
10203 }
10204 }
10205
10206 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010207 public int getCdmaSubscriptionMode(int subId) {
10208 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010209 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010210 mApp, subId, "getCdmaSubscriptionMode");
10211
10212 final long identity = Binder.clearCallingIdentity();
10213 try {
10214 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10215 } finally {
10216 Binder.restoreCallingIdentity(identity);
10217 }
10218 }
10219
10220 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010221 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10222 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10223 mApp, subId, "setCdmaSubscriptionMode");
10224
10225 final long identity = Binder.clearCallingIdentity();
10226 try {
10227 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10228 } finally {
10229 Binder.restoreCallingIdentity(identity);
10230 }
10231 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010232
sqianc5eccab2018-10-19 18:46:41 -070010233 @Override
sqian8c685422019-02-22 15:55:18 -080010234 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010235 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010236 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010237 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10238 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010239 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10240 }
10241 final long identity = Binder.clearCallingIdentity();
10242 try {
sqian854d44b2018-12-12 16:48:18 -080010243 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10244 for (Phone phone: PhoneFactory.getPhones()) {
10245 if (phone.getEmergencyNumberTracker() != null
10246 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10247 emergencyNumberListInternal.put(
10248 phone.getSubId(),
10249 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10250 }
sqian11b7a0e2018-12-05 18:48:28 -080010251 }
sqian854d44b2018-12-12 16:48:18 -080010252 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010253 } finally {
10254 Binder.restoreCallingIdentity(identity);
10255 }
sqianc5eccab2018-10-19 18:46:41 -070010256 }
10257
10258 @Override
sqian8c685422019-02-22 15:55:18 -080010259 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010260 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010261 if (!exactMatch) {
10262 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010263 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010264 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010265 }
10266 final long identity = Binder.clearCallingIdentity();
10267 try {
sqian854d44b2018-12-12 16:48:18 -080010268 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010269 //Note: we ignore passed in param exactMatch. We can remove it once
10270 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010271 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010272 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010273 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010274 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010275 }
sqian11b7a0e2018-12-05 18:48:28 -080010276 }
10277 return false;
10278 } finally {
10279 Binder.restoreCallingIdentity(identity);
10280 }
10281 }
10282
sqianf4ca7ed2019-01-15 18:32:07 -080010283 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010284 * Start emergency callback mode for GsmCdmaPhone for testing.
10285 */
10286 @Override
10287 public void startEmergencyCallbackMode() {
10288 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10289 "startEmergencyCallbackMode");
10290 enforceModifyPermission();
10291 final long identity = Binder.clearCallingIdentity();
10292 try {
10293 for (Phone phone : PhoneFactory.getPhones()) {
10294 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10295 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10296 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10297 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10298 gsmCdmaPhone.obtainMessage(
10299 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10300 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10301 }
10302 }
10303 } finally {
10304 Binder.restoreCallingIdentity(identity);
10305 }
10306 }
10307
10308 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010309 * Update emergency number list for test mode.
10310 */
10311 @Override
10312 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10313 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10314 "updateEmergencyNumberListTestMode");
10315
10316 final long identity = Binder.clearCallingIdentity();
10317 try {
10318 for (Phone phone: PhoneFactory.getPhones()) {
10319 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10320 if (tracker != null) {
10321 tracker.executeEmergencyNumberTestModeCommand(action, num);
10322 }
10323 }
10324 } finally {
10325 Binder.restoreCallingIdentity(identity);
10326 }
10327 }
10328
10329 /**
10330 * Get the full emergency number list for test mode.
10331 */
10332 @Override
10333 public List<String> getEmergencyNumberListTestMode() {
10334 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10335 "getEmergencyNumberListTestMode");
10336
10337 final long identity = Binder.clearCallingIdentity();
10338 try {
10339 Set<String> emergencyNumbers = new HashSet<>();
10340 for (Phone phone: PhoneFactory.getPhones()) {
10341 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10342 if (tracker != null) {
10343 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10344 emergencyNumbers.add(num.getNumber());
10345 }
10346 }
10347 }
10348 return new ArrayList<>(emergencyNumbers);
10349 } finally {
10350 Binder.restoreCallingIdentity(identity);
10351 }
10352 }
10353
chen xud6b45bd2018-10-30 22:27:10 -070010354 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010355 public int getEmergencyNumberDbVersion(int subId) {
10356 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10357
10358 final long identity = Binder.clearCallingIdentity();
10359 try {
10360 final Phone phone = getPhone(subId);
10361 if (phone == null) {
10362 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10363 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10364 }
10365 return phone.getEmergencyNumberDbVersion();
10366 } finally {
10367 Binder.restoreCallingIdentity(identity);
10368 }
10369 }
10370
10371 @Override
10372 public void notifyOtaEmergencyNumberDbInstalled() {
10373 enforceModifyPermission();
10374
10375 final long identity = Binder.clearCallingIdentity();
10376 try {
10377 for (Phone phone: PhoneFactory.getPhones()) {
10378 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10379 if (tracker != null) {
10380 tracker.updateOtaEmergencyNumberDatabase();
10381 }
10382 }
10383 } finally {
10384 Binder.restoreCallingIdentity(identity);
10385 }
10386 }
10387
10388 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010389 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010390 enforceActiveEmergencySessionPermission();
10391
10392 final long identity = Binder.clearCallingIdentity();
10393 try {
10394 for (Phone phone: PhoneFactory.getPhones()) {
10395 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10396 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010397 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10398 }
10399 }
10400 } finally {
10401 Binder.restoreCallingIdentity(identity);
10402 }
10403 }
10404
10405 @Override
10406 public void resetOtaEmergencyNumberDbFilePath() {
10407 enforceActiveEmergencySessionPermission();
10408
10409 final long identity = Binder.clearCallingIdentity();
10410 try {
10411 for (Phone phone: PhoneFactory.getPhones()) {
10412 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10413 if (tracker != null) {
10414 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010415 }
10416 }
10417 } finally {
10418 Binder.restoreCallingIdentity(identity);
10419 }
10420 }
10421
10422 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010423 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10424 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10425 Phone phone = getPhone(subId);
10426 if (phone == null) {
10427 return null;
10428 }
10429 final long identity = Binder.clearCallingIdentity();
10430 try {
10431 UiccProfile profile = UiccController.getInstance()
10432 .getUiccProfileForPhone(phone.getPhoneId());
10433 if (profile != null) {
10434 return profile.getCertsFromCarrierPrivilegeAccessRules();
10435 }
10436 } finally {
10437 Binder.restoreCallingIdentity(identity);
10438 }
10439 return null;
10440 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010441
10442 /**
10443 * Enable or disable a modem stack.
10444 */
10445 @Override
10446 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10447 enforceModifyPermission();
10448
10449 final long identity = Binder.clearCallingIdentity();
10450 try {
10451 Phone phone = PhoneFactory.getPhone(slotIndex);
10452 if (phone == null) {
10453 return false;
10454 } else {
10455 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10456 }
10457 } finally {
10458 Binder.restoreCallingIdentity(identity);
10459 }
10460 }
Michelecea4cf22018-12-21 15:00:11 -080010461
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010462 /**
10463 * Whether a modem stack is enabled or not.
10464 */
10465 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010466 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10467 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010468 Phone phone = PhoneFactory.getPhone(slotIndex);
10469 if (phone == null) return false;
10470
10471 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010472 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10473 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010474 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10475 }
10476
10477 final long identity = Binder.clearCallingIdentity();
10478 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010479 try {
10480 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10481 } catch (NoSuchElementException ex) {
10482 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10483 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010484 } finally {
10485 Binder.restoreCallingIdentity(identity);
10486 }
10487 }
10488
Michelecea4cf22018-12-21 15:00:11 -080010489 @Override
Michele0ea7d782019-03-19 14:58:42 -070010490 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010491 enforceModifyPermission();
10492
10493 final long identity = Binder.clearCallingIdentity();
10494 try {
10495 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010496 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010497 .commit();
10498 } finally {
10499 Binder.restoreCallingIdentity(identity);
10500 }
10501 }
10502
10503 @Override
Michele0ea7d782019-03-19 14:58:42 -070010504 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010505 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010506 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010507 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10508 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010509 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010510 }
Michelecea4cf22018-12-21 15:00:11 -080010511
10512 final long identity = Binder.clearCallingIdentity();
10513 try {
Michele0ea7d782019-03-19 14:58:42 -070010514 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010515 } finally {
10516 Binder.restoreCallingIdentity(identity);
10517 }
10518 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010519
Michele0ea7d782019-03-19 14:58:42 -070010520 @TelephonyManager.IsMultiSimSupportedResult
10521 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010522 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10523 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10524 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010525 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10526 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010527 }
10528 // Check if the hardware supports multisim functionality. If usage of multisim is not
10529 // supported by the modem, indicate that it is restricted.
10530 PhoneCapability staticCapability =
10531 mPhoneConfigurationManager.getStaticPhoneCapability();
10532 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010533 loge("isMultiSimSupportedInternal: no static configuration available");
10534 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010535 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010536 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010537 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10538 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010539 }
10540 // Check if support of multiple SIMs is restricted by carrier
10541 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010542 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010543 }
10544
Michele0ea7d782019-03-19 14:58:42 -070010545 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010546 }
10547
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010548 /**
10549 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010550 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10551 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10552 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010553 * @param numOfSims number of active sims we want to switch to
10554 */
10555 @Override
10556 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010557 if (numOfSims == 1) {
10558 enforceModifyPermission();
10559 } else {
10560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10561 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10562 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010563 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010564
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010565 try {
Michele30b57b22019-03-01 12:01:14 -080010566 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010567 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010568 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10569 return;
10570 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010571 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10572 } finally {
10573 Binder.restoreCallingIdentity(identity);
10574 }
10575 }
10576
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010577 @Override
10578 public boolean isApplicationOnUicc(int subId, int appType) {
10579 enforceReadPrivilegedPermission("isApplicationOnUicc");
10580 Phone phone = getPhone(subId);
10581 if (phone == null) {
10582 return false;
10583 }
10584 final long identity = Binder.clearCallingIdentity();
10585 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010586 UiccPort uiccPort = phone.getUiccPort();
10587 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010588 return false;
10589 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010590 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010591 if (uiccProfile == null) {
10592 return false;
10593 }
10594 if (TelephonyManager.APPTYPE_SIM <= appType
10595 && appType <= TelephonyManager.APPTYPE_ISIM) {
10596 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10597 }
10598 return false;
10599 } finally {
10600 Binder.restoreCallingIdentity(identity);
10601 }
10602 }
10603
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010604 /**
chen xub4baa772019-04-03 10:23:41 -070010605 * Get whether making changes to modem configurations will trigger reboot.
10606 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010607 */
10608 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010609 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10610 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010611 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010612 mApp, subId, callingPackage, callingFeatureId,
10613 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010614 return false;
10615 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010616 final long identity = Binder.clearCallingIdentity();
10617 try {
10618 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10619 } finally {
10620 Binder.restoreCallingIdentity(identity);
10621 }
10622 }
10623
Nathan Harold29f5f052019-02-15 13:41:57 -080010624 private void updateModemStateMetrics() {
10625 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10626 // TODO: check the state for each modem if the api is ready.
10627 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10628 }
10629
Pengquan Meng3889a572019-01-23 11:16:29 -080010630 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010631 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010632 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010633 // Verify that the callingPackage belongs to the calling UID
10634 mApp.getSystemService(AppOpsManager.class)
10635 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010636 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010637 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010638 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010639 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10640 if (slotInfos != null) {
10641 for (int i = 0; i < slotInfos.length; i++) {
10642 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10643 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10644 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10645 portInfo.getLogicalSlotIndex()));
10646 }
10647 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010648 }
10649 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010650 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010651 } finally {
10652 Binder.restoreCallingIdentity(identity);
10653 }
10654 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010655
10656 /**
10657 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010658 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010659 */
jimsunf9ec1622022-09-13 21:18:43 +080010660 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010661 @Override
10662 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010663 return getHalVersion(HAL_SERVICE_RADIO);
10664 }
10665
10666 /**
10667 * Get the HAL Version of a specific service
10668 */
10669 @Override
10670 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010671 Phone phone = getDefaultPhone();
10672 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010673 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010674 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10675 return hv.major * 100 + hv.minor;
10676 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010677
10678 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010679 * Get the current calling package name.
10680 * @return the current calling package name
10681 */
10682 @Override
10683 public String getCurrentPackageName() {
10684 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10685 }
10686
10687 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010688 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10689 * corresponding network requests on a subId.
10690 *
10691 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010692 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010693 * 2) APN is un-metered for this subscription, or
10694 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010695 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010696 *
10697 * @return whether data is allowed for a apn type.
10698 *
10699 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010700 */
10701 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010702 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010703 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10704 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010705
10706 // Now that all security checks passes, perform the operation as ourselves.
10707 final long identity = Binder.clearCallingIdentity();
10708 try {
10709 Phone phone = getPhone(subId);
10710 if (phone == null) return false;
10711
Jack Yu27422a52022-03-21 10:38:05 -070010712 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010713 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010714 isMetered = phone.getDataNetworkController().getDataConfigManager()
10715 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10716 phone.getServiceState().getDataRoaming());
10717 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010718 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010719 } finally {
10720 Binder.restoreCallingIdentity(identity);
10721 }
10722 }
10723
10724 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010725 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010726 enforceReadPrivilegedPermission("isApnMetered");
10727
10728 // Now that all security checks passes, perform the operation as ourselves.
10729 final long identity = Binder.clearCallingIdentity();
10730 try {
10731 Phone phone = getPhone(subId);
10732 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010733 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10734 DataUtils.apnTypeToNetworkCapability(apnType),
10735 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010736 } finally {
10737 Binder.restoreCallingIdentity(identity);
10738 }
10739 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010740
10741 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010742 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10743 int subscriptionId, IBooleanConsumer resultCallback) {
10744 enforceModifyPermission();
10745 long token = Binder.clearCallingIdentity();
10746 try {
10747 Phone phone = getPhone(subscriptionId);
10748 if (phone == null) {
10749 try {
10750 if (resultCallback != null) {
10751 resultCallback.accept(false);
10752 }
10753 } catch (RemoteException e) {
10754 // ignore
10755 }
10756 return;
10757 }
10758 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10759 Pair.create(specifiers, (x) -> {
10760 try {
10761 if (resultCallback != null) {
10762 resultCallback.accept(x);
10763 }
10764 } catch (RemoteException e) {
10765 // ignore
10766 }
10767 });
10768 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10769 } finally {
10770 Binder.restoreCallingIdentity(token);
10771 }
10772 }
10773
10774 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010775 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10776 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010777 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010778 mApp, subId, "getSystemSelectionChannels");
10779 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10780 final long identity = Binder.clearCallingIdentity();
10781 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010782 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10783 if (result instanceof IllegalStateException) {
10784 throw (IllegalStateException) result;
10785 }
10786 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010787 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10788 return specifiers;
10789 } finally {
10790 Binder.restoreCallingIdentity(identity);
10791 }
10792 }
10793
10794 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010795 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010796 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010797 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010798 }
10799
10800 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010801 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10802 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010803 if (callingPackage == null) {
10804 callingPackage = getCurrentPackageName();
10805 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010806 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10807 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010808 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10809 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010810 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10811 }
10812 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10813 Intent intent = new Intent();
10814 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10815 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10816 // Bring up choose default SMS subscription dialog right now
10817 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10818 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10819 mApp.startActivity(intent);
10820 }
chen xud5ca2d52019-05-28 15:20:57 -070010821
10822 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010823 public void showSwitchToManagedProfileDialog() {
10824 enforceModifyPermission();
10825
10826 Intent intent = new Intent();
10827 intent.setClass(mApp, ErrorDialogActivity.class);
10828 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10829 mApp.startActivity(intent);
10830 }
10831
10832 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010833 public String getMmsUAProfUrl(int subId) {
10834 //TODO investigate if this API should require proper permission check in R b/133791609
10835 final long identity = Binder.clearCallingIdentity();
10836 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010837 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10838 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10839 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10840 return carrierUAProfUrl;
10841 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010842 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10843 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010844 } finally {
10845 Binder.restoreCallingIdentity(identity);
10846 }
10847 }
10848
10849 @Override
10850 public String getMmsUserAgent(int subId) {
10851 //TODO investigate if this API should require proper permission check in R b/133791609
10852 final long identity = Binder.clearCallingIdentity();
10853 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010854 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10855 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10856 if (!TextUtils.isEmpty(carrierUserAgent)) {
10857 return carrierUserAgent;
10858 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010859 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10860 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010861 } finally {
10862 Binder.restoreCallingIdentity(identity);
10863 }
10864 }
Jack Yub07d4972019-05-28 16:12:25 -070010865
10866 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010867 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10868 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010869
Jack Yub07d4972019-05-28 16:12:25 -070010870 final long identity = Binder.clearCallingIdentity();
10871 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010872 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010873 if (phone == null) return false;
10874
Ling Maf188d502022-09-16 15:22:36 -070010875 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010876 } finally {
10877 Binder.restoreCallingIdentity(identity);
10878 }
10879 }
10880
10881 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010882 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010883 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010884 enforceModifyPermission();
10885
changbettyd5c246e2019-12-24 15:40:37 +080010886 final long identity = Binder.clearCallingIdentity();
10887 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010888 Phone phone = getPhone(subscriptionId);
10889 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010890
Ling Maf188d502022-09-16 15:22:36 -070010891 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010892 } finally {
10893 Binder.restoreCallingIdentity(identity);
10894 }
10895 }
10896
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010897 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010898 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010899 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10900 * otherwise.
10901 */
10902 @Override
10903 public void setCepEnabled(boolean isCepEnabled) {
10904 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10905
10906 final long identity = Binder.clearCallingIdentity();
10907 try {
10908 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10909 for (Phone phone : PhoneFactory.getPhones()) {
10910 Phone defaultPhone = phone.getImsPhone();
10911 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10912 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10913 ImsPhoneCallTracker imsPhoneCallTracker =
10914 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10915 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10916 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10917 + imsPhone.getMsisdn());
10918 }
10919 }
10920 } finally {
10921 Binder.restoreCallingIdentity(identity);
10922 }
10923 }
allenwtsu46dcc572020-01-08 18:24:03 +080010924
10925 /**
10926 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10927 *
10928 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10929 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10930 * before being read.
10931 */
10932 @Override
10933 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10934 isCompressed) {
10935 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10936 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010937 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10938 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10939 }
10940 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010941 // ProvisioningManager can not handle ServiceSpecificException.
10942 // Throw the IllegalStateException and annotate ProvisioningManager.
10943 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010944 }
10945
10946 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010947 try {
Hui Wang761a6682020-10-31 05:12:53 +000010948 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10949 } finally {
10950 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010951 }
10952 }
zoey chene02881a2019-12-30 16:11:23 +080010953
10954 @Override
10955 public boolean isIccLockEnabled(int subId) {
10956 enforceReadPrivilegedPermission("isIccLockEnabled");
10957
10958 // Now that all security checks passes, perform the operation as ourselves.
10959 final long identity = Binder.clearCallingIdentity();
10960 try {
10961 Phone phone = getPhone(subId);
10962 if (phone != null && phone.getIccCard() != null) {
10963 return phone.getIccCard().getIccLockEnabled();
10964 } else {
10965 return false;
10966 }
10967 } finally {
10968 Binder.restoreCallingIdentity(identity);
10969 }
10970 }
10971
10972 /**
10973 * Set the ICC pin lock enabled or disabled.
10974 *
10975 * @return an integer representing the status of IccLock enabled or disabled in the following
10976 * three cases:
10977 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10978 * successfully.
10979 * - Positive number and zero for remaining password attempts.
10980 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10981 *
10982 */
10983 @Override
10984 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10985 enforceModifyPermission();
10986
10987 Phone phone = getPhone(subId);
10988 if (phone == null) {
10989 return 0;
10990 }
10991 // Now that all security checks passes, perform the operation as ourselves.
10992 final long identity = Binder.clearCallingIdentity();
10993 try {
10994 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10995 new Pair<Boolean, String>(enabled, password), phone, null);
10996 return attemptsRemaining;
10997
10998 } catch (Exception e) {
10999 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11000 } finally {
11001 Binder.restoreCallingIdentity(identity);
11002 }
11003 return 0;
11004 }
11005
11006 /**
11007 * Change the ICC password used in ICC pin lock.
11008 *
11009 * @return an integer representing the status of IccLock changed in the following three cases:
11010 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11011 * - Positive number and zero for remaining password attempts.
11012 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11013 *
11014 */
11015 @Override
11016 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11017 enforceModifyPermission();
11018
11019 Phone phone = getPhone(subId);
11020 if (phone == null) {
11021 return 0;
11022 }
11023 // Now that all security checks passes, perform the operation as ourselves.
11024 final long identity = Binder.clearCallingIdentity();
11025 try {
11026 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11027 new Pair<String, String>(oldPassword, newPassword), phone, null);
11028 return attemptsRemaining;
11029
11030 } catch (Exception e) {
11031 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11032 } finally {
11033 Binder.restoreCallingIdentity(identity);
11034 }
11035 return 0;
11036 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011037
11038 /**
11039 * Request for receiving user activity notification
11040 */
11041 @Override
11042 public void requestUserActivityNotification() {
11043 if (!mNotifyUserActivity.get()
11044 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11045 mNotifyUserActivity.set(true);
11046 }
11047 }
11048
11049 /**
11050 * Called when userActivity is signalled in the power manager.
11051 * This is safe to call from any thread, with any window manager locks held or not.
11052 */
11053 @Override
11054 public void userActivity() {
11055 // ***************************************
11056 // * Inherited from PhoneWindowManager *
11057 // ***************************************
11058 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11059 // WITH ITS LOCKS HELD.
11060 //
11061 // This code must be VERY careful about the locks
11062 // it acquires.
11063 // In fact, the current code acquires way too many,
11064 // and probably has lurking deadlocks.
11065
11066 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11067 throw new SecurityException("Only the OS may call notifyUserActivity()");
11068 }
11069
11070 if (mNotifyUserActivity.getAndSet(false)) {
11071 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11072 USER_ACTIVITY_NOTIFICATION_DELAY);
11073 }
11074 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011075
11076 @Override
11077 public boolean canConnectTo5GInDsdsMode() {
11078 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11079 }
Jack Yud10cdd42020-09-28 20:28:01 -070011080
11081 @Override
11082 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11083 String callingFeatureId) {
11084 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11085 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11086 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11087 }
11088
11089 Phone phone = getPhone(subId);
11090 if (phone == null) {
11091 throw new RuntimeException("phone is not available");
11092 }
11093 // Now that all security checks passes, perform the operation as ourselves.
11094 final long identity = Binder.clearCallingIdentity();
11095 try {
11096 return phone.getEquivalentHomePlmns();
11097 } finally {
11098 Binder.restoreCallingIdentity(identity);
11099 }
11100 }
Daniel Bright59e67312020-11-13 11:49:37 -080011101
11102 @Override
11103 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011104 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
11105 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011106 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011107 if (radioInterfaceCapabilities == null) {
11108 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011109 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011110 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011111 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011112
Hui Wang641e81c2020-10-12 12:14:23 -070011113 @Override
11114 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11115 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011116 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11117 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11118 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11119 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11120 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070011121 if (DBG) {
11122 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11123 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11124 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11125 }
11126
11127 if (!SubscriptionManager.isValidSubscriptionId(subId)
11128 || appType < TelephonyManager.APPTYPE_UNKNOWN
11129 || appType > TelephonyManager.APPTYPE_ISIM
11130 || nafUrl == null || securityProtocol == null || callback == null) {
11131 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11132 if (callback != null) {
11133 try {
11134 callback.onAuthenticationFailure(
11135 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11136 } catch (RemoteException exception) {
11137 log("Fail to notify onAuthenticationFailure due to " + exception);
11138 }
11139 return;
11140 }
11141 }
11142
11143 final long token = Binder.clearCallingIdentity();
11144 try {
11145 getGbaManager(subId).bootstrapAuthenticationRequest(
11146 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011147 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011148 } finally {
11149 Binder.restoreCallingIdentity(token);
11150 }
11151 }
11152
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011153 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011154 * Attempts to set the radio power state for all phones for thermal reason.
11155 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011156 * requested radio power state will actually be set. See {@link
11157 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11158 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011159 * @param enable {@code true} if trying to turn radio on.
11160 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11161 * false}.
11162 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011163 private boolean setRadioPowerForThermal(boolean enable) {
11164 boolean isPhoneAvailable = false;
11165 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11166 Phone phone = PhoneFactory.getPhone(i);
11167 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011168 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011169 isPhoneAvailable = true;
11170 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011171 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011172
11173 // return true if successfully informed the phone object about the thermal radio power
11174 // request.
11175 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011176 }
11177
11178 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011179 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011180 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11181 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11182 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11183 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11184 throw new IllegalArgumentException("modem does not support data throttling");
11185 }
11186
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011187 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11188 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011189 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011190 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11191 }
11192
Sarah Chinecc78c42022-03-31 21:16:48 -070011193 setDataEnabledForReason(
11194 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011195
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011196 if (isDataThrottlingSupported) {
11197 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011198 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011199 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11200 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11201 } else if (thermalMitigationResult
11202 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011203 log("Modem likely does not support data throttling on secondary carrier. Data " +
11204 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11205 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011206 }
11207 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011208 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011209
11210 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011211 }
11212
Jack Nudelman644b91a2021-03-12 14:09:48 -080011213 private static List<String> getThermalMitigationAllowlist(Context context) {
11214 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11215 for (String pckg : context.getResources()
11216 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11217 sThermalMitigationAllowlistedPackages.add(pckg);
11218 }
11219 }
11220
11221 return sThermalMitigationAllowlistedPackages;
11222 }
11223
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011224 private boolean isAnyPhoneInEmergencyState() {
11225 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11226 if (tm.isInEmergencyCall()) {
11227 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11228 return true;
11229 }
11230 for (Phone phone : PhoneFactory.getPhones()) {
11231 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11232 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011233 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11234 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011235 return true;
11236 }
11237 }
11238
11239 return false;
11240 }
11241
Jack Nudelman644b91a2021-03-12 14:09:48 -080011242 /**
11243 * Used by shell commands to add an authorized package name for thermal mitigation.
11244 * @param packageName name of package to be allowlisted
11245 * @param context
11246 */
11247 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11248 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11249 sThermalMitigationAllowlistedPackages.add(packageName);
11250 }
11251
11252 /**
11253 * Used by shell commands to remove an authorized package name for thermal mitigation.
11254 * @param packageName name of package to remove from allowlist
11255 * @param context
11256 */
11257 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11258 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11259 sThermalMitigationAllowlistedPackages.remove(packageName);
11260 }
11261
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011262 /**
11263 * Thermal mitigation request to control functionalities at modem.
11264 *
11265 * @param subId the id of the subscription.
11266 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011267 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011268 *
11269 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11270 */
11271 @Override
11272 @ThermalMitigationResult
11273 public int sendThermalMitigationRequest(
11274 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011275 ThermalMitigationRequest thermalMitigationRequest,
11276 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011277 enforceModifyPermission();
11278
Jack Nudelman644b91a2021-03-12 14:09:48 -080011279 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11280 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11281 .contains(callingPackage)) {
11282 throw new SecurityException("Calling package must be configured in the device config. "
11283 + "calling package: " + callingPackage);
11284 }
11285
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011286 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11287 final long identity = Binder.clearCallingIdentity();
11288
11289 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11290 try {
11291 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11292 switch (thermalMitigationAction) {
11293 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11294 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011295 handleDataThrottlingRequest(subId,
11296 thermalMitigationRequest.getDataThrottlingRequest(),
11297 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011298 break;
11299 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11300 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11301 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11302 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11303 }
11304
11305 // Ensure that radio is on. If not able to power on due to phone being
11306 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011307 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011308 thermalMitigationResult =
11309 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11310 break;
11311 }
11312
11313 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011314 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011315 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11316 break;
11317 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11318 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11319 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11320 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11321 }
11322
11323 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11324 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011325 Phone phone = getPhone(subId);
11326 if (phone == null) {
11327 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011328 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011329 break;
11330 }
11331
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011332 TelephonyConnectionService service =
11333 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011334 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011335 Log.e(LOG_TAG, "An emergency call is pending");
11336 thermalMitigationResult =
11337 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11338 break;
11339 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011340 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011341 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011342 break;
11343 }
11344 } else {
11345 thermalMitigationResult =
11346 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11347 break;
11348 }
11349
11350 // Turn radio off. If not able to power off due to phone being unavailable,
11351 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011352 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011353 thermalMitigationResult =
11354 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11355 break;
11356 }
11357 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011358 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011359 break;
11360 default:
11361 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11362 + "not exist. Requested action: " + thermalMitigationAction);
11363 }
11364 } catch (IllegalArgumentException e) {
11365 throw e;
11366 } catch (Exception e) {
11367 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11368 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11369 } finally {
11370 Binder.restoreCallingIdentity(identity);
11371 }
11372
11373 if (DBG) {
11374 log("thermalMitigationRequest returning with thermalMitigationResult: "
11375 + thermalMitigationResult);
11376 }
11377
11378 return thermalMitigationResult;
11379 }
Hui Wang641e81c2020-10-12 12:14:23 -070011380
11381 /**
11382 * Set the GbaService Package Name that Telephony will bind to.
11383 *
11384 * @param subId The sim that the GbaService is associated with.
11385 * @param packageName The name of the package to be replaced with.
11386 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11387 */
11388 @Override
11389 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11390 enforceModifyPermission();
11391
11392 final long identity = Binder.clearCallingIdentity();
11393 try {
11394 return getGbaManager(subId).overrideServicePackage(packageName);
11395 } finally {
11396 Binder.restoreCallingIdentity(identity);
11397 }
11398 }
11399
11400 /**
11401 * Return the package name of the currently bound GbaService.
11402 *
11403 * @param subId The sim that the GbaService is associated with.
11404 * @return the package name of the GbaService configuration, null if GBA is not supported.
11405 */
11406 @Override
11407 public String getBoundGbaService(int subId) {
11408 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11409
11410 final long identity = Binder.clearCallingIdentity();
11411 try {
11412 return getGbaManager(subId).getServicePackage();
11413 } finally {
11414 Binder.restoreCallingIdentity(identity);
11415 }
11416 }
11417
11418 /**
11419 * Set the release time for telephony to unbind GbaService.
11420 *
11421 * @param subId The sim that the GbaService is associated with.
11422 * @param interval The release time to unbind GbaService by millisecond.
11423 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11424 */
11425 @Override
11426 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11427 enforceModifyPermission();
11428
11429 final long identity = Binder.clearCallingIdentity();
11430 try {
11431 return getGbaManager(subId).overrideReleaseTime(interval);
11432 } finally {
11433 Binder.restoreCallingIdentity(identity);
11434 }
11435 }
11436
11437 /**
11438 * Return the release time for telephony to unbind GbaService.
11439 *
11440 * @param subId The sim that the GbaService is associated with.
11441 * @return The release time to unbind GbaService by millisecond.
11442 */
11443 @Override
11444 public int getGbaReleaseTime(int subId) {
11445 enforceReadPrivilegedPermission("getGbaReleaseTime");
11446
11447 final long identity = Binder.clearCallingIdentity();
11448 try {
11449 return getGbaManager(subId).getReleaseTime();
11450 } finally {
11451 Binder.restoreCallingIdentity(identity);
11452 }
11453 }
11454
11455 private GbaManager getGbaManager(int subId) {
11456 GbaManager instance = GbaManager.getInstance(subId);
11457 if (instance == null) {
11458 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11459 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11460 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11461 }
11462 return instance;
11463 }
Hui Wang761a6682020-10-31 05:12:53 +000011464
11465 /**
11466 * indicate whether the device and the carrier can support
11467 * RCS VoLTE single registration.
11468 */
11469 @Override
11470 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011471 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11472 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11473 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11474 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011475
11476 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11477 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11478 }
11479
11480 final long identity = Binder.clearCallingIdentity();
11481 try {
11482 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11483 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011484 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11485 if (isCapable != null) {
11486 return isCapable;
11487 }
Hui Wang761a6682020-10-31 05:12:53 +000011488 }
Hui Wang67af90e2021-06-04 16:57:15 -070011489 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11490 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011491 } finally {
11492 Binder.restoreCallingIdentity(identity);
11493 }
11494 }
11495
11496 /**
11497 * Register RCS provisioning callback.
11498 */
11499 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011500 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011501 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011502 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011503 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011504 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11505 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011506
11507 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11508 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11509 }
11510 if (!isImsAvailableOnDevice()) {
11511 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11512 "IMS not available on device.");
11513 }
11514
11515 final long identity = Binder.clearCallingIdentity();
11516 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011517 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011518 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011519 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11520 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011521 }
Hui Wang761a6682020-10-31 05:12:53 +000011522 } finally {
11523 Binder.restoreCallingIdentity(identity);
11524 }
11525 }
11526
11527 /**
11528 * Unregister RCS provisioning callback.
11529 */
11530 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011531 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011532 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011533 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011534 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011535 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11536 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011537
11538 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11539 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11540 }
11541 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011542 // operation failed silently
11543 Rlog.w(LOG_TAG, "IMS not available on device.");
11544 return;
Hui Wang761a6682020-10-31 05:12:53 +000011545 }
11546
11547 final long identity = Binder.clearCallingIdentity();
11548 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011549 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011550 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011551 } finally {
11552 Binder.restoreCallingIdentity(identity);
11553 }
11554 }
11555
11556 /**
11557 * trigger RCS reconfiguration.
11558 */
11559 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011560 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11561 "triggerRcsReconfiguration",
11562 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011563
11564 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11565 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11566 }
11567 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011568 // ProvisioningManager can not handle ServiceSpecificException.
11569 // Throw the IllegalStateException and annotate ProvisioningManager.
11570 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000011571 }
11572
11573 final long identity = Binder.clearCallingIdentity();
11574 try {
11575 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11576 } finally {
11577 Binder.restoreCallingIdentity(identity);
11578 }
11579 }
11580
11581 /**
11582 * Provide the client configuration parameters of the RCS application.
11583 */
11584 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011585 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11586 "setRcsClientConfiguration",
11587 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011588
11589 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11590 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11591 }
11592 if (!isImsAvailableOnDevice()) {
11593 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11594 "IMS not available on device.");
11595 }
11596
11597 final long identity = Binder.clearCallingIdentity();
11598
11599 try {
11600 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11601 if (configBinder == null) {
11602 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011603 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11604 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011605 } else {
11606 configBinder.setRcsClientConfiguration(rcc);
11607 }
joonhunshin3e154242021-09-17 06:33:39 +000011608
11609 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11610 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011611 } catch (RemoteException e) {
11612 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011613 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11614 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011615 } finally {
11616 Binder.restoreCallingIdentity(identity);
11617 }
11618 }
11619
11620 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011621 * Enables or disables the test mode for RCS VoLTE single registration.
11622 */
11623 @Override
11624 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11625 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11626 "setRcsSingleRegistrationTestModeEnabled");
11627
11628 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11629 }
11630
11631 /**
11632 * Gets the test mode for RCS VoLTE single registration.
11633 */
11634 @Override
11635 public boolean getRcsSingleRegistrationTestModeEnabled() {
11636 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11637 "getRcsSingleRegistrationTestModeEnabled");
11638
11639 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11640 }
11641
11642 /**
Hui Wang761a6682020-10-31 05:12:53 +000011643 * Overrides the config of RCS VoLTE single registration enabled for the device.
11644 */
11645 @Override
11646 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11647 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11648 "setDeviceSingleRegistrationEnabledOverride");
11649 enforceModifyPermission();
11650
11651 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11652 : Boolean.parseBoolean(enabledStr);
11653 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011654 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011655 }
11656
11657 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011658 * Sends a device to device communication message. Only usable via shell.
11659 * @param message message to send.
11660 * @param value message value.
11661 */
11662 @Override
11663 public void sendDeviceToDeviceMessage(int message, int value) {
11664 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011665 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011666 enforceModifyPermission();
11667
11668 final long identity = Binder.clearCallingIdentity();
11669 try {
11670 TelephonyConnectionService service =
11671 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11672 if (service == null) {
11673 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11674 return;
11675 }
11676 service.sendTestDeviceToDeviceMessage(message, value);
11677 } finally {
11678 Binder.restoreCallingIdentity(identity);
11679 }
11680 }
11681
Tyler Gunnbabbda02021-02-10 11:05:02 -080011682 /**
11683 * Sets the specified device to device transport active.
11684 * @param transport The transport to set active.
11685 */
11686 @Override
11687 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11688 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11689 "setActiveDeviceToDeviceTransport");
11690 enforceModifyPermission();
11691
11692 final long identity = Binder.clearCallingIdentity();
11693 try {
11694 TelephonyConnectionService service =
11695 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11696 if (service == null) {
11697 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11698 return;
11699 }
11700 service.setActiveDeviceToDeviceTransport(transport);
11701 } finally {
11702 Binder.restoreCallingIdentity(identity);
11703 }
11704 }
Tyler Gunn92479152021-01-20 16:30:10 -080011705
Tyler Gunnd4339262021-05-03 14:46:49 -070011706 @Override
11707 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11708 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11709 "setDeviceToDeviceForceEnabled");
11710
11711 final long identity = Binder.clearCallingIdentity();
11712 try {
11713 Arrays.stream(PhoneFactory.getPhones()).forEach(
11714 p -> {
11715 Phone thePhone = p.getImsPhone();
11716 if (thePhone != null && thePhone instanceof ImsPhone) {
11717 ImsPhone imsPhone = (ImsPhone) thePhone;
11718 CallTracker tracker = imsPhone.getCallTracker();
11719 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11720 ImsPhoneCallTracker imsPhoneCallTracker =
11721 (ImsPhoneCallTracker) tracker;
11722 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11723 }
11724 }
11725 }
11726 );
11727 } finally {
11728 Binder.restoreCallingIdentity(identity);
11729 }
11730 }
11731
Tyler Gunn92479152021-01-20 16:30:10 -080011732 /**
Hui Wang761a6682020-10-31 05:12:53 +000011733 * Gets the config of RCS VoLTE single registration enabled for the device.
11734 */
11735 @Override
11736 public boolean getDeviceSingleRegistrationEnabled() {
11737 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11738 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11739 }
11740
11741 /**
11742 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11743 */
11744 @Override
11745 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11746 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11747 "setCarrierSingleRegistrationEnabledOverride");
11748 enforceModifyPermission();
11749
11750 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11751 : Boolean.parseBoolean(enabledStr);
11752 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11753 subId, enabled);
11754 }
11755
11756 /**
11757 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11758 */
11759 @Override
11760 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11761 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11762 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11763 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011764
11765 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011766 * Overrides the ims feature validation result
11767 */
11768 @Override
11769 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11770 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11771 "setImsFeatureValidationOverride");
11772
11773 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11774 : Boolean.parseBoolean(enabledStr);
11775 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11776 subId, enabled);
11777 }
11778
11779 /**
11780 * Gets the ims feature validation override value
11781 */
11782 @Override
11783 public boolean getImsFeatureValidationOverride(int subId) {
11784 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11785 "getImsFeatureValidationOverride");
11786 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11787 }
11788
11789 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011790 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11791 * their mobile plan.
11792 */
11793 @Override
11794 public String getMobileProvisioningUrl() {
11795 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11796 final long identity = Binder.clearCallingIdentity();
11797 try {
11798 return getDefaultPhone().getMobileProvisioningUrl();
11799 } finally {
11800 Binder.restoreCallingIdentity(identity);
11801 }
11802 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011803
James.cf Linbcdf8b32021-01-14 16:44:13 +080011804 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011805 * Get the EAB contact from the EAB database.
11806 */
11807 @Override
11808 public String getContactFromEab(String contact) {
11809 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11810 enforceModifyPermission();
11811 final long identity = Binder.clearCallingIdentity();
11812 try {
11813 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11814 } finally {
11815 Binder.restoreCallingIdentity(identity);
11816 }
11817 }
11818
11819 /**
Calvin Pana1434322021-07-01 19:27:01 +080011820 * Get the EAB capability from the EAB database.
11821 */
11822 @Override
11823 public String getCapabilityFromEab(String contact) {
11824 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11825 enforceModifyPermission();
11826 final long identity = Binder.clearCallingIdentity();
11827 try {
11828 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11829 } finally {
11830 Binder.restoreCallingIdentity(identity);
11831 }
11832 }
11833
11834 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011835 * Remove the EAB contacts from the EAB database.
11836 */
11837 @Override
11838 public int removeContactFromEab(int subId, String contacts) {
11839 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11840 enforceModifyPermission();
11841 final long identity = Binder.clearCallingIdentity();
11842 try {
11843 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11844 } finally {
11845 Binder.restoreCallingIdentity(identity);
11846 }
11847 }
11848
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011849 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011850 public boolean getDeviceUceEnabled() {
11851 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11852 final long identity = Binder.clearCallingIdentity();
11853 try {
11854 return mApp.getDeviceUceEnabled();
11855 } finally {
11856 Binder.restoreCallingIdentity(identity);
11857 }
11858 }
11859
11860 @Override
11861 public void setDeviceUceEnabled(boolean isEnabled) {
11862 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11863 final long identity = Binder.clearCallingIdentity();
11864 try {
11865 mApp.setDeviceUceEnabled(isEnabled);
11866 } finally {
11867 Binder.restoreCallingIdentity(identity);
11868 }
11869 }
11870
Brad Ebinger14d467f2021-02-12 06:18:28 +000011871 /**
11872 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11873 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11874 */
11875 // Used for SHELL command only right now.
11876 @Override
11877 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11878 List<String> featureTags) {
11879 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11880 "addUceRegistrationOverrideShell");
11881 final long identity = Binder.clearCallingIdentity();
11882 try {
11883 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11884 new ArraySet<>(featureTags));
11885 } catch (ImsException e) {
11886 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11887 } finally {
11888 Binder.restoreCallingIdentity(identity);
11889 }
11890 }
11891
11892 /**
11893 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11894 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11895 */
11896 // Used for SHELL command only right now.
11897 @Override
11898 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11899 List<String> featureTags) {
11900 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11901 "removeUceRegistrationOverrideShell");
11902 final long identity = Binder.clearCallingIdentity();
11903 try {
11904 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11905 new ArraySet<>(featureTags));
11906 } catch (ImsException e) {
11907 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11908 } finally {
11909 Binder.restoreCallingIdentity(identity);
11910 }
11911 }
11912
11913 /**
11914 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11915 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11916 */
11917 // Used for SHELL command only right now.
11918 @Override
11919 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11920 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11921 "clearUceRegistrationOverrideShell");
11922 final long identity = Binder.clearCallingIdentity();
11923 try {
11924 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11925 } catch (ImsException e) {
11926 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11927 } finally {
11928 Binder.restoreCallingIdentity(identity);
11929 }
11930 }
11931
11932 /**
11933 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11934 */
11935 // Used for SHELL command only right now.
11936 @Override
11937 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11938 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11939 "getLatestRcsContactUceCapabilityShell");
11940 final long identity = Binder.clearCallingIdentity();
11941 try {
11942 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11943 } catch (ImsException e) {
11944 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11945 } finally {
11946 Binder.restoreCallingIdentity(identity);
11947 }
11948 }
11949
11950 /**
11951 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11952 * device does not have an active PUBLISH.
11953 */
11954 // Used for SHELL command only right now.
11955 @Override
11956 public String getLastUcePidfXmlShell(int subId) {
11957 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11958 final long identity = Binder.clearCallingIdentity();
11959 try {
11960 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11961 } catch (ImsException e) {
11962 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11963 } finally {
11964 Binder.restoreCallingIdentity(identity);
11965 }
11966 }
11967
James.cf Line8713a42021-04-29 16:04:26 +080011968 /**
11969 * Remove UCE requests cannot be sent to the network status.
11970 */
11971 // Used for SHELL command only right now.
11972 @Override
11973 public boolean removeUceRequestDisallowedStatus(int subId) {
11974 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11975 final long identity = Binder.clearCallingIdentity();
11976 try {
11977 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11978 } catch (ImsException e) {
11979 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11980 } finally {
11981 Binder.restoreCallingIdentity(identity);
11982 }
11983 }
11984
James.cf Lin18bb9002021-05-25 01:37:38 +080011985 /**
11986 * Remove UCE requests cannot be sent to the network status.
11987 */
11988 // Used for SHELL command only.
11989 @Override
11990 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11991 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11992 final long identity = Binder.clearCallingIdentity();
11993 try {
11994 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11995 } catch (ImsException e) {
11996 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11997 } finally {
11998 Binder.restoreCallingIdentity(identity);
11999 }
12000 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012001
James.cf Lin4b784aa2021-01-31 03:25:15 +080012002 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012003 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12004 String callingPackage) {
12005 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12006 mApp, subId, "setSignalStrengthUpdateRequest");
12007
12008 final int callingUid = Binder.getCallingUid();
12009 // Verify that tha callingPackage belongs to the calling UID
12010 mApp.getSystemService(AppOpsManager.class)
12011 .checkPackage(callingUid, callingPackage);
12012
Rambo Wang3607f502021-02-01 21:51:40 -080012013 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012014
12015 final long identity = Binder.clearCallingIdentity();
12016 try {
12017 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12018 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12019
12020 if (result instanceof IllegalStateException) {
12021 throw (IllegalStateException) result;
12022 }
12023 } finally {
12024 Binder.restoreCallingIdentity(identity);
12025 }
12026 }
12027
12028 @Override
12029 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12030 String callingPackage) {
12031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12032 mApp, subId, "clearSignalStrengthUpdateRequest");
12033
12034 final int callingUid = Binder.getCallingUid();
12035 // Verify that tha callingPackage belongs to the calling UID
12036 mApp.getSystemService(AppOpsManager.class)
12037 .checkPackage(callingUid, callingPackage);
12038
12039 final long identity = Binder.clearCallingIdentity();
12040 try {
12041 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12042 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12043
12044 if (result instanceof IllegalStateException) {
12045 throw (IllegalStateException) result;
12046 }
12047 } finally {
12048 Binder.restoreCallingIdentity(identity);
12049 }
12050 }
12051
Rambo Wang3607f502021-02-01 21:51:40 -080012052 private static void validateSignalStrengthUpdateRequest(Context context,
12053 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012054 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12055 // phone/system process do not have further restriction on request
12056 return;
12057 }
12058
12059 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012060 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012061 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012062 context.enforceCallingOrSelfPermission(
12063 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12064 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012065 }
12066
12067 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012068 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012069 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012070 || info.isEnabled()) {
12071 throw new IllegalArgumentException(
12072 "Only system can set hide fields in SignalThresholdInfo");
12073 }
12074
12075 // Thresholds length for each RAN need in range. This has been validated in
12076 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12077 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12078 final int[] thresholds = info.getThresholds();
12079 Objects.requireNonNull(thresholds);
12080 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12081 || thresholds.length
12082 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12083 throw new IllegalArgumentException(
12084 "thresholds length is out of range: " + thresholds.length);
12085 }
12086 }
12087 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012088
12089 /**
12090 * Gets the current phone capability.
12091 *
12092 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12093 * @return the PhoneCapability which describes the data connection capability of modem.
12094 * It's used to evaluate possible phone config change, for example from single
12095 * SIM device to multi-SIM device.
12096 */
12097 @Override
12098 public PhoneCapability getPhoneCapability() {
12099 enforceReadPrivilegedPermission("getPhoneCapability");
12100 final long identity = Binder.clearCallingIdentity();
12101 try {
12102 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12103 } finally {
12104 Binder.restoreCallingIdentity(identity);
12105 }
12106 }
Michele Berionne5e411512020-11-13 02:36:59 +000012107
12108 /**
12109 * Prepare TelephonyManager for an unattended reboot. The reboot is
12110 * required to be done shortly after the API is invoked.
12111 */
12112 @Override
12113 @TelephonyManager.PrepareUnattendedRebootResult
12114 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012115 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012116 enforceRebootPermission();
12117
12118 final long identity = Binder.clearCallingIdentity();
12119 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012120 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012121 } finally {
12122 Binder.restoreCallingIdentity(identity);
12123 }
12124 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012125
12126 /**
12127 * Request to get the current slicing configuration including URSP rules and
12128 * NSSAIs (configured, allowed and rejected).
12129 *
12130 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12131 */
12132 @Override
12133 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012134 TelephonyPermissions
12135 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12136 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012137
12138 final long identity = Binder.clearCallingIdentity();
12139 try {
12140 Phone phone = getDefaultPhone();
12141 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12142 } finally {
12143 Binder.restoreCallingIdentity(identity);
12144 }
12145 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012146
12147 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012148 * Check whether the given premium capability is available for purchase from the carrier.
12149 *
12150 * @param capability The premium capability to check.
12151 * @param subId The subId to check the premium capability for.
12152 *
12153 * @return Whether the given premium capability is available to purchase.
12154 */
12155 @Override
12156 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12157 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12158 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12159 log("Premium capability "
12160 + TelephonyManager.convertPremiumCapabilityToString(capability)
12161 + " is not available for purchase due to missing permissions.");
12162 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12163 + "permission READ_BASIC_PHONE_STATE.");
12164 }
12165
12166 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012167 if (phone == null) {
12168 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12169 return false;
12170 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012171 final long identity = Binder.clearCallingIdentity();
12172 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070012173 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012174 .isPremiumCapabilityAvailableForPurchase(capability);
12175 } finally {
12176 Binder.restoreCallingIdentity(identity);
12177 }
12178 }
12179
12180 /**
12181 * Purchase the given premium capability from the carrier.
12182 *
12183 * @param capability The premium capability to purchase.
12184 * @param callback The result of the purchase request.
12185 * @param subId The subId to purchase the premium capability for.
12186 */
12187 @Override
12188 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12189 log("purchasePremiumCapability: capability="
12190 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12191 + getCurrentPackageName());
12192
12193 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12194 mApp, "purchasePremiumCapability")) {
12195 log("purchasePremiumCapability "
12196 + TelephonyManager.convertPremiumCapabilityToString(capability)
12197 + " failed due to missing permissions.");
12198 throw new SecurityException("purchasePremiumCapability requires permission "
12199 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012200 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12201 mApp, "purchasePremiumCapability")) {
12202 log("purchasePremiumCapability "
12203 + TelephonyManager.convertPremiumCapabilityToString(capability)
12204 + " failed due to missing permissions.");
12205 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012206 }
12207
12208 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012209 if (phone == null) {
12210 try {
12211 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12212 callback.accept(result);
12213 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12214 } catch (RemoteException e) {
12215 String logStr = "Purchase premium capability "
12216 + TelephonyManager.convertPremiumCapabilityToString(capability)
12217 + " failed due to RemoteException handling null phone: " + e;
12218 if (DBG) log(logStr);
12219 AnomalyReporter.reportAnomaly(
12220 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12221 }
12222 return;
12223 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012224
12225 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012226 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012227 callingProcess = mApp.getPackageManager().getApplicationInfo(
12228 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012229 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012230 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012231 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012232
12233 boolean isVisible = false;
12234 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12235 if (am != null) {
12236 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12237 if (processes != null) {
12238 for (ActivityManager.RunningAppProcessInfo process : processes) {
12239 log("purchasePremiumCapability: process " + process.processName
12240 + "has importance " + process.importance);
12241 if (process.processName.equals(callingProcess) && process.importance
12242 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12243 isVisible = true;
12244 break;
12245 }
12246 }
12247 }
12248 }
12249
12250 if (!isVisible) {
12251 try {
12252 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12253 callback.accept(result);
12254 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12255 } catch (RemoteException e) {
12256 String logStr = "Purchase premium capability "
12257 + TelephonyManager.convertPremiumCapabilityToString(capability)
12258 + " failed due to RemoteException handling background application: " + e;
12259 if (DBG) log(logStr);
12260 AnomalyReporter.reportAnomaly(
12261 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12262 }
12263 return;
12264 }
12265
Sarah Chin71b3a852022-09-28 15:54:19 -070012266 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012267 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012268 }
12269
12270 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012271 * Register an IMS connection state callback
12272 */
12273 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012274 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12275 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012276 if (feature == ImsFeature.FEATURE_MMTEL) {
12277 // ImsMmTelManager
12278 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12279 TelephonyPermissions
12280 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12281 mApp, subId, "registerImsStateCallback");
12282 } else if (feature == ImsFeature.FEATURE_RCS) {
12283 // ImsRcsManager or SipDelegateManager
12284 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12285 Binder.getCallingUid(), "registerImsStateCallback",
12286 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12287 Manifest.permission.READ_PRECISE_PHONE_STATE,
12288 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12289 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12290 }
12291
12292 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12293 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12294 "IMS not available on device.");
12295 }
12296
12297 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12298 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12299 }
12300
12301 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12302 if (controller == null) {
12303 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12304 "IMS not available on device.");
12305 }
12306
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012307 if (callingPackage == null) {
12308 callingPackage = getCurrentPackageName();
12309 }
12310
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012311 final long token = Binder.clearCallingIdentity();
12312 try {
12313 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012314 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012315 } catch (ImsException e) {
12316 throw new ServiceSpecificException(e.getCode());
12317 } finally {
12318 Binder.restoreCallingIdentity(token);
12319 }
12320 }
12321
12322 /**
12323 * Unregister an IMS connection state callback
12324 */
12325 @Override
12326 public void unregisterImsStateCallback(IImsStateCallback cb) {
12327 final long token = Binder.clearCallingIdentity();
12328 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12329 if (controller == null) {
12330 return;
12331 }
12332 try {
12333 controller.unregisterImsStateCallback(cb);
12334 } finally {
12335 Binder.restoreCallingIdentity(token);
12336 }
12337 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012338
12339 /**
12340 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12341 *
12342 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
12343 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
12344 * SecurityException.
12345 * If there is current registered network this value will be same as the registered cell
12346 * identity. If the device goes out of service the previous cell identity is cached and
12347 * will be returned. If the cache age of the Cell identity is more than 24 hours
12348 * it will be cleared and null will be returned.
12349 *
12350 */
12351 @Override
12352 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12353 String callingFeatureId) {
12354 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12355 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12356 LocationAccessPolicy.checkLocationPermission(mApp,
12357 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12358 .setCallingPackage(callingPackage)
12359 .setCallingFeatureId(callingFeatureId)
12360 .setCallingPid(Binder.getCallingPid())
12361 .setCallingUid(Binder.getCallingUid())
12362 .setMethod("getLastKnownCellIdentity")
12363 .setLogAsInfo(true)
12364 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12365 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12366 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12367 .build());
12368
12369 boolean hasFinePermission =
12370 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12371 if (!hasFinePermission
12372 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12373 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012374 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012375 }
12376
12377 final long identity = Binder.clearCallingIdentity();
12378 try {
12379 Phone phone = getPhone(subId);
12380 if (phone == null) return null;
12381 ServiceStateTracker sst = phone.getServiceStateTracker();
12382 if (sst == null) return null;
12383 return sst.getLastKnownCellIdentity();
12384 } finally {
12385 Binder.restoreCallingIdentity(identity);
12386 }
12387 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012388
jimsun3b9ccac2021-10-26 15:01:23 +080012389 /**
12390 * Sets the modem service class Name that Telephony will bind to.
12391 *
12392 * @param serviceName The class name of the modem service.
12393 * @return true if the operation is succeed, otherwise false.
12394 */
12395 public boolean setModemService(String serviceName) {
12396 Log.d(LOG_TAG, "setModemService - " + serviceName);
12397 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012399 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12400 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012401 return mPhoneConfigurationManager.setModemService(serviceName);
12402 }
12403
12404 /**
12405 * Return the class name of the currently bounded modem service.
12406 *
12407 * @return the class name of the modem service.
12408 */
12409 public String getModemService() {
12410 String result;
12411 Log.d(LOG_TAG, "getModemService");
12412 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12413 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012414 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012415 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12416 "getModemService");
12417 result = mPhoneConfigurationManager.getModemService();
12418 Log.d(LOG_TAG, "result = " + result);
12419 return result;
12420 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012421
12422 @Override
12423 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12424 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12425 mApp.enforceCallingOrSelfPermission(
12426 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12427 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12428
12429 final long identity = Binder.clearCallingIdentity();
12430 try {
12431 Phone phone = getPhone(subId);
12432 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012433 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12434 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012435 phone.setVoiceServiceStateOverride(hasService);
12436 } finally {
12437 Binder.restoreCallingIdentity(identity);
12438 }
12439 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012440
12441 /**
12442 * set removable eSIM as default eUICC.
12443 *
12444 * @hide
12445 */
12446 @Override
12447 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12448 enforceModifyPermission();
12449 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12450
12451 final long identity = Binder.clearCallingIdentity();
12452 try {
12453 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12454 } finally {
12455 Binder.restoreCallingIdentity(identity);
12456 }
12457 }
12458
12459 /**
12460 * Returns whether the removable eSIM is default eUICC or not.
12461 *
12462 * @hide
12463 */
12464 @Override
12465 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12466 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12467 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12468
12469 final long identity = Binder.clearCallingIdentity();
12470 try {
12471 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12472 } finally {
12473 Binder.restoreCallingIdentity(identity);
12474 }
12475 }
12476
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012477 /**
12478 * Get the component name of the default app to direct respond-via-message intent for the
12479 * user associated with this subscription, update the cache if there is no respond-via-message
12480 * application currently configured for this user.
12481 * @return component name of the app and class to direct Respond Via Message intent to, or
12482 * {@code null} if the functionality is not supported.
12483 * @hide
12484 */
12485 @Override
12486 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12487 boolean updateIfNeeded) {
12488 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012489
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012490 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12491
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012492 UserHandle userHandle = null;
12493 final long identity = Binder.clearCallingIdentity();
12494 try {
12495 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12496 } finally {
12497 Binder.restoreCallingIdentity(identity);
12498 }
12499 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12500 updateIfNeeded, userHandle);
12501 }
Jack Yuf5badd92022-12-08 00:50:53 -080012502
12503 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012504 * Set whether the device is able to connect with null ciphering or integrity
12505 * algorithms. This is a global setting and will apply to all active subscriptions
12506 * and all new subscriptions after this.
12507 *
12508 * @param enabled when true, null cipher and integrity algorithms are allowed.
12509 * @hide
12510 */
12511 @Override
12512 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12513 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12514 enforceModifyPermission();
12515 checkForNullCipherAndIntegritySupport();
12516
12517 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12518 // for listening to these preference changes and applying them immediately.
12519 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12520 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12521 editor.apply();
12522
12523 for (Phone phone: PhoneFactory.getPhones()) {
12524 phone.handleNullCipherEnabledChange();
12525 }
12526 }
12527
12528
12529 /**
12530 * Get whether the device is able to connect with null ciphering or integrity
12531 * algorithms. Note that this retrieves the phone-global preference and not
12532 * the state of the radio.
12533 *
12534 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12535 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12536 * version for this feature.
12537 * @hide
12538 */
12539 @Override
12540 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12541 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12542 enforceReadPermission();
12543 checkForNullCipherAndIntegritySupport();
12544 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12545 }
12546
12547 private void checkForNullCipherAndIntegritySupport() {
12548 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12549 throw new UnsupportedOperationException(
12550 "Null cipher and integrity operations require HAL 2.1 or above");
12551 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012552 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12553 throw new UnsupportedOperationException(
12554 "Null cipher and integrity operations unsupported by modem");
12555 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012556 }
12557
12558 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012559 * Get the SIM state for the slot index.
12560 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12561 *
12562 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12563 */
12564 @Override
12565 @SimState
12566 public int getSimStateForSlotIndex(int slotIndex) {
12567 IccCardConstants.State simState;
12568 if (slotIndex < 0) {
12569 simState = IccCardConstants.State.UNKNOWN;
12570 } else {
12571 Phone phone = null;
12572 try {
12573 phone = PhoneFactory.getPhone(slotIndex);
12574 } catch (IllegalStateException e) {
12575 // ignore
12576 }
12577 if (phone == null) {
12578 simState = IccCardConstants.State.UNKNOWN;
12579 } else {
12580 IccCard icc = phone.getIccCard();
12581 if (icc == null) {
12582 simState = IccCardConstants.State.UNKNOWN;
12583 } else {
12584 simState = icc.getState();
12585 }
12586 }
12587 }
12588 return simState.ordinal();
12589 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012590
12591 /**
12592 * Get current cell broadcast ranges.
12593 */
12594 @Override
12595 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12596 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12597 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12598 "getCellBroadcastIdRanges");
12599 final long identity = Binder.clearCallingIdentity();
12600 try {
12601 return getPhone(subId).getCellBroadcastIdRanges();
12602 } finally {
12603 Binder.restoreCallingIdentity(identity);
12604 }
12605 }
12606
12607 /**
12608 * Set reception of cell broadcast messages with the list of the given ranges
12609 *
12610 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12611 */
12612 @Override
12613 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12614 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12615 @Nullable IIntegerConsumer callback) {
12616 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12617 "setCellBroadcastIdRanges");
12618 final long identity = Binder.clearCallingIdentity();
12619 try {
12620 Phone phone = getPhoneFromSubId(subId);
12621 if (DBG) {
12622 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12623 }
12624 phone.setCellBroadcastIdRanges(ranges, result -> {
12625 if (callback != null) {
12626 try {
12627 callback.accept(result);
12628 } catch (RemoteException e) {
12629 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12630 }
12631 }
12632 });
12633 } finally {
12634 Binder.restoreCallingIdentity(identity);
12635 }
12636 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012637
12638 /**
12639 * Returns whether the device supports the domain selection service.
12640 *
12641 * @return {@code true} if the device supports the domain selection service.
12642 */
12643 @Override
12644 public boolean isDomainSelectionSupported() {
12645 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12646 "isDomainSelectionSupported");
12647
12648 final long identity = Binder.clearCallingIdentity();
12649 try {
12650 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12651 } finally {
12652 Binder.restoreCallingIdentity(identity);
12653 }
12654 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012655
12656 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012657 * Enable or disable the satellite modem. If the satellite modem is enabled, this will also
12658 * disable the cellular modem, and if the satellite modem is disabled, this will also re-enable
12659 * the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012660 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012661 * @param subId The subId to set satellite enabled for.
12662 * @param enable {@code true} to enable the satellite modem and {@code false} to disable.
12663 * @param callback The callback to get the error code of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012664 *
12665 * @throws SecurityException if the caller doesn't have the required permission.
12666 */
12667 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012668 public void setSatelliteEnabled(int subId, boolean enable, @NonNull IIntegerConsumer callback) {
12669 enforceSatelliteCommunicationPermission("setSatelliteEnabled");
12670 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012671 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012672 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12673 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012674 }
Sarah Chin503828c2023-02-01 23:54:20 -080012675
12676 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012677 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012678 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
12679 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012680 }
12681
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012682 Phone phone = getPhoneOrDefault(validSubId, "setSatelliteEnabled");
Sarah Chin503828c2023-02-01 23:54:20 -080012683 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012684 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
12685 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012686 }
12687
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012688 Pair<Boolean, Consumer<Integer>> arg = new Pair<>(enable, result);
12689 sendRequestAsync(CMD_SET_SATELLITE_ENABLED, arg, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080012690 }
12691
12692 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012693 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012694 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012695 * @param subId The subId to check whether satellite is enabled for.
12696 * @param result The result receiver that returns whether the satellite modem is enabled
12697 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012698 *
12699 * @throws SecurityException if the caller doesn't have the required permission.
12700 */
12701 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012702 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12703 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012704 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012705 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
12706 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012707 }
Sarah Chin503828c2023-02-01 23:54:20 -080012708
12709 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012710 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012711 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
12712 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012713 }
12714
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012715 Phone phone = getPhoneOrDefault(validSubId, "requestIsSatelliteEnabled");
Sarah Chin503828c2023-02-01 23:54:20 -080012716 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012717 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12718 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012719 }
12720
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012721 sendRequest(CMD_IS_SATELLITE_ENABLED, result, subId);
Sarah Chin503828c2023-02-01 23:54:20 -080012722 }
12723
12724 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012725 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012726 *
12727 * @param subId The subId to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012728 * @param result The result receiver that returns whether the satellite service is supported on
12729 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012730 */
12731 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012732 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012733 synchronized (mIsSatelliteSupportedLock) {
12734 if (mIsSatelliteSupported != null) {
12735 /* We have already successfully queried the satellite modem. */
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012736 Bundle bundle = new Bundle();
12737 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, mIsSatelliteSupported);
12738 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, bundle);
12739 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012740 }
12741 }
Sarah Chin503828c2023-02-01 23:54:20 -080012742
12743 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012744 Phone phone = getPhoneOrDefault(validSubId, "requestIsSatelliteSupported");
Sarah Chin503828c2023-02-01 23:54:20 -080012745 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012746 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12747 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012748 }
12749
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012750 sendRequestAsync(CMD_IS_SATELLITE_SUPPORTED, result, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080012751 }
12752
12753 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012754 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012755 *
12756 * @param subId The subId to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012757 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12758 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012759 *
12760 * @throws SecurityException if the caller doesn't have required permission.
12761 */
12762 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012763 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12764 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012765 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012766 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
12767 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012768 }
Sarah Chin503828c2023-02-01 23:54:20 -080012769
12770 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012771 Phone phone = getPhoneOrDefault(validSubId, "requestSatelliteCapabilities");
Sarah Chin503828c2023-02-01 23:54:20 -080012772 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012773 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12774 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012775 }
12776
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012777 sendRequestAsync(CMD_GET_SATELLITE_CAPABILITIES, result, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080012778 }
12779
12780 /**
Sarah Chineccfbd12023-01-20 19:00:35 -080012781 * Start receiving satellite position updates.
12782 * This can be called by the pointing UI when the user starts pointing to the satellite.
12783 * Modem should continue to report the pointing input as the device or satellite moves.
12784 *
12785 * @param subId The subId to start satellite position updates for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012786 * @param errorCallback The callback to get the error code of the request.
Sarah Chineccfbd12023-01-20 19:00:35 -080012787 * @param callback The callback to notify of changes in satellite position.
Sarah Chin503828c2023-02-01 23:54:20 -080012788 *
12789 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012790 */
12791 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012792 public void startSatellitePositionUpdates(int subId, @NonNull IIntegerConsumer errorCallback,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012793 @NonNull ISatelliteStateListener callback) {
Sarah Chinf75afa72023-02-01 01:32:19 -080012794 enforceSatelliteCommunicationPermission("startSatellitePositionUpdates");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012795 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012796 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012797 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12798 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012799 }
Sarah Chinf75afa72023-02-01 01:32:19 -080012800
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012801 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012802 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012803 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
12804 return;
Sarah Chinf75afa72023-02-01 01:32:19 -080012805 }
12806
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012807 Phone phone = getPhoneOrDefault(validSubId, "startSatellitePositionUpdates");
Sarah Chineccfbd12023-01-20 19:00:35 -080012808 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012809 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
12810 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012811 }
12812
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012813 if (mSatellitePositionUpdateHandlers.containsKey(callback.asBinder())) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012814 if (DBG) {
12815 log("startSatellitePositionUpdates: callback already registered: "
12816 + callback.asBinder());
12817 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012818 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
12819 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012820 }
12821
12822 SatellitePositionUpdateHandler handler =
12823 new SatellitePositionUpdateHandler(callback, Looper.getMainLooper());
12824 phone.registerForSatellitePointingInfoChanged(handler,
12825 SatellitePositionUpdateHandler.EVENT_POSITION_UPDATE, null);
12826 phone.registerForSatelliteMessagesTransferComplete(handler,
12827 SatellitePositionUpdateHandler.EVENT_MESSAGE_TRANSFER_STATE_UPDATE, null);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012828 mSatellitePositionUpdateHandlers.put(callback.asBinder(), handler);
Sarah Chineccfbd12023-01-20 19:00:35 -080012829
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012830 sendRequestAsync(CMD_START_SATELLITE_POSITION_UPDATES, result, phone, null);
Sarah Chineccfbd12023-01-20 19:00:35 -080012831 }
12832
12833 /**
12834 * Stop receiving satellite position updates.
12835 * This can be called by the pointing UI when the user stops pointing to the satellite.
12836 *
12837 * @param subId The subId to stop satellite position updates for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012838 * @param errorCallback The callback to get the error code of the request.
12839 * @param callback The callback that was passed to {@link
12840 * #startSatellitePositionUpdates(int, IIntegerConsumer, ISatelliteStateListener)}
Sarah Chin503828c2023-02-01 23:54:20 -080012841 *
12842 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012843 */
12844 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012845 public void stopSatellitePositionUpdates(int subId, @NonNull IIntegerConsumer errorCallback,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012846 @NonNull ISatelliteStateListener callback) {
Sarah Chinf75afa72023-02-01 01:32:19 -080012847 enforceSatelliteCommunicationPermission("stopSatellitePositionUpdates");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012848 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012849 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012850 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12851 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012852 }
Sarah Chinf75afa72023-02-01 01:32:19 -080012853
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012854 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012855 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012856 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
12857 return;
Sarah Chinf75afa72023-02-01 01:32:19 -080012858 }
12859
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012860 Phone phone = getPhoneOrDefault(validSubId, "stopSatellitePositionUpdates");
Sarah Chineccfbd12023-01-20 19:00:35 -080012861 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012862 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
12863 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012864 }
12865
12866 SatellitePositionUpdateHandler handler =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012867 mSatellitePositionUpdateHandlers.remove(callback.asBinder());
Sarah Chineccfbd12023-01-20 19:00:35 -080012868 if (handler == null) {
12869 loge("stopSatellitePositionUpdates: No SatellitePositionArgument");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012870 result.accept(SatelliteManager.SATELLITE_INVALID_ARGUMENTS);
12871 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012872 } else {
12873 phone.unregisterForSatellitePointingInfoChanged(handler);
12874 phone.unregisterForSatelliteMessagesTransferComplete(handler);
12875 }
12876
12877 if (!mSatellitePositionUpdateHandlers.isEmpty()) {
12878 log("stopSatellitePositionUpdates: other listeners still exist.");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012879 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
12880 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012881 }
12882
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012883 sendRequestAsync(CMD_STOP_SATELLITE_POSITION_UPDATES, result, phone, null);
Sarah Chineccfbd12023-01-20 19:00:35 -080012884 }
12885
12886 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012887 * Request to get the maximum number of characters per text message on satellite.
12888 *
12889 * @param subId The subId of the subscription.
12890 * @param result The result receiver that returns the maximum number of characters per text
12891 * message on satellite if the request is successful or an error code
12892 * if the request failed.
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012893 *
12894 * @throws SecurityException if the caller doesn't have the required permission.
12895 */
12896 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012897 public void requestMaxCharactersPerSatelliteTextMessage(int subId,
12898 @NonNull ResultReceiver result) {
12899 enforceSatelliteCommunicationPermission("requestMaxCharactersPerSatelliteTextMessage");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012900 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012901 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
12902 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012903 }
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012904
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012905 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012906 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012907 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
12908 return;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012909 }
12910
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012911 Phone phone = getPhoneOrDefault(validSubId, "requestMaxCharactersPerSatelliteTextMessage");
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012912 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012913 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12914 return;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012915 }
12916
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012917 sendRequestAsync(CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG, result, phone, null);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012918 }
12919
12920 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012921 * Register the subscription with a satellite provider.
12922 * This is needed to register the subscription if the provider allows dynamic registration.
12923 *
12924 * @param subId The subId of the subscription to be provisioned.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012925 * @param token The security token of the device/subscription to be provisioned.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012926 * @param callback The callback to get the error code of the request.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012927 * @return The signal transport used by the caller to cancel the provision request,
12928 * or {@code null} if the request failed.
12929 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012930 * @throws SecurityException if the caller doesn't have the required permission.
12931 */
12932 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012933 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
12934 @NonNull String token, @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012935 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012936 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012937 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012938 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012939 return null;
12940 }
12941
12942 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012943 Phone phone = getPhoneOrDefault(validSubId, "provisionSatelliteService");
12944 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012945 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012946 return null;
12947 }
12948
12949 if (mSatelliteProvisionCallbacks.containsKey(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012950 result.accept(SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012951 return null;
12952 }
12953
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012954 if (isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012955 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012956 return null;
12957 }
12958
12959 sendRequestAsync(CMD_PROVISION_SATELLITE_SERVICE,
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012960 new ProvisionSatelliteServiceArgument(token, result, validSubId), phone, null);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012961
12962 ICancellationSignal cancelTransport = CancellationSignal.createTransport();
12963 CancellationSignal.fromTransport(cancelTransport)
12964 .setOnCancelListener(() -> {
12965 sendRequestAsync(CMD_CANCEL_PROVISION_SATELLITE_SERVICE, validSubId);
12966 });
12967 return cancelTransport;
12968 }
12969
12970 /**
12971 * Register for the satellite provision state change.
12972 *
12973 * @param subId The subId of the subscription associated with the satellite service.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012974 * @param errorCallback The callback to get the error code of the request.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012975 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012976 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012977 * @throws SecurityException if the caller doesn't have the required permission.
12978 */
12979 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012980 public void registerForSatelliteProvisionStateChanged(int subId,
12981 @NonNull IIntegerConsumer errorCallback, @NonNull ISatelliteStateListener callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012982 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012983 Consumer<Integer> result = null;
12984 if (errorCallback != null) {
12985 result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
12986 }
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012987 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012988 if (result != null) {
12989 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12990 }
12991 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012992 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012993
12994 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012995 Phone phone = getPhoneOrDefault(validSubId, "registerForSatelliteProvisionStateChanged");
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012996 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012997 if (result != null) {
12998 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
12999 }
13000 return;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013001 }
13002
13003 SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler =
13004 mSatelliteProvisionStateChangedHandlers.get(validSubId);
13005 if (satelliteProvisionStateChangedHandler == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013006 satelliteProvisionStateChangedHandler = new SatelliteProvisionStateChangedHandler(
13007 Looper.getMainLooper(), validSubId);
13008 phone.registerForSatelliteProvisionStateChanged(satelliteProvisionStateChangedHandler,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013009 SatelliteProvisionStateChangedHandler.EVENT_PROVISION_STATE_CHANGED, null);
13010 }
13011
13012 if (callback != null) {
13013 satelliteProvisionStateChangedHandler.addListener(callback);
13014 }
13015 mSatelliteProvisionStateChangedHandlers.put(
13016 validSubId, satelliteProvisionStateChangedHandler);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013017 if (result != null) {
13018 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
13019 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013020 }
13021
13022 /**
13023 * Unregister for the satellite provision state change.
13024 *
13025 * @param subId The subId of the subscription associated with the satellite service.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013026 * @param errorCallback The callback to get the error code of the request.
13027 * @param callback The callback that was passed to {@link
13028 * #registerForSatelliteProvisionStateChanged(int, IIntegerConsumer, ISatelliteStateListener)}.
13029 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013030 * @throws SecurityException if the caller doesn't have the required permission.
13031 */
13032 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013033 public void unregisterForSatelliteProvisionStateChanged(int subId,
13034 @NonNull IIntegerConsumer errorCallback, @NonNull ISatelliteStateListener callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013035 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013036 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013037 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013038 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
13039 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013040 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013041
13042 final int validSubId = getValidSatelliteSubId(subId);
13043 SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler =
13044 mSatelliteProvisionStateChangedHandlers.get(validSubId);
13045 if (satelliteProvisionStateChangedHandler != null) {
13046 if (satelliteProvisionStateChangedHandler.removeListener(callback)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013047 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
13048 return;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013049 }
13050 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013051 result.accept(SatelliteManager.SATELLITE_INVALID_ARGUMENTS);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013052 }
13053
13054 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013055 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013056 *
13057 * @param subId The subId of the subscription associated with the satellite service.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013058 * @param result The result receiver that returns whether the device is provisioned with a
13059 * satellite provider if the request is successful or an error code if the
13060 * request failed.
13061 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013062 * @throws SecurityException if the caller doesn't have the required permission.
13063 */
13064 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013065 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13066 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013067 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013068 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
13069 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013070 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013071
13072 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013073 Bundle bundle = new Bundle();
13074 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_PROVISIONED,
13075 isSatelliteProvisioned(validSubId));
13076 result.send(SatelliteManager.SATELLITE_ERROR_NONE, bundle);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013077 }
13078
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013079 /**
13080 * Register for listening to satellite state changes.
13081 *
13082 * @param subId - The subId to start listening to satellite state changes for.
13083 * @param callback - The callback to handle the satellite state change event.
13084 * @return The result of the operation.
13085 * @throws SecurityException if the caller doesn't have the required permission.
13086 */
13087 @Override
13088 @SatelliteManager.SatelliteError
13089 public int registerForSatelliteModemStateChange(int subId,
13090 @NonNull ISatelliteStateListener callback) {
13091 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChange");
13092
13093 final int validSubId = getValidSatelliteSubId(subId);
13094 Phone phone = getPhoneOrDefault(
13095 validSubId, "registerForSatelliteModemStateChange");
13096 if (phone == null) {
13097 return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
13098 }
13099
13100 SatelliteStateListenerHandler satelliteStateListenerHandler =
13101 mSatelliteStateListenerHandlers.get(validSubId);
13102 if (satelliteStateListenerHandler == null) {
13103 satelliteStateListenerHandler = new SatelliteStateListenerHandler(
13104 Looper.getMainLooper(), validSubId);
13105 phone.registerForSatelliteModemStateChange(satelliteStateListenerHandler,
13106 SatelliteStateListenerHandler.EVENT_SATELLITE_MODEM_STATE_CHANGE, null);
13107 phone.registerForPendingMessageCount(satelliteStateListenerHandler,
13108 SatelliteStateListenerHandler.EVENT_PENDING_MESSAGE_COUNT, null);
13109 }
13110
13111 satelliteStateListenerHandler.addListener(callback);
13112 mSatelliteStateListenerHandlers.put(validSubId, satelliteStateListenerHandler);
13113 return SatelliteManager.SATELLITE_ERROR_NONE;
13114 }
13115
13116 /**
13117 * Unregister from listening to satellite state changes.
13118 *
13119 * @param subId - The subId to stop listening to satellite state changes for.
13120 * @param callback - The callback that was passed to
13121 * {@link #registerForSatelliteModemStateChange(int, ISatelliteStateListener)}
13122 * @return The result of the operation.
13123 *
13124 * @throws SecurityException if the caller doesn't have the required permission.
13125 */
13126 @Override
13127 @SatelliteManager.SatelliteError
13128 public int unregisterForSatelliteModemStateChange(int subId,
13129 @NonNull ISatelliteStateListener callback) {
13130 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChange");
13131
13132 final int validSubId = getValidSatelliteSubId(subId);
13133 SatelliteStateListenerHandler satelliteStateListenerHandler =
13134 mSatelliteStateListenerHandlers.get(validSubId);
13135 if (satelliteStateListenerHandler != null) {
13136 if (satelliteStateListenerHandler.removeListener(callback)) {
13137 return SatelliteManager.SATELLITE_ERROR_NONE;
13138 }
13139 }
13140 return SatelliteManager.SATELLITE_INVALID_ARGUMENTS;
13141 }
13142
13143 /**
13144 * Register to receive incoming datagrams over satellite.
13145 *
13146 * @param subId - The subId to start receiving datagrams over satellite.
13147 * @param datagramType - type of datagram
13148 * @param callback - The callback to handle incoming datagrams over satellite.
13149 * @return The result of the operation.
13150 * @throws SecurityException if the caller doesn't have the required permission.
13151 */
13152 @Override
13153 @SatelliteManager.SatelliteError
13154 public int registerForSatelliteDatagram(int subId,
13155 @SatelliteManager.DatagramType int datagramType,
13156 @NonNull ISatelliteStateListener callback) {
13157 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
13158
13159 final int validSubId = getValidSatelliteSubId(subId);
13160 Phone phone = getPhoneOrDefault(
13161 validSubId, "registerForSatelliteDatagram");
13162 if (phone == null) {
13163 return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
13164 }
13165
13166 SatelliteDatagramListenerHandler satelliteDatagramListenerHandler =
13167 mSatelliteDatagramListenerHandlers.get(validSubId);
13168 if (satelliteDatagramListenerHandler == null) {
13169 satelliteDatagramListenerHandler = new SatelliteDatagramListenerHandler(
13170 Looper.getMainLooper(), validSubId);
13171 phone.registerForNewSatelliteDatagram(satelliteDatagramListenerHandler,
13172 SatelliteDatagramListenerHandler.EVENT_SATELLITE_DATAGRAMS_RECEIVED, null);
13173 }
13174
13175 satelliteDatagramListenerHandler.addListener(callback);
13176 mSatelliteDatagramListenerHandlers.put(validSubId, satelliteDatagramListenerHandler);
13177 return SatelliteManager.SATELLITE_ERROR_NONE;
13178 }
13179
13180 /**
13181 * Unregister to stop receiving incoming datagrams over satellite.
13182 *
13183 * @param subId - The subId to stop listening incoming datagrams over satellite.
13184 * @param callback - The callback that was passed to
13185 * {@link #registerForSatelliteDatagram(int, int, ISatelliteStateListener)}
13186 * @return The result of the operation.
13187 *
13188 * @throws SecurityException if the caller doesn't have the required permission.
13189 */
13190 @Override
13191 @SatelliteManager.SatelliteError
13192 public int unregisterForSatelliteDatagram(int subId,
13193 @NonNull ISatelliteStateListener callback) {
13194 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
13195
13196 final int validSubId = getValidSatelliteSubId(subId);
13197 SatelliteDatagramListenerHandler satelliteDatagramListenerHandler =
13198 mSatelliteDatagramListenerHandlers.get(validSubId);
13199 if (satelliteDatagramListenerHandler != null) {
13200 if (satelliteDatagramListenerHandler.removeListener(callback)) {
13201 return SatelliteManager.SATELLITE_ERROR_NONE;
13202 }
13203 }
13204 return SatelliteManager.SATELLITE_INVALID_ARGUMENTS;
13205 }
13206
13207
13208 /**
13209 * Poll pending satellite datagrams over satellite.
13210 * @param subId - The subId of the subscription used for receiving datagrams.
13211 * @return The result of the operation.
13212 * @throws SecurityException if the caller doesn't have the required permission.
13213 */
13214 @Override
13215 @SatelliteManager.SatelliteError
13216 public int pollPendingSatelliteDatagrams(int subId) {
13217 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
13218
13219 final int validSubId = getValidSatelliteSubId(subId);
13220 if (!isSatelliteProvisioned(validSubId)) {
13221 return SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED;
13222 }
13223
13224 Phone phone = getPhoneOrDefault(validSubId, "pollPendingSatelliteDatagrams");
13225 if (phone == null) {
13226 return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
13227 }
13228
13229 int result = (int) sendRequest(CMD_POLL_PENDING_SATELLITE_DATAGRAMS, null, validSubId);
13230 if (DBG) log("pollPendingSatelliteDatagrams result: " + result);
13231 return result;
13232 }
13233
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013234 private void handleCmdProvisionSatelliteService(@NonNull ProvisionSatelliteServiceArgument arg,
13235 @NonNull Phone phone, Message onCompleted) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013236 if (arg == null) {
13237 loge("handleCmdProvisionSatelliteService: arg is null");
13238 return;
13239 }
13240 if (phone == null) {
13241 loge("handleCmdProvisionSatelliteService: phone is null");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013242 arg.callback.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013243 return;
13244 }
13245
13246 if (!mSatelliteProvisionCallbacks.containsKey(arg.subId)) {
13247 mSatelliteProvisionCallbacks.put(arg.subId, arg.callback);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013248 phone.provisionSatelliteService(onCompleted, arg.token, phone.getImei(),
13249 phone.getMsisdn(), getSatelliteImsi(arg.subId));
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013250 } else {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013251 arg.callback.accept(SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013252 }
13253 }
13254
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013255 private void handleEventProvisionSatelliteServiceDone(int subId,
13256 @SatelliteManager.SatelliteError int result) {
13257 Consumer<Integer> callback = mSatelliteProvisionCallbacks.remove(subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013258 if (callback == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013259 loge("handleEventProvisionSatelliteServiceDone: callback is null for subId=" + subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013260 return;
13261 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013262 callback.accept(result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013263
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013264 if (DBG) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013265 log("handleEventProvisionSatelliteServiceDone: result=" + result + ", subId="
13266 + subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013267 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013268
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013269 if (result == SatelliteManager.SATELLITE_ERROR_NONE) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013270 setSatelliteProvisioned(subId, true);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013271 }
13272
13273 /**
13274 * We need to update satellite provision status in SubscriptionController
13275 * or SatelliteController.
13276 * TODO (b/267826133) we need to do this for all subscriptions on the device.
13277 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013278 registerForSatelliteProvisionStateChanged(subId, null, null);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013279 }
13280
13281 private void handleCmdCancelProvisionSatelliteService(int subId, Message onCompleted) {
13282 final Phone phone = getPhoneOrDefault(
13283 subId, "handleCmdCancelProvisionSatelliteService");
13284 if (phone == null) {
13285 return;
13286 }
13287 phone.cancelProvisionSatelliteService(onCompleted, getSatelliteImsi(subId));
13288 }
13289
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013290 private String getSatelliteImsi(int subId) {
13291 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
13292 return "";
13293 }
13294
13295 if (mSubscriptionController == null) {
13296 loge("getSatelliteImsi: mSubscriptionController is null");
13297 return "";
13298 }
13299 return mSubscriptionController.getImsiPrivileged(subId);
13300 }
13301
13302 private Phone getPhoneOrDefault(int subId, String caller) {
13303 Phone phone = getPhone(subId);
13304 if (phone == null) {
13305 loge(caller + " called with invalid subId: " + subId
13306 + ". Retrying with default phone.");
13307 phone = getDefaultPhone();
13308 if (phone == null) {
13309 loge(caller + " failed with no phone object.");
13310 }
13311 }
13312 return phone;
13313 }
13314
13315 /**
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013316 * Check if satellite is provisioned for a subscription or the device.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013317 *
13318 * Note: this is the version without permission check for telephony internal use only. The
13319 * caller need to take care of the permission check.
13320 */
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013321 private boolean isSatelliteProvisioned(int subId) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013322 if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
13323 if (mSubscriptionController == null) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013324 loge("isSatelliteProvisioned mSubscriptionController is null");
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013325 return false;
13326 }
13327
13328 String strResult = mSubscriptionController.getSubscriptionProperty(
13329 subId, SubscriptionManager.SATELLITE_ENABLED);
13330 if (strResult != null) {
13331 int intResult = Integer.parseInt(strResult);
13332 return (intResult == 1) ? true : false;
13333 }
13334 } else {
13335 //TODO (b/267826133): check via SatelliteController
13336 }
13337 return false;
13338 }
13339
13340 /**
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013341 * Set satellite provisioned for a subscription or the device.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013342 *
13343 * The permission {@link android.Manifest.permission#MODIFY_PHONE_STATE} will be enforced by
13344 * {@link SubscriptionController} when setting satellite enabled for an active subscription.
13345 * Otherwise, {@link android.Manifest.permission#SATELLITE_COMMUNICATION} will be enforced.
13346 */
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013347 private void setSatelliteProvisioned(int subId, boolean isEnabled) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013348 if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
13349 if (mSubscriptionController == null) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013350 loge("setSatelliteProvisioned mSubscriptionController is null");
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013351 return;
13352 }
13353 mSubscriptionController.setSubscriptionProperty(
13354 subId, SubscriptionManager.SATELLITE_ENABLED, isEnabled ? "1" : "0");
13355 } else {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013356 //TODO (b/267826133): set via SatelliteController
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013357 }
13358 }
13359
13360 private int getValidSatelliteSubId(int subId) {
13361 if (mSubscriptionController == null) {
13362 loge("getValidSatelliteSubId mSubscriptionController is null. "
13363 + "Use DEFAULT_SUBSCRIPTION_ID for subId=" + subId);
13364 return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
13365 }
13366 final long identity = Binder.clearCallingIdentity();
13367 try {
13368 Context context = getDefaultPhone().getContext();
13369 if (mSubscriptionController.isActiveSubId(
13370 subId, context.getOpPackageName(), context.getAttributionTag())) {
13371 return subId;
13372 }
13373 } finally {
13374 Binder.restoreCallingIdentity(identity);
13375 }
13376 if (DBG) log("getValidSatelliteSubId: use DEFAULT_SUBSCRIPTION_ID for subId=" + subId);
13377 return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
13378 }
13379
13380 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013381 * If we have not successfully queried the satellite modem for its satellite service support,
13382 * we will retry the query one more time. Otherwise, we will return the queried result.
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013383 */
13384 private boolean isSatelliteSupported() {
13385 synchronized (mIsSatelliteSupportedLock) {
13386 if (mIsSatelliteSupported != null) {
13387 /* We have already successfully queried the satellite modem. */
13388 return mIsSatelliteSupported;
13389 }
13390 }
13391 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013392 * We have not successfully checked whether the modem supports satellite service.
13393 * Thus, we need to retry it now.
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013394 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013395 requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
13396 mSatelliteSupportedReceiver);
13397 return false;
13398 }
13399
13400 /**
13401 * Get the {@link SatelliteManager.SatelliteError} from the provided result.
13402 * @param ar AsyncResult used to determine the error code.
13403 * @param caller The satellite request.
13404 * @param checkResult Whether to check if the result exists.
13405 * @return The {@link SatelliteManager.SatelliteError} error code from the request.
13406 */
13407 @SatelliteManager.SatelliteError private int getSatelliteError(@NonNull AsyncResult ar,
13408 @NonNull String caller, boolean checkResult) {
13409 int errorCode;
13410 if (ar.exception == null) {
13411 errorCode = SatelliteManager.SATELLITE_ERROR_NONE;
13412 if (checkResult && ar.result == null) {
13413 loge(caller + ": result is null");
13414 errorCode = SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
13415 }
13416 } else {
13417 errorCode = SatelliteManager.SATELLITE_ERROR;
13418 if (ar.exception instanceof CommandException) {
13419 CommandException.Error error =
13420 ((CommandException) (ar.exception)).getCommandError();
13421 errorCode = RILUtils.convertToSatelliteError(error);
13422 loge(caller + " CommandException: " + ar.exception);
13423 } else {
13424 loge(caller + " unknown exception: " + ar.exception);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013425 }
13426 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013427 log(caller + " error: " + errorCode);
13428 return errorCode;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013429 }
13430
13431 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000013432 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
13433 *
13434 * <p>This method behaves in one of the following ways:
13435 * <ul>
13436 * <li>return true : if the calling package has the appop permission {@link
13437 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
13438 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
13439 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
13440 * Owner device identifier access check, or the calling package has carrier privileges</>
13441 * <li>throw SecurityException: if the caller does not meet any of the requirements.
13442 * </ul>
13443 */
13444 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
13445 String callingPackage, @Nullable String callingFeatureId, String message) {
13446 for (Phone phone : PhoneFactory.getPhones()) {
13447 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
13448 phone.getSubId(), callingPackage, callingFeatureId, message)) {
13449 return true;
13450 }
13451 }
13452 return false;
13453 }
arunvoddud7401012022-12-15 16:08:12 +000013454
13455 /**
Jack Yufa8ed012023-02-11 15:42:28 -080013456 * @return The subscription manager service instance.
13457 */
13458 public SubscriptionManagerService getSubscriptionManagerService() {
13459 return SubscriptionManagerService.getInstance();
13460 }
13461
13462 /**
arunvoddud7401012022-12-15 16:08:12 +000013463 * Class binds the consumer[callback] and carrierId.
13464 */
13465 private static class CallerCallbackInfo {
13466 private final Consumer<Integer> mConsumer;
13467 private final int mCarrierId;
13468
13469 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
13470 mConsumer = consumer;
13471 mCarrierId = carrierId;
13472 }
13473
13474 public Consumer<Integer> getConsumer() {
13475 return mConsumer;
13476 }
13477
13478 public int getCarrierId() {
13479 return mCarrierId;
13480 }
13481 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013482
13483 private static SatelliteDatagram[] convertToSatelliteDatagramArray(byte[][] datagrams) {
13484 // Convert 2D byte array into SatelliteDatagramArray.
13485 SatelliteDatagram[] satelliteDatagramArray =
13486 new SatelliteDatagram[datagrams.length];
13487 for (int i = 0; i < datagrams.length; i++) {
13488 satelliteDatagramArray[i] = new SatelliteDatagram(datagrams[i]);
13489 }
13490 return satelliteDatagramArray;
13491 }
Jack Yufa8ed012023-02-11 15:42:28 -080013492}