blob: 821b0945fcc931a6ff069f05c5ca486765c8647d [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000020import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080021import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Hall Liud892bec2018-11-30 14:51:45 -080022
Shuo Qianccbaf742021-02-22 18:32:21 -080023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
24import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070025import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000027import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070028
Brad Ebinger34c09a52021-02-17 23:23:21 +000029import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080030import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080031import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070032import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000033import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080034import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080036import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070037import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000038import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080039import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000040import android.compat.annotation.ChangeId;
41import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070042import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070043import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.content.Context;
45import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070046import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070047import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070048import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.net.Uri;
50import android.os.AsyncResult;
51import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080052import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.Bundle;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080054import android.os.CancellationSignal;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070056import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080057import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080058import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import android.os.Looper;
60import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070061import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080062import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070063import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070064import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080065import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080066import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070067import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070068import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080069import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070071import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070072import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070073import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070074import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080075import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070076import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000077import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090078import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080079import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080080import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070081import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080082import android.telephony.AccessNetworkConstants;
83import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070084import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070085import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080086import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070087import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080088import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070089import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080090import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -060091import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -070092import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080093import android.telephony.CellIdentityCdma;
94import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070096import android.telephony.CellInfoGsm;
97import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070098import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080099import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700100import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700101import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700102import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800103import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700104import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800105import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700106import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800107import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800108import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700109import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800110import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800112import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800113import android.telephony.SignalStrengthUpdateRequest;
114import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800115import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800117import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700118import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700119import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800120import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800121import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800122import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800123import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000124import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000125import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000126import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700127import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700128import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800129import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800130import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700131import android.telephony.gba.GbaAuthRequest;
132import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700133import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800134import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000135import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000136import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700137import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000138import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700139import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800140import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700141import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800142import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700143import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000144import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700145import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800146import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800147import android.telephony.ims.stub.ImsRegistrationImplBase;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800148import android.telephony.satellite.ISatelliteDatagramCallback;
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +0000149import android.telephony.satellite.ISatelliteDatagramReceiverAck;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800150import android.telephony.satellite.ISatellitePositionUpdateCallback;
151import android.telephony.satellite.ISatelliteProvisionStateCallback;
152import android.telephony.satellite.ISatelliteStateCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800153import android.telephony.satellite.PointingInfo;
Sarah Chin503828c2023-02-01 23:54:20 -0800154import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000155import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800156import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800157import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800158import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800160import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700161import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800163import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800164
Andrew Lee312e8172014-10-23 17:01:36 -0700165import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800166import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800167import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800168import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800169import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700170import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700171import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700172import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800173import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800174import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700175import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700176import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800177import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700178import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800179import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800180import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800181import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700182import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000183import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700184import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800185import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800187import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800188import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800189import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700190import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700191import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700192import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700194import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800195import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700196import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700197import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700198import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700199import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800200import com.android.internal.telephony.RILConstants;
Sarah Chineccfbd12023-01-20 19:00:35 -0800201import com.android.internal.telephony.RILUtils;
Daniel Bright94f43662021-03-01 14:43:40 -0800202import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700203import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000204import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700205import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700206import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800207import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800208import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800209import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700210import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000211import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800212import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700213import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800214import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700215import com.android.internal.telephony.imsphone.ImsPhone;
216import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000217import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800218import com.android.internal.telephony.metrics.TelephonyMetrics;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800219import com.android.internal.telephony.satellite.SatelliteServiceController;
Jack Yu285100e2022-12-02 22:48:35 -0800220import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
221import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700222import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700223import com.android.internal.telephony.uicc.IccIoResult;
224import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800225import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700226import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800227import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700228import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000229import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800230import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000231import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800232import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000233import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700234import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700235import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800236import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800237import com.android.phone.callcomposer.CallComposerPictureManager;
238import com.android.phone.callcomposer.CallComposerPictureTransfer;
239import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700240import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700241import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000242import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700243import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800244import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700245import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700246import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800247import com.android.services.telephony.TelecomAccountRegistry;
248import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800249import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800250
Hall Liu82694d52020-12-11 18:22:04 -0800251import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700252import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800253import java.io.IOException;
254import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700255import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700256import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800257import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000258import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800259import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800260import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800261import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800262import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100263import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800264import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700265import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800266import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800267import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700268import java.util.UUID;
Sarah Chineccfbd12023-01-20 19:00:35 -0800269import java.util.concurrent.ConcurrentHashMap;
Hall Liu82694d52020-12-11 18:22:04 -0800270import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800271import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800272import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700273
274/**
275 * Implementation of the ITelephony interface.
276 */
Santos Cordon117fee72014-05-16 17:56:12 -0700277public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700278 private static final String LOG_TAG = "PhoneInterfaceManager";
279 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
280 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800281 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700282
283 // Message codes used with mMainThreadHandler
284 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700285 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
286 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700287 private static final int CMD_OPEN_CHANNEL = 9;
288 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
289 private static final int CMD_CLOSE_CHANNEL = 11;
290 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800291 private static final int CMD_NV_READ_ITEM = 13;
292 private static final int EVENT_NV_READ_ITEM_DONE = 14;
293 private static final int CMD_NV_WRITE_ITEM = 15;
294 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
295 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
296 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700297 private static final int CMD_RESET_MODEM_CONFIG = 19;
298 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800299 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
300 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800301 private static final int CMD_SEND_ENVELOPE = 25;
302 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000303 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
304 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700305 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
306 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
307 private static final int CMD_EXCHANGE_SIM_IO = 31;
308 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800309 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
310 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700311 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
312 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700313 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
314 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700315 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
316 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
317 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
318 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700319 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
320 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
321 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
322 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700323 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800324 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
325 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000326 private static final int CMD_SWITCH_SLOTS = 50;
327 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700328 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
329 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
330 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
331 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
332 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
333 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
334 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
335 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700336 private static final int CMD_GET_ALL_CELL_INFO = 60;
337 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
338 private static final int CMD_GET_CELL_LOCATION = 62;
339 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700340 private static final int CMD_MODEM_REBOOT = 64;
341 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700342 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
343 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800344 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
345 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700346 private static final int CMD_GET_MODEM_STATUS = 70;
347 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700348 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
349 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700350 private static final int CMD_ERASE_MODEM_CONFIG = 74;
351 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800352 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
353 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
354 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
355 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800356 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
357 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800358 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800359 private static final int CMD_GET_CALL_FORWARDING = 83;
360 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
361 private static final int CMD_SET_CALL_FORWARDING = 85;
362 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
363 private static final int CMD_GET_CALL_WAITING = 87;
364 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
365 private static final int CMD_SET_CALL_WAITING = 89;
366 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700367 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
368 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
369 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
370 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700371 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
372 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800373 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
374 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800375 private static final int CMD_SET_DATA_THROTTLING = 99;
376 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800377 private static final int CMD_SET_SIM_POWER = 101;
378 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800379 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
380 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
381 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
382 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800383 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
384 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000385 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800386 private static final int CMD_GET_SLICING_CONFIG = 110;
387 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800388 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700389 private static final int CMD_ENABLE_VONR = 113;
390 private static final int EVENT_ENABLE_VONR_DONE = 114;
391 private static final int CMD_IS_VONR_ENABLED = 115;
392 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700393 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
394 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Sarah Chineccfbd12023-01-20 19:00:35 -0800395 private static final int CMD_START_SATELLITE_POSITION_UPDATES = 119;
396 private static final int EVENT_START_SATELLITE_POSITION_UPDATES_DONE = 120;
397 private static final int CMD_STOP_SATELLITE_POSITION_UPDATES = 121;
398 private static final int EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE = 122;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +0000399 private static final int CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG = 123;
400 private static final int EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE = 124;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800401 private static final int CMD_PROVISION_SATELLITE_SERVICE = 125;
402 private static final int EVENT_PROVISION_SATELLITE_SERVICE_DONE = 126;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -0800403 private static final int CMD_DEPROVISION_SATELLITE_SERVICE = 127;
404 private static final int EVENT_DEPROVISION_SATELLITE_SERVICE_DONE = 128;
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800405 private static final int CMD_SET_SATELLITE_ENABLED = 129;
406 private static final int EVENT_SET_SATELLITE_ENABLED_DONE = 130;
407 private static final int CMD_IS_SATELLITE_ENABLED = 131;
408 private static final int EVENT_IS_SATELLITE_ENABLED_DONE = 132;
409 private static final int CMD_IS_SATELLITE_SUPPORTED = 133;
410 private static final int EVENT_IS_SATELLITE_SUPPORTED_DONE = 134;
411 private static final int CMD_GET_SATELLITE_CAPABILITIES = 135;
412 private static final int EVENT_GET_SATELLITE_CAPABILITIES_DONE = 136;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000413 private static final int CMD_POLL_PENDING_SATELLITE_DATAGRAMS = 137;
414 private static final int EVENT_POLL_PENDING_SATELLITE_DATAGRAMS_DONE = 138;
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +0000415 private static final int CMD_SEND_SATELLITE_DATAGRAM = 139;
416 private static final int EVENT_SEND_SATELLITE_DATAGRAM_DONE = 140;
Sarah Chindf715ec2023-02-13 13:46:24 -0800417 private static final int CMD_IS_SATELLITE_COMMUNICATION_ALLOWED = 141;
418 private static final int EVENT_IS_SATELLITE_COMMUNICATION_ALLOWED_DONE = 142;
419 private static final int CMD_GET_TIME_SATELLITE_NEXT_VISIBLE = 143;
420 private static final int EVENT_GET_TIME_SATELLITE_NEXT_VISIBLE_DONE = 144;
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800421 // Parameters of select command.
422 private static final int SELECT_COMMAND = 0xA4;
423 private static final int SELECT_P1 = 0x04;
424 private static final int SELECT_P2 = 0;
425 private static final int SELECT_P3 = 0x10;
426
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000427 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
428 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
429
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700430 /** The singleton instance. */
431 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800432 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700433
Sarah Chin4beb2b72023-02-14 14:47:54 -0800434 private final PhoneGlobals mApp;
435 private final CallManager mCM;
436 private final ImsResolver mImsResolver;
437 private final SatelliteServiceController mSatelliteServiceController;
438 private final UserManager mUserManager;
439 private final AppOpsManager mAppOps;
440 private final MainThreadHandler mMainThreadHandler;
Jack Yue37dd262022-12-16 11:53:37 -0800441 private final SubscriptionController mSubscriptionController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800442 private final SharedPreferences mTelephonySharedPreferences;
443 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800444 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445
Peter Wangdafb9ac2020-01-15 14:13:38 -0800446 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800447 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800448 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
449
Sarah Chin4beb2b72023-02-14 14:47:54 -0800450 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800451
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800452 /**
453 * Map key: subId, value: callback to get error code of the provision request.
454 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800455 private final ConcurrentHashMap<Integer, Consumer<Integer>> mSatelliteProvisionCallbacks =
Sarah Chineccfbd12023-01-20 19:00:35 -0800456 new ConcurrentHashMap<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800457 /**
458 * Map key: subId, value: SatellitePositionUpdateHandler to notify registrants.
459 */
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800460 private final ConcurrentHashMap<Integer, SatellitePositionUpdateHandler>
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800461 mSatellitePositionUpdateHandlers = new ConcurrentHashMap<>();
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800462 /**
463 * Map key: subId, value: SatelliteProvisionStateChangedHandler to notify registrants.
464 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800465 private final ConcurrentHashMap<Integer, SatelliteProvisionStateChangedHandler>
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800466 mSatelliteProvisionStateChangedHandlers = new ConcurrentHashMap<>();
467
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800468 private Boolean mIsSatelliteSupported = null;
469 private final Object mIsSatelliteSupportedLock = new Object();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800470 private final ResultReceiver mSatelliteSupportedReceiver;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800471 /**
472 * {@code true} to use the vendor satellite service and {@code false} to use the HAL.
473 */
474 private final boolean mIsSatelliteServiceSupported = false;
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800475
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000476 /**
477 * Map key: subId, value: SatelliteStateChangeHandler to notify registrants.
478 */
479 private ConcurrentHashMap<Integer, SatelliteStateListenerHandler>
480 mSatelliteStateListenerHandlers = new ConcurrentHashMap<>();
481
482 /**
483 * Map key: subId, value: SatelliteDatagramListenerHandler to notify registrants.
484 */
485 private ConcurrentHashMap<Integer, SatelliteDatagramListenerHandler>
486 mSatelliteDatagramListenerHandlers = new ConcurrentHashMap<>();
487
Derek Tan97ebb422014-09-05 16:55:38 -0700488 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
489 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800490 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800491 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700492
Michelecea4cf22018-12-21 15:00:11 -0800493 // String to store multi SIM allowed
494 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
495
Derek Tan740e1672017-06-27 14:56:27 -0700496 // The AID of ISD-R.
497 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
498
yinxub1bed742017-04-17 11:45:04 -0700499 private NetworkScanRequestTracker mNetworkScanRequestTracker;
500
David Kelly5e06a7f2018-03-12 14:10:59 +0000501 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
502 private static final int MANUFACTURER_CODE_LENGTH = 8;
503
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800504 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800505 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800506
Sarah Chin2ec39f62022-08-31 17:03:26 -0700507 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
508 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
509
Derek Tan89e89d42014-07-08 17:00:10 -0700510 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700511 * Experiment flag to enable erase modem config on reset network, default value is false
512 */
513 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
514 "reset_network_erase_modem_config_enabled";
515
Rambo Wang0f050d82021-02-12 11:43:36 -0800516 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800517
Gary Jian76280a42022-12-07 16:18:33 +0800518 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
519
sandeepjsb6c87872021-09-27 15:34:44 +0000520 /**
521 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
522 * one ICCID active at the same time.
523 * Apps should use below API signatures if targeting SDK is T and beyond.
524 *
525 * @hide
526 */
527 @ChangeId
528 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
529 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800530
Naina Nallurid63128d2019-09-17 14:10:30 -0700531 /**
Chen Xu540470b2021-12-14 17:15:47 -0800532 * Apps targeting on Android T and beyond will get exception whenever icc close channel
533 * operation fails.
534 */
535 @ChangeId
536 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
537 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
538
539 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700540 * A request object to use for transmitting data to an ICC.
541 */
542 private static final class IccAPDUArgument {
543 public int channel, cla, command, p1, p2, p3;
544 public String data;
545
546 public IccAPDUArgument(int channel, int cla, int command,
547 int p1, int p2, int p3, String data) {
548 this.channel = channel;
549 this.cla = cla;
550 this.command = command;
551 this.p1 = p1;
552 this.p2 = p2;
553 this.p3 = p3;
554 this.data = data;
555 }
556 }
557
558 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700559 * A request object to use for transmitting data to an ICC.
560 */
561 private static final class ManualNetworkSelectionArgument {
562 public OperatorInfo operatorInfo;
563 public boolean persistSelection;
564
565 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
566 this.operatorInfo = operatorInfo;
567 this.persistSelection = persistSelection;
568 }
569 }
570
Sarah Chin71b3a852022-09-28 15:54:19 -0700571 private static final class PurchasePremiumCapabilityArgument {
572 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700573 public @NonNull IIntegerConsumer callback;
574
575 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800576 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700577 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700578 this.callback = callback;
579 }
580 }
581
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800582 private static final class ProvisionSatelliteServiceArgument {
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800583 public @NonNull String token;
584 public @NonNull Consumer<Integer> callback;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800585 public int subId;
586
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800587 ProvisionSatelliteServiceArgument(String token, Consumer<Integer> callback, int subId) {
588 this.token = token;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800589 this.callback = callback;
590 this.subId = subId;
591 }
592 }
593
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +0000594 private static final class SendSatelliteDatagramArgument {
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +0000595 public long datagramId;
596
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +0000597 public @SatelliteManager.DatagramType int datagramType;
598 public @NonNull SatelliteDatagram datagram;
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +0000599
600 public boolean needFullScreenPointingUI;
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +0000601 public @NonNull ResultReceiver result;
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +0000602
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +0000603 SendSatelliteDatagramArgument(long datagramId,
604 @SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +0000605 SatelliteDatagram datagram, boolean needFullScreenPointingUI,
606 ResultReceiver result) {
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +0000607 this.datagramId = datagramId;
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +0000608 this.datagramType = datagramType;
609 this.datagram = datagram;
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +0000610 this.needFullScreenPointingUI = needFullScreenPointingUI;
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +0000611 this.result = result;
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +0000612 }
613 }
614
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800615 private static final class SatellitePositionUpdateArgument {
616 public @NonNull Consumer<Integer> errorCallback;
617 public @NonNull ISatellitePositionUpdateCallback callback;
618 public int subId;
619
620 SatellitePositionUpdateArgument(Consumer<Integer> errorCallback,
621 ISatellitePositionUpdateCallback callback, int subId) {
622 this.errorCallback = errorCallback;
623 this.callback = callback;
624 this.subId = subId;
625 }
626 }
627
Sarah Chineccfbd12023-01-20 19:00:35 -0800628 private static final class SatellitePositionUpdateHandler extends Handler {
Sarah Chin43457982023-02-15 17:50:38 -0800629 public static final int EVENT_POSITION_INFO_CHANGED = 1;
630 public static final int EVENT_DATAGRAM_TRANSFER_STATE_CHANGED = 2;
Sarah Chineccfbd12023-01-20 19:00:35 -0800631
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800632 private final ConcurrentHashMap<IBinder, ISatellitePositionUpdateCallback> mListeners;
633 SatellitePositionUpdateHandler(Looper looper) {
Sarah Chineccfbd12023-01-20 19:00:35 -0800634 super(looper);
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800635 mListeners = new ConcurrentHashMap<>();
636 }
637
638 public void addListener(ISatellitePositionUpdateCallback listener) {
639 mListeners.put(listener.asBinder(), listener);
640 }
641
642 public void removeListener(ISatellitePositionUpdateCallback listener) {
643 mListeners.remove(listener.asBinder());
644 }
645
646 public boolean hasListeners() {
647 return !mListeners.isEmpty();
Sarah Chineccfbd12023-01-20 19:00:35 -0800648 }
649
650 @Override
651 public void handleMessage(@NonNull Message msg) {
652 switch (msg.what) {
Sarah Chin43457982023-02-15 17:50:38 -0800653 case EVENT_POSITION_INFO_CHANGED: {
Sarah Chineccfbd12023-01-20 19:00:35 -0800654 AsyncResult ar = (AsyncResult) msg.obj;
655 PointingInfo pointingInfo = (PointingInfo) ar.result;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800656 mListeners.values().forEach(listener -> {
657 try {
Sarah Chin43457982023-02-15 17:50:38 -0800658 listener.onSatellitePositionChanged(pointingInfo);
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800659 } catch (RemoteException e) {
Sarah Chin43457982023-02-15 17:50:38 -0800660 log("EVENT_POSITION_INFO_CHANGED RemoteException: " + e);
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800661 }
662 });
Sarah Chineccfbd12023-01-20 19:00:35 -0800663 break;
664 }
Sarah Chin43457982023-02-15 17:50:38 -0800665 case EVENT_DATAGRAM_TRANSFER_STATE_CHANGED: {
Sarah Chineccfbd12023-01-20 19:00:35 -0800666 AsyncResult ar = (AsyncResult) msg.obj;
Sarah Chin43457982023-02-15 17:50:38 -0800667 int result = (int) ar.result;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800668 mListeners.values().forEach(listener -> {
669 try {
Sarah Chin43457982023-02-15 17:50:38 -0800670 // TODO: process and return the rest of the values correctly
671 listener.onDatagramTransferStateChanged(result, 0, 0, 0);
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800672 } catch (RemoteException e) {
Sarah Chin43457982023-02-15 17:50:38 -0800673 log("EVENT_DATAGRAM_TRANSFER_STATE_CHANGED RemoteException: " + e);
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800674 }
675 });
Sarah Chineccfbd12023-01-20 19:00:35 -0800676 break;
677 }
678 default:
679 loge("SatellitePositionUpdateHandler unknown event: " + msg.what);
680 }
681 }
682 }
683
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800684 private static final class SatelliteProvisionStateChangedHandler extends Handler {
685 public static final int EVENT_PROVISION_STATE_CHANGED = 1;
686
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800687 private final ConcurrentHashMap<IBinder, ISatelliteProvisionStateCallback> mListeners;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800688 private final int mSubId;
689
690 SatelliteProvisionStateChangedHandler(Looper looper, int subId) {
691 super(looper);
692 mListeners = new ConcurrentHashMap<>();
693 mSubId = subId;
694 }
695
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800696 public void addListener(ISatelliteProvisionStateCallback listener) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800697 mListeners.put(listener.asBinder(), listener);
698 }
699
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800700 public void removeListener(ISatelliteProvisionStateCallback listener) {
701 mListeners.remove(listener.asBinder());
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800702 }
703
704 @Override
705 public void handleMessage(@NonNull Message msg) {
706 switch (msg.what) {
707 case EVENT_PROVISION_STATE_CHANGED: {
708 AsyncResult ar = (AsyncResult) msg.obj;
709 boolean provisioned = (boolean) ar.userObj;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800710 log("Received EVENT_PROVISION_STATE_CHANGED for subId=" + mSubId
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800711 + ", provisioned=" + provisioned);
712 mListeners.values().forEach(listener -> {
713 try {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -0800714 listener.onSatelliteProvisionStateChanged(provisioned);
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800715 } catch (RemoteException e) {
716 log("EVENT_PROVISION_STATE_CHANGED RemoteException: " + e);
717 }
718 });
719
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800720 setSatelliteProvisioned(provisioned);
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800721 /**
722 * TODO: Take bugreport if provisioned is true and user did not initiate the
723 * provision procedure for the corresponding subscription.
724 */
725 break;
726 }
727 default:
728 loge("SatelliteProvisionStateChangedHandler unknown event: " + msg.what);
729 }
730 }
731
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800732 private void setSatelliteProvisioned(boolean isProvisioned) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800733 if (mSubId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
734 SubscriptionManager.setSubscriptionProperty(
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800735 mSubId, SubscriptionManager.SATELLITE_ENABLED, isProvisioned ? "1" : "0");
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800736 } else {
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800737 //TODO (b/267826133): set via SatelliteController.
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800738 }
739 }
740 }
741
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000742 private static final class SatelliteStateListenerHandler extends Handler {
743 public static final int EVENT_SATELLITE_MODEM_STATE_CHANGE = 1;
Aishwarya Mallampati224317a2023-02-13 22:09:30 +0000744 public static final int EVENT_PENDING_DATAGRAM_COUNT = 2;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000745
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800746 private final ConcurrentHashMap<IBinder, ISatelliteStateCallback> mListeners;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000747 private final int mSubId;
748
749 SatelliteStateListenerHandler(Looper looper, int subId) {
750 super(looper);
751 mSubId = subId;
752 mListeners = new ConcurrentHashMap<>();
753 }
754
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800755 public void addListener(ISatelliteStateCallback listener) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000756 mListeners.put(listener.asBinder(), listener);
757 }
758
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800759 public void removeListener(ISatelliteStateCallback listener) {
760 mListeners.remove(listener.asBinder());
761 }
762
763 public boolean hasListeners() {
764 return !mListeners.isEmpty();
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000765 }
766
767 @Override
768 public void handleMessage(@NonNull Message msg) {
769 switch (msg.what) {
770 case EVENT_SATELLITE_MODEM_STATE_CHANGE : {
771 AsyncResult ar = (AsyncResult) msg.obj;
772 int state = (int) ar.result;
773 log("Received EVENT_SATELLITE_MODEM_STATE_CHANGE for subId=" + mSubId
774 + ", state=" + state);
775 mListeners.values().forEach(listener -> {
776 try {
Sarah Chin43457982023-02-15 17:50:38 -0800777 listener.onSatelliteModemStateChanged(state);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000778 } catch (RemoteException e) {
779 log("EVENT_SATELLITE_MODEM_STATE_CHANGE RemoteException: " + e);
780 }
781 });
782 break;
783 }
Aishwarya Mallampati224317a2023-02-13 22:09:30 +0000784 case EVENT_PENDING_DATAGRAM_COUNT: {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000785 AsyncResult ar = (AsyncResult) msg.obj;
786 int count = (int) ar.result;
Aishwarya Mallampati224317a2023-02-13 22:09:30 +0000787 log("Received EVENT_PENDING_DATAGRAM_COUNT for subId=" + mSubId
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000788 + ", count=" + count);
789 mListeners.values().forEach(listener -> {
790 try {
Aishwarya Mallampati224317a2023-02-13 22:09:30 +0000791 listener.onPendingDatagramCount(count);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000792 } catch (RemoteException e) {
Aishwarya Mallampati224317a2023-02-13 22:09:30 +0000793 log("EVENT_PENDING_DATAGRAM_COUNT RemoteException: " + e);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000794 }
795 });
796 break;
797 }
798 default:
799 loge("SatelliteStateListenerHandler unknown event: " + msg.what);
800 }
801 }
802 }
803
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +0000804 /** Callback used by datagram receiver app to send ack back to Telephony. */
805 private static final ISatelliteDatagramReceiverAck.Stub mDatagramReceiverAck =
806 new ISatelliteDatagramReceiverAck.Stub() {
807 /**
808 * This callback will be used by datagram receiver app to send ack back to
809 * Telephony. If the callback is not received within five minutes,
810 * then Telephony will resend the datagram again.
811 *
812 * @param datagramId An id that uniquely identifies datagram
813 * received by satellite datagram receiver app.
814 * This should match with datagramId passed in
815 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(
816 * long, SatelliteDatagram, int, ISatelliteDatagramReceiverAck)}.
817 * Upon receiving the ack, Telephony will remove the datagram from
818 * the persistent memory.
819 */
820 public void acknowledgeSatelliteDatagramReceived(long datagramId) {
821
822 }
823 };
824
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000825 private static final class SatelliteDatagramListenerHandler extends Handler {
826 public static final int EVENT_SATELLITE_DATAGRAMS_RECEIVED = 1;
827
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800828 private final ConcurrentHashMap<IBinder, ISatelliteDatagramCallback> mListeners;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000829 private final int mSubId;
830
831 SatelliteDatagramListenerHandler(Looper looper, int subId) {
832 super(looper);
833 mSubId = subId;
834 mListeners = new ConcurrentHashMap<>();
835 }
836
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800837 public void addListener(ISatelliteDatagramCallback listener) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000838 mListeners.put(listener.asBinder(), listener);
839 }
840
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800841 public void removeListener(ISatelliteDatagramCallback listener) {
842 mListeners.remove(listener.asBinder());
843 }
844
845 public boolean hasListeners() {
846 return !mListeners.isEmpty();
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000847 }
848
849 @Override
850 public void handleMessage(@NonNull Message msg) {
851 switch (msg.what) {
Sarah Chin43457982023-02-15 17:50:38 -0800852 case EVENT_SATELLITE_DATAGRAMS_RECEIVED: {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000853 AsyncResult ar = (AsyncResult) msg.obj;
Sarah Chin43457982023-02-15 17:50:38 -0800854 Pair<SatelliteDatagram[], Integer> result =
855 (Pair<SatelliteDatagram[], Integer>) ar.result;
856 SatelliteDatagram[] satelliteDatagrams = result.first;
857 int pendingCount = result.second;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000858
859 log("Received EVENT_SATELLITE_DATAGRAMS_RECEIVED for subId=" + mSubId);
860 mListeners.values().forEach(listener -> {
861 try {
Sarah Chin43457982023-02-15 17:50:38 -0800862 for (int i = 0; i < satelliteDatagrams.length; i++) {
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +0000863 // TODO (b/269637555): wait for ack and retry after 5mins
Sarah Chin43457982023-02-15 17:50:38 -0800864 listener.onSatelliteDatagramReceived(
865 // TODO: create a new datagramId every time
866 i, satelliteDatagrams[i], pendingCount,
867 // TODO: create a new instance of ack that will resend
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +0000868 mDatagramReceiverAck);
869 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000870 } catch (RemoteException e) {
871 log("EVENT_SATELLITE_DATAGRAMS_RECEIVED RemoteException: " + e);
872 }
873 });
874 break;
875 }
876 default:
877 loge("SatelliteDatagramListenerHandler unknown event: " + msg.what);
878 }
879 }
880 }
881
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700882 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700883 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
884 * request after sending. The main thread will notify the request when it is complete.
885 */
886 private static final class MainThreadRequest {
887 /** The argument to use for the request */
888 public Object argument;
889 /** The result of the request that is run on the main thread */
890 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800891 // The subscriber id that this request applies to. Defaults to
892 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
893 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700894
Nathan Harold92bed182018-10-12 18:16:49 -0700895 // In cases where subId is unavailable, the caller needs to specify the phone.
896 public Phone phone;
897
vagdeviaf9a5b92018-08-15 16:01:53 -0700898 public WorkSource workSource;
899
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700900 public MainThreadRequest(Object argument) {
901 this.argument = argument;
902 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800903
Nathan Harold92bed182018-10-12 18:16:49 -0700904 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
905 this.argument = argument;
906 if (phone != null) {
907 this.phone = phone;
908 }
909 this.workSource = workSource;
910 }
911
vagdeviaf9a5b92018-08-15 16:01:53 -0700912 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800913 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800914 if (subId != null) {
915 this.subId = subId;
916 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700917 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800918 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700919 }
920
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800921 private static final class IncomingThirdPartyCallArgs {
922 public final ComponentName component;
923 public final String callId;
924 public final String callerDisplayName;
925
926 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
927 String callerDisplayName) {
928 this.component = component;
929 this.callId = callId;
930 this.callerDisplayName = callerDisplayName;
931 }
932 }
933
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700934 /**
935 * A handler that processes messages on the main thread in the phone process. Since many
936 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
937 * inbound binder threads to the main thread in the phone process. The Binder thread
938 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
939 * on, which will be notified when the operation completes and will contain the result of the
940 * request.
941 *
942 * <p>If a MainThreadRequest object is provided in the msg.obj field,
943 * note that request.result must be set to something non-null for the calling thread to
944 * unblock.
945 */
946 private final class MainThreadHandler extends Handler {
947 @Override
948 public void handleMessage(Message msg) {
949 MainThreadRequest request;
950 Message onCompleted;
951 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000952 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700953 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800954 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700955
956 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700957 case CMD_HANDLE_USSD_REQUEST: {
958 request = (MainThreadRequest) msg.obj;
959 final Phone phone = getPhoneFromRequest(request);
960 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800961 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700962 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700963
Pengquan Menga1bb6272018-09-06 09:59:22 -0700964 if (!isUssdApiAllowed(request.subId)) {
965 // Carrier does not support use of this API, return failure.
966 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
967 UssdResponse response = new UssdResponse(ussdRequest, null);
968 Bundle returnData = new Bundle();
969 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
970 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700971
Pengquan Menga1bb6272018-09-06 09:59:22 -0700972 request.result = true;
973 notifyRequester(request);
974 return;
975 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700976
Pengquan Menga1bb6272018-09-06 09:59:22 -0700977 try {
978 request.result = phone != null
979 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
980 } catch (CallStateException cse) {
981 request.result = false;
982 }
983 // Wake up the requesting thread
984 notifyRequester(request);
985 break;
pkanwar32d516d2016-10-14 19:37:38 -0700986 }
987
Yorke Lee716f67e2015-06-17 15:39:16 -0700988 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700989 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700990 final Phone phone = getPhoneFromRequest(request);
991 request.result = phone != null ?
992 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
993 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700994 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700995 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700996 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700997 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700998
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700999 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -07001000 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001001 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001002 uiccPort = getUiccPortFromRequest(request);
1003 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001004 loge("iccTransmitApduLogicalChannel: 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 {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001008 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -08001009 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001010 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -08001011 iccArgument.channel, iccArgument.cla, iccArgument.command,
1012 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
1013 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001014 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001015 break;
1016
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001017 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -07001018 ar = (AsyncResult) msg.obj;
1019 request = (MainThreadRequest) ar.userObj;
1020 if (ar.exception == null && ar.result != null) {
1021 request.result = ar.result;
1022 } else {
Chen Xue9d737e2022-01-01 23:41:31 -08001023 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001024 if (ar.result == null) {
1025 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -08001026 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -07001027 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -08001028 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001029 } else {
1030 loge("iccTransmitApduLogicalChannel: Unknown exception");
1031 }
1032 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001033 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001034 break;
1035
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001036 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
1037 request = (MainThreadRequest) msg.obj;
1038 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001039 uiccPort = getUiccPortFromRequest(request);
1040 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001041 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -08001042 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001043 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001044 } else {
1045 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -08001046 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001047 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -08001048 iccArgument.cla, iccArgument.command, iccArgument.p1,
1049 iccArgument.p2,
1050 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001051 }
1052 break;
1053
1054 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
1055 ar = (AsyncResult) msg.obj;
1056 request = (MainThreadRequest) ar.userObj;
1057 if (ar.exception == null && ar.result != null) {
1058 request.result = ar.result;
1059 } else {
Chen Xue9d737e2022-01-01 23:41:31 -08001060 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001061 if (ar.result == null) {
1062 loge("iccTransmitApduBasicChannel: Empty response");
1063 } else if (ar.exception instanceof CommandException) {
1064 loge("iccTransmitApduBasicChannel: CommandException: " +
1065 ar.exception);
1066 } else {
1067 loge("iccTransmitApduBasicChannel: Unknown exception");
1068 }
1069 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001070 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001071 break;
1072
1073 case CMD_EXCHANGE_SIM_IO:
1074 request = (MainThreadRequest) msg.obj;
1075 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001076 uiccPort = getUiccPortFromRequest(request);
1077 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001078 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -08001079 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001080 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001081 } else {
1082 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
1083 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001084 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001085 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
1086 iccArgument.data, onCompleted);
1087 }
1088 break;
1089
1090 case EVENT_EXCHANGE_SIM_IO_DONE:
1091 ar = (AsyncResult) msg.obj;
1092 request = (MainThreadRequest) ar.userObj;
1093 if (ar.exception == null && ar.result != null) {
1094 request.result = ar.result;
1095 } else {
Chen Xue9d737e2022-01-01 23:41:31 -08001096 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001097 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001098 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001099 break;
1100
Derek Tan4d5e5c12014-02-04 11:54:58 -08001101 case CMD_SEND_ENVELOPE:
1102 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001103 uiccPort = getUiccPortFromRequest(request);
1104 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001105 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -08001106 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001107 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001108 } else {
1109 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -08001110 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001111 }
Derek Tan4d5e5c12014-02-04 11:54:58 -08001112 break;
1113
1114 case EVENT_SEND_ENVELOPE_DONE:
1115 ar = (AsyncResult) msg.obj;
1116 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -07001117 if (ar.exception == null && ar.result != null) {
1118 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -08001119 } else {
Chen Xue9d737e2022-01-01 23:41:31 -08001120 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -07001121 if (ar.result == null) {
1122 loge("sendEnvelopeWithStatus: Empty response");
1123 } else if (ar.exception instanceof CommandException) {
1124 loge("sendEnvelopeWithStatus: CommandException: " +
1125 ar.exception);
1126 } else {
1127 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
1128 }
Derek Tan4d5e5c12014-02-04 11:54:58 -08001129 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001130 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -08001131 break;
1132
Shishir Agrawal566b7612013-10-28 14:41:00 -07001133 case CMD_OPEN_CHANNEL:
1134 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001135 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -08001136 IccLogicalChannelRequest openChannelRequest =
1137 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001138 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001139 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -08001140 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -08001141 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001142 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001143 } else {
1144 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -08001145 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
1146 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001147 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001148 break;
1149
1150 case EVENT_OPEN_CHANNEL_DONE:
1151 ar = (AsyncResult) msg.obj;
1152 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001153 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -07001154 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001155 int[] result = (int[]) ar.result;
1156 int channelId = result[0];
1157 byte[] selectResponse = null;
1158 if (result.length > 1) {
1159 selectResponse = new byte[result.length - 1];
1160 for (int i = 1; i < result.length; ++i) {
1161 selectResponse[i - 1] = (byte) result[i];
1162 }
1163 }
1164 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -08001165 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -08001166
1167 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -07001168 if (uiccPort == null) {
1169 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
1170 } else {
1171 IccLogicalChannelRequest channelRequest =
1172 (IccLogicalChannelRequest) request.argument;
1173 channelRequest.channel = channelId;
1174 uiccPort.onLogicalChannelOpened(channelRequest);
1175 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001176 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -07001177 if (ar.result == null) {
1178 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -07001179 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001180 if (ar.exception != null) {
1181 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
1182 }
1183
Shishir Agrawal527e8bf2014-08-25 08:54:56 -07001184 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -07001185 if (ar.exception instanceof CommandException) {
1186 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -08001187 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -07001188 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -07001189 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -07001190 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -07001191 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001192 }
1193 }
1194 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -08001195 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001196 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -07001197 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001198 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001199 break;
1200
1201 case CMD_CLOSE_CHANNEL:
1202 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001203 uiccPort = getUiccPortFromRequest(request);
1204 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001205 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -08001206 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001207 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -08001208 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001209 } else {
1210 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001211 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001212 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001213 break;
1214
1215 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -08001216 ar = (AsyncResult) msg.obj;
1217 request = (MainThreadRequest) ar.userObj;
1218 if (ar.exception == null) {
1219 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -08001220 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -07001221 if (uiccPort == null) {
1222 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
1223 } else {
1224 final int channelId = (Integer) request.argument;
1225 uiccPort.onLogicalChannelClosed(channelId);
1226 }
Chen Xu540470b2021-12-14 17:15:47 -08001227 } else {
1228 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -08001229 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -08001230 if (ar.exception instanceof CommandException) {
1231 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
1232 CommandException.Error error =
1233 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -08001234 if (error == CommandException.Error.INVALID_ARGUMENTS) {
1235 // should only throw exceptions from the binder threads.
1236 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -08001237 "iccCloseLogicalChannel: invalid argument ");
1238 }
1239 } else {
1240 loge("iccCloseLogicalChannel: Unknown exception");
1241 }
Chen Xua8f0dff2022-02-12 00:34:15 -08001242 request.result = (exception != null) ? exception :
1243 new IllegalStateException(
1244 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -08001245 }
1246 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001247 break;
1248
1249 case CMD_NV_READ_ITEM:
1250 request = (MainThreadRequest) msg.obj;
1251 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001252 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
1253 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -08001254 break;
1255
1256 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -07001257 ar = (AsyncResult) msg.obj;
1258 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -08001259 if (ar.exception == null && ar.result != null) {
1260 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -07001261 } else {
Jake Hambye994d462014-02-03 13:10:13 -08001262 request.result = "";
1263 if (ar.result == null) {
1264 loge("nvReadItem: Empty response");
1265 } else if (ar.exception instanceof CommandException) {
1266 loge("nvReadItem: CommandException: " +
1267 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001268 } else {
Jake Hambye994d462014-02-03 13:10:13 -08001269 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -07001270 }
1271 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001272 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001273 break;
1274
Jake Hambye994d462014-02-03 13:10:13 -08001275 case CMD_NV_WRITE_ITEM:
1276 request = (MainThreadRequest) msg.obj;
1277 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
1278 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001279 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -07001280 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -08001281 break;
1282
1283 case EVENT_NV_WRITE_ITEM_DONE:
1284 handleNullReturnEvent(msg, "nvWriteItem");
1285 break;
1286
1287 case CMD_NV_WRITE_CDMA_PRL:
1288 request = (MainThreadRequest) msg.obj;
1289 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001290 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -08001291 break;
1292
1293 case EVENT_NV_WRITE_CDMA_PRL_DONE:
1294 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
1295 break;
1296
chen xu6dac5ab2018-10-26 17:39:23 -07001297 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -08001298 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -07001299 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001300 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -08001301 break;
1302
chen xu6dac5ab2018-10-26 17:39:23 -07001303 case EVENT_RESET_MODEM_CONFIG_DONE:
1304 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -08001305 break;
1306
Sooraj Sasindran37444802020-08-11 10:40:43 -07001307 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
1308 request = (MainThreadRequest) msg.obj;
1309 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
1310 request);
1311 Phone phone = getPhoneFromRequest(request);
1312 if (phone != null) {
1313 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
1314 } else {
1315 loge("isNRDualConnectivityEnabled: No phone object");
1316 request.result = false;
1317 notifyRequester(request);
1318 }
1319 break;
1320 }
1321
1322 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
1323 ar = (AsyncResult) msg.obj;
1324 request = (MainThreadRequest) ar.userObj;
1325 if (ar.exception == null && ar.result != null) {
1326 request.result = ar.result;
1327 } else {
1328 // request.result must be set to something non-null
1329 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001330 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -07001331 request.result = ar.result;
1332 } else {
1333 request.result = false;
1334 }
1335 if (ar.result == null) {
1336 loge("isNRDualConnectivityEnabled: Empty response");
1337 } else if (ar.exception instanceof CommandException) {
1338 loge("isNRDualConnectivityEnabled: CommandException: "
1339 + ar.exception);
1340 } else {
1341 loge("isNRDualConnectivityEnabled: Unknown exception");
1342 }
1343 }
1344 notifyRequester(request);
1345 break;
1346
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001347 case CMD_IS_VONR_ENABLED: {
1348 request = (MainThreadRequest) msg.obj;
1349 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1350 request);
1351 Phone phone = getPhoneFromRequest(request);
1352 if (phone != null) {
1353 phone.isVoNrEnabled(onCompleted, request.workSource);
1354 } else {
1355 loge("isVoNrEnabled: No phone object");
1356 request.result = false;
1357 notifyRequester(request);
1358 }
1359 break;
1360 }
1361
1362 case EVENT_IS_VONR_ENABLED_DONE:
1363 ar = (AsyncResult) msg.obj;
1364 request = (MainThreadRequest) ar.userObj;
1365 if (ar.exception == null && ar.result != null) {
1366 request.result = ar.result;
1367 } else {
1368 // request.result must be set to something non-null
1369 // for the calling thread to unblock
1370 if (ar.result != null) {
1371 request.result = ar.result;
1372 } else {
1373 request.result = false;
1374 }
1375 if (ar.result == null) {
1376 loge("isVoNrEnabled: Empty response");
1377 } else if (ar.exception instanceof CommandException) {
1378 loge("isVoNrEnabled: CommandException: "
1379 + ar.exception);
1380 } else {
1381 loge("isVoNrEnabled: Unknown exception");
1382 }
1383 }
1384 notifyRequester(request);
1385 break;
1386
Sooraj Sasindran37444802020-08-11 10:40:43 -07001387 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1388 request = (MainThreadRequest) msg.obj;
1389 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1390 Phone phone = getPhoneFromRequest(request);
1391 if (phone != null) {
1392 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1393 request.workSource);
1394 } else {
1395 loge("enableNrDualConnectivity: No phone object");
1396 request.result =
1397 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1398 notifyRequester(request);
1399 }
1400 break;
1401 }
1402
1403 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1404 ar = (AsyncResult) msg.obj;
1405 request = (MainThreadRequest) ar.userObj;
1406 if (ar.exception == null) {
1407 request.result =
1408 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1409 } else {
1410 request.result =
1411 TelephonyManager
1412 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1413 if (ar.exception instanceof CommandException) {
1414 CommandException.Error error =
1415 ((CommandException) (ar.exception)).getCommandError();
1416 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1417 request.result =
1418 TelephonyManager
1419 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001420 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1421 request.result =
1422 TelephonyManager
1423 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001424 }
1425 loge("enableNrDualConnectivity" + ": CommandException: "
1426 + ar.exception);
1427 } else {
1428 loge("enableNrDualConnectivity" + ": Unknown exception");
1429 }
1430 }
1431 notifyRequester(request);
1432 break;
1433 }
1434
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001435 case CMD_ENABLE_VONR: {
1436 request = (MainThreadRequest) msg.obj;
1437 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1438 Phone phone = getPhoneFromRequest(request);
1439 if (phone != null) {
1440 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1441 request.workSource);
1442 } else {
1443 loge("setVoNrEnabled: No phone object");
1444 request.result =
1445 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1446 notifyRequester(request);
1447 }
1448 break;
1449 }
1450
1451 case EVENT_ENABLE_VONR_DONE: {
1452 ar = (AsyncResult) msg.obj;
1453 request = (MainThreadRequest) ar.userObj;
1454 if (ar.exception == null) {
1455 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1456 } else {
1457 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1458 if (ar.exception instanceof CommandException) {
1459 CommandException.Error error =
1460 ((CommandException) (ar.exception)).getCommandError();
1461 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1462 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1463 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1464 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1465 } else {
1466 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1467 }
1468 loge("setVoNrEnabled" + ": CommandException: "
1469 + ar.exception);
1470 } else {
1471 loge("setVoNrEnabled" + ": Unknown exception");
1472 }
1473 }
1474 notifyRequester(request);
1475 break;
1476 }
1477
SongFerngWang3ef3e072020-12-21 16:41:52 +08001478 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001479 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001480 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1481 request);
1482 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001483 break;
1484
SongFerngWang3ef3e072020-12-21 16:41:52 +08001485 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001486 ar = (AsyncResult) msg.obj;
1487 request = (MainThreadRequest) ar.userObj;
1488 if (ar.exception == null && ar.result != null) {
1489 request.result = ar.result; // Integer
1490 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301491 // request.result must be set to something non-null
1492 // for the calling thread to unblock
1493 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001494 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001495 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001496 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001497 loge("getAllowedNetworkTypesBitmask: CommandException: "
1498 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001499 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001500 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001501 }
1502 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001503 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001504 break;
1505
SongFerngWang3ef3e072020-12-21 16:41:52 +08001506 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001507 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001508 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1509 request);
1510 Pair<Integer, Long> reasonWithNetworkTypes =
1511 (Pair<Integer, Long>) request.argument;
1512 getPhoneFromRequest(request).setAllowedNetworkTypes(
1513 reasonWithNetworkTypes.first,
1514 reasonWithNetworkTypes.second,
1515 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001516 break;
1517
SongFerngWang3ef3e072020-12-21 16:41:52 +08001518 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1519 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001520 break;
1521
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001522 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1523 request = (MainThreadRequest)msg.obj;
1524 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001525 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001526 break;
1527
1528 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1529 ar = (AsyncResult)msg.obj;
1530 request = (MainThreadRequest)ar.userObj;
1531 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001532 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001533 break;
1534
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001535 case CMD_SET_VOICEMAIL_NUMBER:
1536 request = (MainThreadRequest) msg.obj;
1537 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1538 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001539 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1540 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001541 break;
1542
1543 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1544 handleNullReturnEvent(msg, "setVoicemailNumber");
1545 break;
1546
Stuart Scott54788802015-03-30 13:18:01 -07001547 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1548 request = (MainThreadRequest) msg.obj;
1549 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1550 request);
1551 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1552 break;
1553
1554 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1555 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1556 break;
1557
Shishir Agrawal302c8692015-06-19 13:49:39 -07001558 case CMD_PERFORM_NETWORK_SCAN:
1559 request = (MainThreadRequest) msg.obj;
1560 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1561 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1562 break;
1563
Hall Liu27d24262020-09-18 19:04:59 -07001564 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001565 request = (MainThreadRequest) msg.obj;
1566 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001567 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1568 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1569 request.argument;
1570 int callForwardingReason = args.first;
1571 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001572 break;
Hall Liu27d24262020-09-18 19:04:59 -07001573 }
1574 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001575 ar = (AsyncResult) msg.obj;
1576 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001577 TelephonyManager.CallForwardingInfoCallback callback =
1578 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1579 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001580 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001581 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001582 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1583 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1584 // Service Class is a bit mask per 3gpp 27.007. Search for
1585 // any service for voice call.
1586 if ((callForwardInfo.serviceClass
1587 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001588 callForwardingInfo = new CallForwardingInfo(
1589 callForwardInfo.status
1590 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001591 callForwardInfo.reason,
1592 callForwardInfo.number,
1593 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001594 break;
1595 }
1596 }
1597 // Didn't find a call forward info for voice call.
1598 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001599 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1600 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001601 }
Hall Liu27d24262020-09-18 19:04:59 -07001602 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001603 } else {
1604 if (ar.result == null) {
1605 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1606 }
1607 if (ar.exception != null) {
1608 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1609 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001610 int errorCode = TelephonyManager
1611 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001612 if (ar.exception instanceof CommandException) {
1613 CommandException.Error error =
1614 ((CommandException) (ar.exception)).getCommandError();
1615 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001616 errorCode = TelephonyManager
1617 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001618 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001619 errorCode = TelephonyManager
1620 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001621 }
1622 }
Hall Liu27d24262020-09-18 19:04:59 -07001623 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001624 }
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 CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001629 request = (MainThreadRequest) msg.obj;
1630 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001631 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001632 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001633 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1634 request.argument).first;
1635 request.phone.setCallForwardingOption(
1636 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001637 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001638 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001639 callForwardingInfoToSet.getReason(),
1640 callForwardingInfoToSet.getNumber(),
1641 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1642 break;
Hall Liu27d24262020-09-18 19:04:59 -07001643 }
Shuo Qian4a594052020-01-23 11:59:30 -08001644
Hall Liu27d24262020-09-18 19:04:59 -07001645 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001646 ar = (AsyncResult) msg.obj;
1647 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001648 Consumer<Integer> callback =
1649 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1650 request.argument).second;
1651 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001652 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001653 int errorCode = TelephonyManager.CallForwardingInfoCallback
1654 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001655 if (ar.exception instanceof CommandException) {
1656 CommandException.Error error =
1657 ((CommandException) (ar.exception)).getCommandError();
1658 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001659 errorCode = TelephonyManager.CallForwardingInfoCallback
1660 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001661 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001662 errorCode = TelephonyManager.CallForwardingInfoCallback
1663 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001664 }
1665 }
1666 callback.accept(errorCode);
1667 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001668 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001669 }
Shuo Qian4a594052020-01-23 11:59:30 -08001670 break;
Hall Liu27d24262020-09-18 19:04:59 -07001671 }
Shuo Qian4a594052020-01-23 11:59:30 -08001672
Hall Liu27d24262020-09-18 19:04:59 -07001673 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001674 request = (MainThreadRequest) msg.obj;
1675 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1676 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1677 break;
Hall Liu27d24262020-09-18 19:04:59 -07001678 }
Shuo Qian4a594052020-01-23 11:59:30 -08001679
Hall Liu27d24262020-09-18 19:04:59 -07001680 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001681 ar = (AsyncResult) msg.obj;
1682 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001683 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001684 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001685 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001686 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001687 // Service Class is a bit mask per 3gpp 27.007.
1688 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001689 if (callForwardResults.length > 1
1690 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001691 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001692 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001693 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1694 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001695 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001696 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001697 }
1698 } else {
1699 if (ar.result == null) {
1700 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1701 }
1702 if (ar.exception != null) {
1703 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1704 }
1705 if (ar.exception instanceof CommandException) {
1706 CommandException.Error error =
1707 ((CommandException) (ar.exception)).getCommandError();
1708 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001709 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001710 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001711 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1712 callWaitingStatus =
1713 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001714 }
1715 }
1716 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001717 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001718 break;
Hall Liu27d24262020-09-18 19:04:59 -07001719 }
Shuo Qian4a594052020-01-23 11:59:30 -08001720
Hall Liu27d24262020-09-18 19:04:59 -07001721 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001722 request = (MainThreadRequest) msg.obj;
1723 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001724 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1725 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001726 break;
Hall Liu27d24262020-09-18 19:04:59 -07001727 }
Shuo Qian4a594052020-01-23 11:59:30 -08001728
Hall Liu27d24262020-09-18 19:04:59 -07001729 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001730 ar = (AsyncResult) msg.obj;
1731 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001732 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1733 Consumer<Integer> callback =
1734 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1735 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001736 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001737 if (ar.exception instanceof CommandException) {
1738 CommandException.Error error =
1739 ((CommandException) (ar.exception)).getCommandError();
1740 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1741 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001742 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1743 callback.accept(
1744 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001745 } else {
1746 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1747 }
1748 } else {
1749 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1750 }
1751 } else {
1752 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1753 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001754 }
Shuo Qian4a594052020-01-23 11:59:30 -08001755 break;
Hall Liu27d24262020-09-18 19:04:59 -07001756 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001757 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1758 ar = (AsyncResult) msg.obj;
1759 request = (MainThreadRequest) ar.userObj;
1760 CellNetworkScanResult cellScanResult;
1761 if (ar.exception == null && ar.result != null) {
1762 cellScanResult = new CellNetworkScanResult(
1763 CellNetworkScanResult.STATUS_SUCCESS,
1764 (List<OperatorInfo>) ar.result);
1765 } else {
1766 if (ar.result == null) {
1767 loge("getCellNetworkScanResults: Empty response");
1768 }
1769 if (ar.exception != null) {
1770 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1771 }
1772 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1773 if (ar.exception instanceof CommandException) {
1774 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001775 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001776 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1777 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1778 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1779 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1780 }
1781 }
1782 cellScanResult = new CellNetworkScanResult(errorCode, null);
1783 }
1784 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001785 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001786 break;
1787
1788 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1789 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001790 ManualNetworkSelectionArgument selArg =
1791 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001792 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1793 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001794 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1795 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001796 break;
1797
1798 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001799 ar = (AsyncResult) msg.obj;
1800 request = (MainThreadRequest) ar.userObj;
1801 if (ar.exception == null) {
1802 request.result = true;
1803 } else {
1804 request.result = false;
1805 loge("setNetworkSelectionModeManual " + ar.exception);
1806 }
1807 notifyRequester(request);
1808 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001809 break;
1810
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001811 case CMD_GET_MODEM_ACTIVITY_INFO:
1812 request = (MainThreadRequest) msg.obj;
1813 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001814 if (defaultPhone != null) {
1815 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001816 } else {
1817 ResultReceiver result = (ResultReceiver) request.argument;
1818 Bundle bundle = new Bundle();
1819 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001820 new ModemActivityInfo(0, 0, 0,
1821 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001822 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001823 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001824 break;
1825
Hall Liud0f208c2020-10-14 16:54:44 -07001826 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001827 ar = (AsyncResult) msg.obj;
1828 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001829 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001830 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001831 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001832 if (mLastModemActivityInfo == null) {
1833 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1834 mLastModemActivitySpecificInfo[0] =
1835 new ActivityStatsTechSpecificInfo(
1836 0,
1837 0,
1838 new int[ModemActivityInfo.getNumTxPowerLevels()],
1839 0);
1840 mLastModemActivityInfo =
1841 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1842 }
1843
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001844 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001845 // Update the last modem activity info and the result of the request.
1846 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1847 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001848 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001849 } else {
1850 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001851 }
Kai Shi917fdc62022-11-28 14:01:02 -08001852 // This is needed to decouple ret from mLastModemActivityInfo
1853 // We don't want to return mLastModemActivityInfo which is updated
1854 // inside mergeModemActivityInfo()
1855 ret = new ModemActivityInfo(
1856 mLastModemActivityInfo.getTimestampMillis(),
1857 mLastModemActivityInfo.getSleepTimeMillis(),
1858 mLastModemActivityInfo.getIdleTimeMillis(),
1859 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001860
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001861 } else {
1862 if (ar.result == null) {
1863 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001864 error = TelephonyManager.ModemActivityInfoException
1865 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001866 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001867 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001868 error = TelephonyManager.ModemActivityInfoException
1869 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001870 } else {
1871 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001872 error = TelephonyManager.ModemActivityInfoException
1873 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001874 }
1875 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001876 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001877 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001878 bundle.putParcelable(
1879 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001880 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001881 } else {
1882 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1883 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001884 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001885 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001886 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001887 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001888
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001889 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001890 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001891 CarrierRestrictionRules argument =
1892 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001893 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001894 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001895 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001896 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001897
1898 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1899 ar = (AsyncResult) msg.obj;
1900 request = (MainThreadRequest) ar.userObj;
1901 if (ar.exception == null && ar.result != null) {
1902 request.result = ar.result;
1903 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001904 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1905 if (ar.exception instanceof CommandException) {
1906 loge("setAllowedCarriers: CommandException: " + ar.exception);
1907 CommandException.Error error =
1908 ((CommandException) (ar.exception)).getCommandError();
1909 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1910 request.result =
1911 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1912 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001913 } else {
1914 loge("setAllowedCarriers: Unknown exception");
1915 }
1916 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001917 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001918 break;
1919
1920 case CMD_GET_ALLOWED_CARRIERS:
1921 request = (MainThreadRequest) msg.obj;
1922 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001923 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001924 break;
1925
1926 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1927 ar = (AsyncResult) msg.obj;
1928 request = (MainThreadRequest) ar.userObj;
1929 if (ar.exception == null && ar.result != null) {
1930 request.result = ar.result;
1931 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001932 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001933 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001934 if (ar.result == null) {
1935 loge("getAllowedCarriers: Empty response");
1936 } else if (ar.exception instanceof CommandException) {
1937 loge("getAllowedCarriers: CommandException: " +
1938 ar.exception);
1939 } else {
1940 loge("getAllowedCarriers: Unknown exception");
1941 }
1942 }
arunvoddud7401012022-12-15 16:08:12 +00001943 if (request.argument != null) {
1944 // This is for the implementation of carrierRestrictionStatus.
1945 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1946 Consumer<Integer> callback = callbackInfo.getConsumer();
1947 int callerCarrierId = callbackInfo.getCarrierId();
1948 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1949 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1950 CarrierRestrictionRules carrierRestrictionRules =
1951 (CarrierRestrictionRules) ar.result;
1952 int carrierId = -1;
1953 try {
1954 CarrierIdentifier carrierIdentifier =
1955 carrierRestrictionRules.getAllowedCarriers().get(0);
1956 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1957 carrierIdentifier);
1958 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1959 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1960 }
1961 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1962 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1963 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001964 lockStatus = TelephonyManager
1965 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001966 }
1967 } else {
1968 Rlog.e(LOG_TAG,
1969 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1970 }
1971 callback.accept(lockStatus);
1972 } else {
1973 // This is for the implementation of getAllowedCarriers.
1974 notifyRequester(request);
1975 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001976 break;
1977
Nathan Haroldb3014052017-01-25 15:57:32 -08001978 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1979 ar = (AsyncResult) msg.obj;
1980 request = (MainThreadRequest) ar.userObj;
1981 if (ar.exception == null && ar.result != null) {
1982 request.result = ar.result;
1983 } else {
1984 request.result = new IllegalArgumentException(
1985 "Failed to retrieve Forbidden Plmns");
1986 if (ar.result == null) {
1987 loge("getForbiddenPlmns: Empty response");
1988 } else {
1989 loge("getForbiddenPlmns: Unknown exception");
1990 }
1991 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001992 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001993 break;
1994
1995 case CMD_GET_FORBIDDEN_PLMNS:
1996 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001997 uiccPort = getUiccPortFromRequest(request);
1998 if (uiccPort == null) {
1999 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08002000 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002001 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07002002 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08002003 break;
2004 }
2005 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002006 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08002007 if (uiccApp == null) {
2008 loge("getForbiddenPlmns() no app with specified type -- "
2009 + appType);
2010 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07002011 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08002012 break;
2013 } else {
2014 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
2015 + " specified type -- " + appType);
2016 }
2017 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
2018 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002019 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08002020 break;
2021
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00002022 case CMD_SWITCH_SLOTS:
2023 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00002024 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00002025 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00002026 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00002027 break;
2028
2029 case EVENT_SWITCH_SLOTS_DONE:
2030 ar = (AsyncResult) msg.obj;
2031 request = (MainThreadRequest) ar.userObj;
2032 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07002033 notifyRequester(request);
2034 break;
2035 case CMD_GET_NETWORK_SELECTION_MODE:
2036 request = (MainThreadRequest) msg.obj;
2037 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
2038 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
2039 break;
2040
2041 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
2042 ar = (AsyncResult) msg.obj;
2043 request = (MainThreadRequest) ar.userObj;
2044 if (ar.exception != null) {
2045 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2046 } else {
2047 int mode = ((int[]) ar.result)[0];
2048 if (mode == 0) {
2049 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
2050 } else {
2051 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
2052 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00002053 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002054 notifyRequester(request);
2055 break;
2056 case CMD_GET_CDMA_ROAMING_MODE:
2057 request = (MainThreadRequest) msg.obj;
2058 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
2059 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
2060 break;
2061 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
2062 ar = (AsyncResult) msg.obj;
2063 request = (MainThreadRequest) ar.userObj;
2064 if (ar.exception != null) {
2065 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
2066 } else {
2067 request.result = ((int[]) ar.result)[0];
2068 }
2069 notifyRequester(request);
2070 break;
2071 case CMD_SET_CDMA_ROAMING_MODE:
2072 request = (MainThreadRequest) msg.obj;
2073 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
2074 int mode = (int) request.argument;
2075 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
2076 break;
2077 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
2078 ar = (AsyncResult) msg.obj;
2079 request = (MainThreadRequest) ar.userObj;
2080 request.result = ar.exception == null;
2081 notifyRequester(request);
2082 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07002083 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
2084 request = (MainThreadRequest) msg.obj;
2085 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
2086 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
2087 break;
2088 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
2089 ar = (AsyncResult) msg.obj;
2090 request = (MainThreadRequest) ar.userObj;
2091 if (ar.exception != null) {
2092 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
2093 } else {
2094 request.result = ((int[]) ar.result)[0];
2095 }
2096 notifyRequester(request);
2097 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07002098 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
2099 request = (MainThreadRequest) msg.obj;
2100 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
2101 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07002102 getPhoneFromRequest(request).setCdmaSubscriptionMode(
2103 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07002104 break;
2105 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
2106 ar = (AsyncResult) msg.obj;
2107 request = (MainThreadRequest) ar.userObj;
2108 request.result = ar.exception == null;
2109 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00002110 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07002111 case CMD_GET_ALL_CELL_INFO:
2112 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07002113 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07002114 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07002115 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07002116 case EVENT_GET_ALL_CELL_INFO_DONE:
2117 ar = (AsyncResult) msg.obj;
2118 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07002119 // If a timeout occurs, the response will be null
2120 request.result = (ar.exception == null && ar.result != null)
2121 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07002122 synchronized (request) {
2123 request.notifyAll();
2124 }
2125 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002126 case CMD_REQUEST_CELL_INFO_UPDATE:
2127 request = (MainThreadRequest) msg.obj;
2128 request.phone.requestCellInfoUpdate(request.workSource,
2129 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
2130 break;
2131 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
2132 ar = (AsyncResult) msg.obj;
2133 request = (MainThreadRequest) ar.userObj;
2134 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
2135 try {
2136 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002137 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07002138 cb.onError(
2139 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
2140 ar.exception.getClass().getName(),
2141 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002142 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002143 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07002144 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002145 } else {
2146 // use the result as returned
2147 cb.onCellInfo((List<CellInfo>) ar.result);
2148 }
2149 } catch (RemoteException re) {
2150 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
2151 }
2152 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08002153 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07002154 request = (MainThreadRequest) msg.obj;
2155 WorkSource ws = (WorkSource) request.argument;
2156 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08002157 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07002158 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08002159 }
2160 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07002161 ar = (AsyncResult) msg.obj;
2162 request = (MainThreadRequest) ar.userObj;
2163 if (ar.exception == null) {
2164 request.result = ar.result;
2165 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08002166 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07002167 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08002168 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07002169 }
2170
2171 synchronized (request) {
2172 request.notifyAll();
2173 }
2174 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08002175 }
chen xu6dac5ab2018-10-26 17:39:23 -07002176 case CMD_MODEM_REBOOT:
2177 request = (MainThreadRequest) msg.obj;
2178 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002179 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07002180 break;
chen xu6dac5ab2018-10-26 17:39:23 -07002181 case EVENT_CMD_MODEM_REBOOT_DONE:
2182 handleNullReturnEvent(msg, "rebootModem");
2183 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002184 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002185 request = (MainThreadRequest) msg.obj;
2186 boolean enable = (boolean) request.argument;
2187 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08002188 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002189 PhoneConfigurationManager.getInstance()
2190 .enablePhone(request.phone, enable, onCompleted);
2191 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002192 }
Michele Berionne5e411512020-11-13 02:36:59 +00002193 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002194 ar = (AsyncResult) msg.obj;
2195 request = (MainThreadRequest) ar.userObj;
2196 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07002197 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08002198 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07002199 if ((boolean) request.result) {
2200 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
2201 updateModemStateMetrics();
2202 } else {
2203 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
2204 + ar.exception);
2205 }
2206 notifyRequester(request);
2207 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002208 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07002209 case CMD_GET_MODEM_STATUS:
2210 request = (MainThreadRequest) msg.obj;
2211 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
2212 PhoneConfigurationManager.getInstance()
2213 .getPhoneStatusFromModem(request.phone, onCompleted);
2214 break;
2215 case EVENT_GET_MODEM_STATUS_DONE:
2216 ar = (AsyncResult) msg.obj;
2217 request = (MainThreadRequest) ar.userObj;
2218 int id = request.phone.getPhoneId();
2219 if (ar.exception == null && ar.result != null) {
2220 request.result = ar.result;
2221 //update the cache as modem status has changed
2222 mPhoneConfigurationManager.addToPhoneStatusCache(id,
2223 (boolean) request.result);
2224 } else {
2225 // Return true if modem status cannot be retrieved. For most cases,
2226 // modem status is on. And for older version modems, GET_MODEM_STATUS
2227 // and disable modem are not supported. Modem is always on.
2228 // TODO: this should be fixed in R to support a third
2229 // status UNKNOWN b/131631629
2230 request.result = true;
2231 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
2232 + ar.exception);
2233 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002234 notifyRequester(request);
2235 break;
Hall Liu73f5d362020-01-20 13:42:00 -08002236 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
2237 request = (MainThreadRequest) msg.obj;
2238 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
2239 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
2240 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
2241 request.phone.setSystemSelectionChannels(args.first, onCompleted);
2242 break;
2243 }
2244 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
2245 ar = (AsyncResult) msg.obj;
2246 request = (MainThreadRequest) ar.userObj;
2247 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
2248 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
2249 args.second.accept(ar.exception == null);
2250 notifyRequester(request);
2251 break;
2252 }
Sarah Chin679c08a2020-11-18 13:39:35 -08002253 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
2254 request = (MainThreadRequest) msg.obj;
2255 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
2256 Phone phone = getPhoneFromRequest(request);
2257 if (phone != null) {
2258 phone.getSystemSelectionChannels(onCompleted);
2259 } else {
2260 loge("getSystemSelectionChannels: No phone object");
2261 request.result = new ArrayList<RadioAccessSpecifier>();
2262 notifyRequester(request);
2263 }
2264 break;
2265 }
2266 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
2267 ar = (AsyncResult) msg.obj;
2268 request = (MainThreadRequest) ar.userObj;
2269 if (ar.exception == null && ar.result != null) {
2270 request.result = ar.result;
2271 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08002272 request.result = new IllegalStateException(
2273 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08002274 if (ar.result == null) {
2275 loge("getSystemSelectionChannels: Empty response");
2276 } else {
2277 loge("getSystemSelectionChannels: Unknown exception");
2278 }
2279 }
2280 notifyRequester(request);
2281 break;
yincheng zhao2737e882019-09-06 17:06:54 -07002282 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
2283 ar = (AsyncResult) msg.obj;
2284 request = (MainThreadRequest) ar.userObj;
2285 if (ar.exception == null && ar.result != null) {
2286 request.result = ar.result;
2287 } else {
2288 request.result = -1;
2289 loge("Failed to set Forbidden Plmns");
2290 if (ar.result == null) {
2291 loge("setForbidenPlmns: Empty response");
2292 } else if (ar.exception != null) {
2293 loge("setForbiddenPlmns: Exception: " + ar.exception);
2294 request.result = -1;
2295 } else {
2296 loge("setForbiddenPlmns: Unknown exception");
2297 }
2298 }
2299 notifyRequester(request);
2300 break;
2301 case CMD_SET_FORBIDDEN_PLMNS:
2302 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002303 uiccPort = getUiccPortFromRequest(request);
2304 if (uiccPort == null) {
2305 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07002306 request.result = -1;
2307 notifyRequester(request);
2308 break;
2309 }
2310 Pair<Integer, List<String>> setFplmnsArgs =
2311 (Pair<Integer, List<String>>) request.argument;
2312 appType = setFplmnsArgs.first;
2313 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002314 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07002315 if (uiccApp == null) {
2316 loge("setForbiddenPlmns: no app with specified type -- " + appType);
2317 request.result = -1;
2318 loge("Failed to get UICC App");
2319 notifyRequester(request);
2320 } else {
2321 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
2322 ((SIMRecords) uiccApp.getIccRecords())
2323 .setForbiddenPlmns(onCompleted, fplmns);
2324 }
yinchengzhao4d163c02019-12-12 15:21:47 -08002325 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07002326 case CMD_ERASE_MODEM_CONFIG:
2327 request = (MainThreadRequest) msg.obj;
2328 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
2329 defaultPhone.eraseModemConfig(onCompleted);
2330 break;
2331 case EVENT_ERASE_MODEM_CONFIG_DONE:
2332 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07002333 break;
zoey chene02881a2019-12-30 16:11:23 +08002334
Kai Shif70f46f2021-03-03 13:59:46 -08002335 case CMD_ERASE_DATA_SHARED_PREFERENCES:
2336 request = (MainThreadRequest) msg.obj;
2337 request.result = defaultPhone.eraseDataInSharedPreferences();
2338 notifyRequester(request);
2339 break;
2340
zoey chene02881a2019-12-30 16:11:23 +08002341 case CMD_CHANGE_ICC_LOCK_PASSWORD:
2342 request = (MainThreadRequest) msg.obj;
2343 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
2344 Pair<String, String> changed = (Pair<String, String>) request.argument;
2345 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
2346 changed.first, changed.second, onCompleted);
2347 break;
2348 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2349 ar = (AsyncResult) msg.obj;
2350 request = (MainThreadRequest) ar.userObj;
2351 if (ar.exception == null) {
2352 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002353 // If the operation is successful, update the PIN storage
2354 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2355 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002356 UiccController.getInstance().getPinStorage()
2357 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002358 } else {
2359 request.result = msg.arg1;
2360 }
2361 notifyRequester(request);
2362 break;
2363
Michele Berionne5e411512020-11-13 02:36:59 +00002364 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002365 request = (MainThreadRequest) msg.obj;
2366 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2367 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2368 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2369 enabled.first, enabled.second, onCompleted);
2370 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002371 }
zoey chene02881a2019-12-30 16:11:23 +08002372 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2373 ar = (AsyncResult) msg.obj;
2374 request = (MainThreadRequest) ar.userObj;
2375 if (ar.exception == null) {
2376 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002377 // If the operation is successful, update the PIN storage
2378 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2379 int phoneId = getPhoneFromRequest(request).getPhoneId();
2380 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002381 UiccController.getInstance().getPinStorage()
2382 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002383 } else {
2384 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2385 }
zoey chene02881a2019-12-30 16:11:23 +08002386 } else {
2387 request.result = msg.arg1;
2388 }
Michele Berionne5e411512020-11-13 02:36:59 +00002389
2390
zoey chene02881a2019-12-30 16:11:23 +08002391 notifyRequester(request);
2392 break;
2393
Peter Wangdafb9ac2020-01-15 14:13:38 -08002394 case MSG_NOTIFY_USER_ACTIVITY:
2395 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002396 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002397 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2398 getDefaultPhone().getContext().sendBroadcastAsUser(
2399 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2400 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002401
2402 case CMD_SET_DATA_THROTTLING: {
2403 request = (MainThreadRequest) msg.obj;
2404 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2405 DataThrottlingRequest dataThrottlingRequest =
2406 (DataThrottlingRequest) request.argument;
2407 Phone phone = getPhoneFromRequest(request);
2408 if (phone != null) {
2409 phone.setDataThrottling(onCompleted,
2410 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2411 dataThrottlingRequest.getCompletionDurationMillis());
2412 } else {
2413 loge("setDataThrottling: No phone object");
2414 request.result =
2415 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2416 notifyRequester(request);
2417 }
2418
2419 break;
2420 }
2421 case EVENT_SET_DATA_THROTTLING_DONE:
2422 ar = (AsyncResult) msg.obj;
2423 request = (MainThreadRequest) ar.userObj;
2424
2425 if (ar.exception == null) {
2426 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2427 } else if (ar.exception instanceof CommandException) {
2428 loge("setDataThrottling: CommandException: " + ar.exception);
2429 CommandException.Error error =
2430 ((CommandException) (ar.exception)).getCommandError();
2431
2432 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2433 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002434 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002435 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2436 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002437 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2438 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002439 } else {
2440 request.result =
2441 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2442 }
2443 } else {
2444 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2445 }
2446 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2447 notifyRequester(request);
2448 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002449
2450 case CMD_SET_SIM_POWER: {
2451 request = (MainThreadRequest) msg.obj;
2452 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2453 request = (MainThreadRequest) msg.obj;
2454 int stateToSet =
2455 ((Pair<Integer, IIntegerConsumer>)
2456 request.argument).first;
2457 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2458 break;
2459 }
2460 case EVENT_SET_SIM_POWER_DONE: {
2461 ar = (AsyncResult) msg.obj;
2462 request = (MainThreadRequest) ar.userObj;
2463 IIntegerConsumer callback =
2464 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2465 if (ar.exception != null) {
2466 loge("setSimPower exception: " + ar.exception);
2467 int errorCode = TelephonyManager.CallForwardingInfoCallback
2468 .RESULT_ERROR_UNKNOWN;
2469 if (ar.exception instanceof CommandException) {
2470 CommandException.Error error =
2471 ((CommandException) (ar.exception)).getCommandError();
2472 if (error == CommandException.Error.SIM_ERR) {
2473 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2474 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2475 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2476 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2477 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2478 } else {
2479 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2480 }
2481 }
2482 try {
2483 callback.accept(errorCode);
2484 } catch (RemoteException e) {
2485 // Ignore if the remote process is no longer available to call back.
2486 Log.w(LOG_TAG, "setSimPower: callback not available.");
2487 }
2488 } else {
2489 try {
2490 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2491 } catch (RemoteException e) {
2492 // Ignore if the remote process is no longer available to call back.
2493 Log.w(LOG_TAG, "setSimPower: callback not available.");
2494 }
2495 }
2496 break;
2497 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002498 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2499 request = (MainThreadRequest) msg.obj;
2500
2501 final Phone phone = getPhoneFromRequest(request);
2502 if (phone == null || phone.getServiceStateTracker() == null) {
2503 request.result = new IllegalStateException("Phone or SST is null");
2504 notifyRequester(request);
2505 break;
2506 }
2507
2508 Pair<Integer, SignalStrengthUpdateRequest> pair =
2509 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2510 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2511 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002512 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002513 request.subId, pair.first /*callingUid*/,
2514 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002515 break;
2516 }
2517 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2518 ar = (AsyncResult) msg.obj;
2519 request = (MainThreadRequest) ar.userObj;
2520 // request.result will be the exception of ar if present, true otherwise.
2521 // Be cautious not to leave result null which will wait() forever
2522 request.result = ar.exception != null ? ar.exception : true;
2523 notifyRequester(request);
2524 break;
2525 }
2526 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2527 request = (MainThreadRequest) msg.obj;
2528
2529 Phone phone = getPhoneFromRequest(request);
2530 if (phone == null || phone.getServiceStateTracker() == null) {
2531 request.result = new IllegalStateException("Phone or SST is null");
2532 notifyRequester(request);
2533 break;
2534 }
2535
2536 Pair<Integer, SignalStrengthUpdateRequest> pair =
2537 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2538 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2539 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002540 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002541 request.subId, pair.first /*callingUid*/,
2542 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002543 break;
2544 }
2545 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2546 ar = (AsyncResult) msg.obj;
2547 request = (MainThreadRequest) ar.userObj;
2548 request.result = ar.exception != null ? ar.exception : true;
2549 notifyRequester(request);
2550 break;
2551 }
Jordan Liu109698e2020-11-24 14:50:34 -08002552
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002553 case CMD_GET_SLICING_CONFIG: {
2554 request = (MainThreadRequest) msg.obj;
2555 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2556 request.phone.getSlicingConfig(onCompleted);
2557 break;
2558 }
2559 case EVENT_GET_SLICING_CONFIG_DONE: {
2560 ar = (AsyncResult) msg.obj;
2561 request = (MainThreadRequest) ar.userObj;
2562 ResultReceiver result = (ResultReceiver) request.argument;
2563
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002564 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002565 Bundle bundle = new Bundle();
2566 int resultCode = 0;
2567 if (ar.exception != null) {
2568 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2569 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002570 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002571 } else if (ar.result == null) {
2572 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002573 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002574 } else {
2575 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002576 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2577 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002578 }
2579
2580 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002581 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002582 }
2583 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2584 result.send(resultCode, bundle);
2585 notifyRequester(request);
2586 break;
2587 }
2588
Sarah Chin71b3a852022-09-28 15:54:19 -07002589 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002590 request = (MainThreadRequest) msg.obj;
2591 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002592 PurchasePremiumCapabilityArgument arg =
2593 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002594 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chinb8218c22023-01-04 13:35:29 -08002595 arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002596 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002597 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002598
Sarah Chin71b3a852022-09-28 15:54:19 -07002599 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002600 ar = (AsyncResult) msg.obj;
2601 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002602 PurchasePremiumCapabilityArgument arg =
2603 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002604 try {
2605 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002606 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002607 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002608 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002609 + ", result= "
2610 + TelephonyManager.convertPurchaseResultToString(result));
2611 } catch (RemoteException e) {
2612 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002613 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002614 + " failed: " + e;
2615 if (DBG) log(logStr);
2616 AnomalyReporter.reportAnomaly(
2617 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2618 }
2619 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002620 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002621
Michele Berionne5e411512020-11-13 02:36:59 +00002622 case CMD_PREPARE_UNATTENDED_REBOOT:
2623 request = (MainThreadRequest) msg.obj;
2624 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002625 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002626 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002627 notifyRequester(request);
2628 break;
2629
Sarah Chineccfbd12023-01-20 19:00:35 -08002630 case CMD_START_SATELLITE_POSITION_UPDATES: {
2631 request = (MainThreadRequest) msg.obj;
2632 onCompleted =
2633 obtainMessage(EVENT_START_SATELLITE_POSITION_UPDATES_DONE, request);
Sarah Chin4beb2b72023-02-14 14:47:54 -08002634 if (mIsSatelliteServiceSupported) {
2635 mSatelliteServiceController.startSendingSatellitePointingInfo(onCompleted);
2636 break;
2637 }
Sarah Chineccfbd12023-01-20 19:00:35 -08002638 Phone phone = getPhoneFromRequest(request);
2639 if (phone != null) {
2640 phone.startSatellitePositionUpdates(onCompleted);
2641 } else {
2642 loge("startSatellitePositionUpdates: No phone object");
Thomas Nguyen299d6cd2023-02-14 09:57:15 -08002643 SatellitePositionUpdateArgument arg =
2644 (SatellitePositionUpdateArgument) request.argument;
2645 arg.errorCallback.accept(
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002646 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Sarah Chineccfbd12023-01-20 19:00:35 -08002647 }
2648 break;
2649 }
2650
2651 case EVENT_START_SATELLITE_POSITION_UPDATES_DONE: {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -08002652 handleStartSatellitePositionUpdatesDone((AsyncResult) msg.obj);
Sarah Chineccfbd12023-01-20 19:00:35 -08002653 break;
2654 }
2655
2656 case CMD_STOP_SATELLITE_POSITION_UPDATES: {
2657 request = (MainThreadRequest) msg.obj;
2658 onCompleted =
2659 obtainMessage(EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE, request);
Sarah Chin4beb2b72023-02-14 14:47:54 -08002660 if (mIsSatelliteServiceSupported) {
2661 mSatelliteServiceController.stopSendingSatellitePointingInfo(onCompleted);
2662 break;
2663 }
Sarah Chineccfbd12023-01-20 19:00:35 -08002664 Phone phone = getPhoneFromRequest(request);
2665 if (phone != null) {
2666 phone.stopSatellitePositionUpdates(onCompleted);
2667 } else {
2668 loge("stopSatellitePositionUpdates: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002669 ((Consumer<Integer>) request.argument).accept(
2670 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Sarah Chineccfbd12023-01-20 19:00:35 -08002671 }
2672 break;
2673 }
2674
2675 case EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE: {
2676 ar = (AsyncResult) msg.obj;
2677 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002678 int error = getSatelliteError(ar, "stopSatellitePositionUpdates", false);
2679 ((Consumer<Integer>) request.argument).accept(error);
Sarah Chineccfbd12023-01-20 19:00:35 -08002680 break;
2681 }
2682
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002683 case CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG: {
2684 request = (MainThreadRequest) msg.obj;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002685 onCompleted =
2686 obtainMessage(EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE, request);
2687 if (mIsSatelliteServiceSupported) {
2688 mSatelliteServiceController
2689 .requestMaxCharactersPerMOTextMessage(onCompleted);
2690 break;
2691 }
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002692 Phone phone = getPhoneFromRequest(request);
2693 if (phone != null) {
2694 phone.getMaxCharactersPerSatelliteTextMessage(onCompleted);
2695 } else {
2696 loge("getMaxCharactersPerSatelliteTextMessage: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002697 ((ResultReceiver) request.argument).send(
2698 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002699 }
2700 break;
2701 }
2702
2703 case EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE: {
2704 ar = (AsyncResult) msg.obj;
2705 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002706 int error =
2707 getSatelliteError(ar, "getMaxCharactersPerSatelliteTextMessage", true);
2708 Bundle bundle = new Bundle();
2709 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002710 int maxCharLimit = ((int[]) ar.result)[0];
Sarah Chin503828c2023-02-01 23:54:20 -08002711 if (DBG) log("getMaxCharactersPerSatelliteTextMessage: " + maxCharLimit);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002712 bundle.putInt(SatelliteManager.KEY_MAX_CHARACTERS_PER_SATELLITE_TEXT,
2713 maxCharLimit);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002714 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002715 ((ResultReceiver) request.argument).send(error, bundle);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002716 break;
2717 }
2718
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002719 case CMD_PROVISION_SATELLITE_SERVICE: {
2720 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002721 ProvisionSatelliteServiceArgument argument =
2722 (ProvisionSatelliteServiceArgument) request.argument;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002723 if (mSatelliteProvisionCallbacks.containsKey(argument.subId)) {
2724 argument.callback.accept(
2725 SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS);
2726 notifyRequester(request);
2727 break;
2728 }
2729 mSatelliteProvisionCallbacks.put(argument.subId, argument.callback);
2730 onCompleted = obtainMessage(EVENT_PROVISION_SATELLITE_SERVICE_DONE, request);
2731 if (mIsSatelliteServiceSupported) {
2732 mSatelliteServiceController
2733 .provisionSatelliteService(argument.token, onCompleted);
2734 break;
2735 }
2736 Phone phone = getPhoneFromRequest(request);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002737 if (phone != null) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08002738 phone.provisionSatelliteService(onCompleted, argument.token);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002739 } else {
2740 loge("provisionSatelliteService: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002741 argument.callback.accept(
2742 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002743 notifyRequester(request);
2744 }
2745 break;
2746 }
2747
2748 case EVENT_PROVISION_SATELLITE_SERVICE_DONE: {
2749 ar = (AsyncResult) msg.obj;
2750 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002751 int errorCode = getSatelliteError(ar, "provisionSatelliteService", false);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002752 handleEventProvisionSatelliteServiceDone(
2753 (ProvisionSatelliteServiceArgument) request.argument, errorCode);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002754 notifyRequester(request);
2755 break;
2756 }
2757
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002758 case CMD_DEPROVISION_SATELLITE_SERVICE: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002759 request = (MainThreadRequest) msg.obj;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002760 ProvisionSatelliteServiceArgument argument =
2761 (ProvisionSatelliteServiceArgument) request.argument;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002762 onCompleted = obtainMessage(EVENT_DEPROVISION_SATELLITE_SERVICE_DONE, request);
2763 if (mIsSatelliteServiceSupported) {
2764 mSatelliteServiceController
2765 .deprovisionSatelliteService(argument.token, onCompleted);
2766 break;
2767 }
2768 Phone phone = getPhoneFromRequest(request);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002769 if (phone != null) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08002770 phone.deprovisionSatelliteService(onCompleted, argument.token);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002771 } else {
2772 loge("deprovisionSatelliteService: No phone object");
2773 if (argument.callback != null) {
2774 argument.callback.accept(
2775 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
2776 }
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002777 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002778 break;
2779 }
2780
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002781 case EVENT_DEPROVISION_SATELLITE_SERVICE_DONE: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002782 ar = (AsyncResult) msg.obj;
2783 request = (MainThreadRequest) ar.userObj;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002784 int errorCode = getSatelliteError(ar, "deprovisionSatelliteService", false);
2785 handleEventDeprovisionSatelliteServiceDone(
2786 (ProvisionSatelliteServiceArgument) request.argument, errorCode);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002787 break;
2788 }
2789
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002790 case CMD_SET_SATELLITE_ENABLED: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002791 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002792 Pair<Boolean, Consumer<Integer>> argument =
2793 (Pair<Boolean, Consumer<Integer>>) request.argument;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002794 onCompleted = obtainMessage(EVENT_SET_SATELLITE_ENABLED_DONE, request);
2795 if (mIsSatelliteServiceSupported) {
2796 mSatelliteServiceController
2797 .requestSatelliteEnabled(argument.first, onCompleted);
2798 break;
2799 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002800 Phone phone = getPhoneFromRequest(request);
2801 if (phone != null) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08002802 phone.setSatellitePower(onCompleted, argument.first);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002803 } else {
Sarah Chin4beb2b72023-02-14 14:47:54 -08002804 loge("requestSatelliteEnabled: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002805 argument.second.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002806 }
2807 break;
2808 }
2809
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002810 case EVENT_SET_SATELLITE_ENABLED_DONE: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002811 ar = (AsyncResult) msg.obj;
2812 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002813 Pair<Boolean, Consumer<Integer>> argument =
2814 (Pair<Boolean, Consumer<Integer>>) request.argument;
2815 int error = getSatelliteError(ar, "setSatelliteEnabled", false);
2816 argument.second.accept(error);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002817 break;
2818 }
2819
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002820 case CMD_IS_SATELLITE_ENABLED: {
Sarah Chin503828c2023-02-01 23:54:20 -08002821 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002822 onCompleted = obtainMessage(EVENT_IS_SATELLITE_ENABLED_DONE, request);
Sarah Chin4beb2b72023-02-14 14:47:54 -08002823 if (mIsSatelliteServiceSupported) {
2824 mSatelliteServiceController.requestIsSatelliteEnabled(onCompleted);
2825 break;
2826 }
Sarah Chin503828c2023-02-01 23:54:20 -08002827 Phone phone = getPhoneFromRequest(request);
2828 if (phone != null) {
2829 phone.isSatellitePowerOn(onCompleted);
2830 } else {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002831 loge("isSatelliteEnabled: No phone object");
2832 ((ResultReceiver) request.argument).send(
2833 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002834 }
2835 break;
2836 }
2837
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002838 case EVENT_IS_SATELLITE_ENABLED_DONE: {
Sarah Chin503828c2023-02-01 23:54:20 -08002839 ar = (AsyncResult) msg.obj;
2840 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002841 int error = getSatelliteError(ar, "isSatelliteEnabled", true);
2842 Bundle bundle = new Bundle();
2843 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
2844 boolean enabled = ((int[]) ar.result)[0] == 1;
2845 if (DBG) log("isSatelliteEnabled: " + enabled);
2846 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_ENABLED, enabled);
Sarah Chin503828c2023-02-01 23:54:20 -08002847 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002848 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002849 break;
2850 }
2851
2852 case CMD_IS_SATELLITE_SUPPORTED: {
2853 request = (MainThreadRequest) msg.obj;
2854 onCompleted = obtainMessage(EVENT_IS_SATELLITE_SUPPORTED_DONE, request);
Sarah Chin4beb2b72023-02-14 14:47:54 -08002855 if (mIsSatelliteServiceSupported) {
2856 mSatelliteServiceController.requestIsSatelliteSupported(onCompleted);
2857 break;
2858 }
Sarah Chin503828c2023-02-01 23:54:20 -08002859 Phone phone = getPhoneFromRequest(request);
2860 if (phone != null) {
2861 phone.isSatelliteSupported(onCompleted);
2862 } else {
2863 loge("isSatelliteSupported: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002864 ((ResultReceiver) request.argument).send(
2865 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002866 }
2867 break;
2868 }
2869
2870 case EVENT_IS_SATELLITE_SUPPORTED_DONE: {
2871 ar = (AsyncResult) msg.obj;
2872 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002873 int error = getSatelliteError(ar, "isSatelliteSupported", true);
2874 Bundle bundle = new Bundle();
2875 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
Sarah Chin43457982023-02-15 17:50:38 -08002876 boolean supported = (boolean) ar.result;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002877 if (DBG) log("isSatelliteSupported: " + supported);
2878 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, supported);
Thomas Nguyene77de6d2023-02-10 17:42:43 -08002879 synchronized (mIsSatelliteSupportedLock) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002880 mIsSatelliteSupported = supported;
2881 }
2882 } else {
2883 synchronized (mIsSatelliteSupportedLock) {
2884 mIsSatelliteSupported = null;
Thomas Nguyene77de6d2023-02-10 17:42:43 -08002885 }
Sarah Chin503828c2023-02-01 23:54:20 -08002886 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002887 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002888 break;
2889 }
2890
2891 case CMD_GET_SATELLITE_CAPABILITIES: {
2892 request = (MainThreadRequest) msg.obj;
2893 onCompleted = obtainMessage(EVENT_GET_SATELLITE_CAPABILITIES_DONE, request);
Sarah Chin4beb2b72023-02-14 14:47:54 -08002894 if (mIsSatelliteServiceSupported) {
2895 mSatelliteServiceController.requestSatelliteCapabilities(onCompleted);
2896 break;
2897 }
Sarah Chin503828c2023-02-01 23:54:20 -08002898 Phone phone = getPhoneFromRequest(request);
2899 if (phone != null) {
2900 phone.getSatelliteCapabilities(onCompleted);
2901 } else {
2902 loge("getSatelliteCapabilities: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002903 ((ResultReceiver) request.argument).send(
2904 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002905 }
2906 break;
2907 }
2908
2909 case EVENT_GET_SATELLITE_CAPABILITIES_DONE: {
2910 ar = (AsyncResult) msg.obj;
2911 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002912 int error = getSatelliteError(ar, "getSatelliteCapabilities", true);
2913 Bundle bundle = new Bundle();
2914 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
Sarah Chin503828c2023-02-01 23:54:20 -08002915 SatelliteCapabilities capabilities = (SatelliteCapabilities) ar.result;
2916 if (DBG) log("getSatelliteCapabilities: " + capabilities);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002917 bundle.putParcelable(SatelliteManager.KEY_SATELLITE_CAPABILITIES,
2918 capabilities);
Sarah Chin503828c2023-02-01 23:54:20 -08002919 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002920 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002921 break;
2922 }
2923
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +00002924 case CMD_POLL_PENDING_SATELLITE_DATAGRAMS: {
2925 request = (MainThreadRequest) msg.obj;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002926 onCompleted =
2927 obtainMessage(EVENT_POLL_PENDING_SATELLITE_DATAGRAMS_DONE, request);
2928 if (mIsSatelliteServiceSupported) {
2929 mSatelliteServiceController.pollPendingSatelliteDatagrams(onCompleted);
2930 break;
2931 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +00002932 Phone phone = getPhoneFromRequest(request);
2933 if (phone != null) {
2934 phone.pollPendingSatelliteDatagrams(onCompleted);
2935 } else {
2936 loge("pollPendingSatelliteDatagrams: No phone object");
Sarah Chin4beb2b72023-02-14 14:47:54 -08002937 ((Consumer<Integer>) request.argument).accept(
2938 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +00002939 }
2940 break;
2941 }
2942
2943 case EVENT_POLL_PENDING_SATELLITE_DATAGRAMS_DONE: {
2944 ar = (AsyncResult) msg.obj;
2945 request = (MainThreadRequest) ar.userObj;
Aishwarya Mallampati224317a2023-02-13 22:09:30 +00002946 int error = getSatelliteError(ar, "pollPendingSatelliteDatagrams", false);
2947 ((Consumer<Integer>) request.argument).accept(error);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +00002948 break;
2949 }
2950
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +00002951 case CMD_SEND_SATELLITE_DATAGRAM: {
2952 request = (MainThreadRequest) msg.obj;
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +00002953 SendSatelliteDatagramArgument argument =
2954 (SendSatelliteDatagramArgument) request.argument;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002955 onCompleted = obtainMessage(EVENT_SEND_SATELLITE_DATAGRAM_DONE, request);
2956 if (mIsSatelliteServiceSupported) {
Sarah Chin43457982023-02-15 17:50:38 -08002957 mSatelliteServiceController.sendSatelliteDatagram(
2958 argument.datagram,
2959 argument.datagramType == SatelliteManager.DATAGRAM_TYPE_SOS_MESSAGE,
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +00002960 argument.needFullScreenPointingUI, onCompleted);
Sarah Chin4beb2b72023-02-14 14:47:54 -08002961 break;
2962 }
2963 Phone phone = getPhoneFromRequest(request);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +00002964 if (phone != null) {
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +00002965 phone.sendSatelliteDatagram(onCompleted, argument.datagram,
2966 argument.needFullScreenPointingUI);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +00002967 } else {
2968 loge("sendSatelliteDatagram: No phone object");
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +00002969 argument.result.send(
2970 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +00002971 }
2972 break;
2973 }
2974
2975 case EVENT_SEND_SATELLITE_DATAGRAM_DONE: {
2976 ar = (AsyncResult) msg.obj;
2977 request = (MainThreadRequest) ar.userObj;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002978 int error = getSatelliteError(ar, "sendSatelliteDatagram", false);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +00002979 SendSatelliteDatagramArgument argument =
2980 (SendSatelliteDatagramArgument) request.argument;
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +00002981 Bundle bundle = new Bundle();
2982 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
2983 bundle.putLong(SatelliteManager.KEY_SEND_SATELLITE_DATAGRAM,
2984 argument.datagramId);
2985 }
2986 argument.result.send(error, bundle);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +00002987 break;
2988 }
2989
Sarah Chindf715ec2023-02-13 13:46:24 -08002990 case CMD_IS_SATELLITE_COMMUNICATION_ALLOWED: {
2991 request = (MainThreadRequest) msg.obj;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002992 onCompleted =
2993 obtainMessage(EVENT_IS_SATELLITE_COMMUNICATION_ALLOWED_DONE, request);
2994 if (mIsSatelliteServiceSupported) {
2995 mSatelliteServiceController
2996 .requestIsSatelliteCommunicationAllowedForCurrentLocation(
2997 onCompleted);
2998 break;
2999 }
Sarah Chindf715ec2023-02-13 13:46:24 -08003000 Phone phone = getPhoneFromRequest(request);
3001 if (phone != null) {
3002 phone.isSatelliteCommunicationAllowedForCurrentLocation(onCompleted);
3003 } else {
3004 loge("isSatelliteCommunicationAllowedForCurrentLocation: No phone object");
3005 ((ResultReceiver) request.argument).send(
3006 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
3007 }
3008 break;
3009 }
3010
3011 case EVENT_IS_SATELLITE_COMMUNICATION_ALLOWED_DONE: {
3012 ar = (AsyncResult) msg.obj;
3013 request = (MainThreadRequest) ar.userObj;
3014 int error = getSatelliteError(
3015 ar, "isSatelliteCommunicationAllowedForCurrentLocation", true);
3016 Bundle bundle = new Bundle();
3017 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
Sarah Chin43457982023-02-15 17:50:38 -08003018 boolean communicationAllowed = (boolean) ar.result;
Sarah Chindf715ec2023-02-13 13:46:24 -08003019 if (DBG) {
3020 log("isSatelliteCommunicationAllowedForCurrentLocation: "
3021 + communicationAllowed);
3022 }
3023 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_COMMUNICATION_ALLOWED,
3024 communicationAllowed);
3025 }
3026 ((ResultReceiver) request.argument).send(error, bundle);
3027 break;
3028 }
3029
3030 case CMD_GET_TIME_SATELLITE_NEXT_VISIBLE: {
3031 request = (MainThreadRequest) msg.obj;
3032 onCompleted = obtainMessage(EVENT_GET_TIME_SATELLITE_NEXT_VISIBLE_DONE,
3033 request);
Sarah Chin4beb2b72023-02-14 14:47:54 -08003034 if (mIsSatelliteServiceSupported) {
3035 mSatelliteServiceController
3036 .requestTimeForNextSatelliteVisibility(onCompleted);
3037 break;
3038 }
Sarah Chindf715ec2023-02-13 13:46:24 -08003039 Phone phone = getPhoneFromRequest(request);
3040 if (phone != null) {
3041 phone.requestTimeForNextSatelliteVisibility(onCompleted);
3042 } else {
3043 loge("requestTimeForNextSatelliteVisibility: No phone object");
3044 ((ResultReceiver) request.argument).send(
3045 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
3046 }
3047 break;
3048 }
3049
3050 case EVENT_GET_TIME_SATELLITE_NEXT_VISIBLE_DONE: {
3051 ar = (AsyncResult) msg.obj;
3052 request = (MainThreadRequest) ar.userObj;
3053 int error =
3054 getSatelliteError(ar, "requestTimeForNextSatelliteVisibility", true);
3055 Bundle bundle = new Bundle();
3056 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
3057 int nextVisibilityDuration = ((int[]) ar.result)[0];
3058 if (DBG) {
3059 log("requestTimeForNextSatelliteVisibility: " + nextVisibilityDuration);
3060 }
3061 bundle.putInt(SatelliteManager.KEY_SATELLITE_NEXT_VISIBILITY,
3062 nextVisibilityDuration);
3063 }
3064 ((ResultReceiver) request.argument).send(error, bundle);
3065 break;
3066 }
3067
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003068 default:
3069 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
3070 break;
3071 }
3072 }
Jake Hambye994d462014-02-03 13:10:13 -08003073
Pengquan Menga1bb6272018-09-06 09:59:22 -07003074 private void notifyRequester(MainThreadRequest request) {
3075 synchronized (request) {
3076 request.notifyAll();
3077 }
3078 }
3079
Jake Hambye994d462014-02-03 13:10:13 -08003080 private void handleNullReturnEvent(Message msg, String command) {
3081 AsyncResult ar = (AsyncResult) msg.obj;
3082 MainThreadRequest request = (MainThreadRequest) ar.userObj;
3083 if (ar.exception == null) {
3084 request.result = true;
3085 } else {
3086 request.result = false;
3087 if (ar.exception instanceof CommandException) {
3088 loge(command + ": CommandException: " + ar.exception);
3089 } else {
3090 loge(command + ": Unknown exception");
3091 }
3092 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003093 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08003094 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003095 }
3096
3097 /**
3098 * Posts the specified command to be executed on the main thread,
3099 * waits for the request to complete, and returns the result.
3100 * @see #sendRequestAsync
3101 */
3102 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08003103 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
3104 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07003105 }
3106
3107 /**
3108 * Posts the specified command to be executed on the main thread,
3109 * waits for the request to complete, and returns the result.
3110 * @see #sendRequestAsync
3111 */
3112 private Object sendRequest(int command, Object argument, WorkSource workSource) {
3113 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08003114 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07003115 }
3116
3117 /**
3118 * Posts the specified command to be executed on the main thread,
3119 * waits for the request to complete, and returns the result.
3120 * @see #sendRequestAsync
3121 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003122 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08003123 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
3124 }
3125
3126 /**
3127 * Posts the specified command to be executed on the main thread,
3128 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
3129 * if not timeout or null otherwise.
3130 * @see #sendRequestAsync
3131 */
3132 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
3133 long timeoutInMs) {
3134 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07003135 }
3136
3137 /**
3138 * Posts the specified command to be executed on the main thread,
3139 * waits for the request to complete, and returns the result.
3140 * @see #sendRequestAsync
3141 */
Nathan Harold92bed182018-10-12 18:16:49 -07003142 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08003143 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07003144 }
3145
3146 /**
3147 * Posts the specified command to be executed on the main thread,
3148 * waits for the request to complete, and returns the result.
3149 * @see #sendRequestAsync
3150 */
3151 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08003152 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
3153 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07003154 }
3155
3156 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08003157 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
3158 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
3159 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07003160 * @see #sendRequestAsync
3161 */
Rambo Wang0f050d82021-02-12 11:43:36 -08003162 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
3163 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003164 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
3165 throw new RuntimeException("This method will deadlock if called from the main thread.");
3166 }
3167
Nathan Harold92bed182018-10-12 18:16:49 -07003168 MainThreadRequest request = null;
3169 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
3170 throw new IllegalArgumentException("subId and phone cannot both be specified!");
3171 } else if (phone != null) {
3172 request = new MainThreadRequest(argument, phone, workSource);
3173 } else {
3174 request = new MainThreadRequest(argument, subId, workSource);
3175 }
3176
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003177 Message msg = mMainThreadHandler.obtainMessage(command, request);
3178 msg.sendToTarget();
3179
Rambo Wang0f050d82021-02-12 11:43:36 -08003180
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003181 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08003182 if (timeoutInMs >= 0) {
3183 // Wait for at least timeoutInMs before returning null request result
3184 long now = SystemClock.elapsedRealtime();
3185 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07003186 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08003187 try {
3188 request.wait(deadline - now);
3189 } catch (InterruptedException e) {
3190 // Do nothing, go back and check if request is completed or timeout
3191 } finally {
3192 now = SystemClock.elapsedRealtime();
3193 }
3194 }
3195 } else {
3196 // Wait for the request to complete
3197 while (request.result == null) {
3198 try {
3199 request.wait();
3200 } catch (InterruptedException e) {
3201 // Do nothing, go back and wait until the request is complete
3202 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003203 }
3204 }
3205 }
Rambo Wang0f050d82021-02-12 11:43:36 -08003206 if (request.result == null) {
3207 Log.wtf(LOG_TAG,
3208 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
3209 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003210 return request.result;
3211 }
3212
3213 /**
3214 * Asynchronous ("fire and forget") version of sendRequest():
3215 * Posts the specified command to be executed on the main thread, and
3216 * returns immediately.
3217 * @see #sendRequest
3218 */
3219 private void sendRequestAsync(int command) {
3220 mMainThreadHandler.sendEmptyMessage(command);
3221 }
3222
3223 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003224 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003225 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003226 */
3227 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003228 sendRequestAsync(command, argument, null, null);
3229 }
3230
3231 /**
3232 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
3233 * @see {@link #sendRequest(int,Object)}
3234 */
3235 private void sendRequestAsync(
3236 int command, Object argument, Phone phone, WorkSource workSource) {
3237 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003238 Message msg = mMainThreadHandler.obtainMessage(command, request);
3239 msg.sendToTarget();
3240 }
3241
3242 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003243 * Initialize the singleton PhoneInterfaceManager instance.
3244 * This is only done once, at startup, from PhoneApp.onCreate().
3245 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003246 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003247 synchronized (PhoneInterfaceManager.class) {
3248 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003249 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003250 } else {
3251 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
3252 }
3253 return sInstance;
3254 }
3255 }
3256
3257 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00003258 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003259 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003260 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00003261 mImsResolver = ImsResolver.getInstance();
Sarah Chin4beb2b72023-02-14 14:47:54 -08003262 mSatelliteServiceController = SatelliteServiceController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07003263 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003264 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
3265 mMainThreadHandler = new MainThreadHandler();
Jack Yue37dd262022-12-16 11:53:37 -08003266 if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) {
3267 mSubscriptionController = SubscriptionController.getInstance();
3268 } else {
3269 mSubscriptionController = null;
3270 }
Sarah Chin4beb2b72023-02-14 14:47:54 -08003271 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07003272 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07003273 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08003274 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08003275 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07003276 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003277 publish();
arunvoddud7401012022-12-15 16:08:12 +00003278 CarrierAllowListInfo.loadInstance(mApp);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08003279 mSatelliteSupportedReceiver = new ResultReceiver(mMainThreadHandler) {
3280 @Override
3281 protected void onReceiveResult(int resultCode, Bundle resultData) {
3282 if (resultCode == SatelliteManager.SATELLITE_ERROR_NONE
3283 && resultData.containsKey(SatelliteManager.KEY_SATELLITE_SUPPORTED)) {
3284 synchronized (mIsSatelliteSupportedLock) {
3285 mIsSatelliteSupported = resultData.getBoolean(
3286 SatelliteManager.KEY_SATELLITE_SUPPORTED);
3287 }
3288 } else {
3289 synchronized (mIsSatelliteSupportedLock) {
3290 mIsSatelliteSupported = null;
3291 }
3292 }
3293 }
3294 };
3295 requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
3296 mSatelliteSupportedReceiver);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003297 }
3298
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003299 @VisibleForTesting
3300 public SharedPreferences getSharedPreferences() {
3301 return mTelephonySharedPreferences;
3302 }
3303
Gil Cukierman92cc7db2023-01-06 19:25:53 +00003304 /**
3305 * Get the default phone for this device.
3306 */
3307 @VisibleForTesting
3308 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003309 Phone thePhone = getPhone(getDefaultSubscription());
3310 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
3311 }
3312
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003313 private void publish() {
3314 if (DBG) log("publish: " + this);
3315
Peter Wangc035ce42020-01-08 21:00:22 -08003316 TelephonyFrameworkInitializer
3317 .getTelephonyServiceManager()
3318 .getTelephonyServiceRegisterer()
3319 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003320 }
3321
Stuart Scott584921c2015-01-15 17:10:34 -08003322 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08003323 if (request.phone != null) {
3324 return request.phone;
3325 } else {
3326 return getPhoneFromSubId(request.subId);
3327 }
3328 }
3329
3330 private Phone getPhoneFromSubId(int subId) {
3331 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
3332 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08003333 }
3334
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00003335 /**
3336 * Get phone object associated with a subscription.
3337 * Return default phone if phone object associated with subscription is null
3338 * @param subId - subscriptionId
3339 * @return phone object associated with a subscription or default phone if null.
3340 */
3341 private Phone getPhoneFromSubIdOrDefault(int subId) {
3342 Phone phone = getPhoneFromSubId(subId);
3343 if (phone == null) {
3344 phone = getDefaultPhone();
3345 }
3346 return phone;
3347 }
3348
Rambo Wange53e07d2022-05-10 13:01:13 -07003349 @Nullable
3350 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003351 Phone phone = getPhoneFromRequest(request);
3352 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00003353 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003354 }
3355
Wink Saville36469e72014-06-11 15:17:00 -07003356 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07003357 private Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08003358 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07003359 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003360
Kai Shif70f46f2021-03-03 13:59:46 -08003361 private void sendEraseModemConfig(@NonNull Phone phone) {
3362 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
3363 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
3364 }
3365
3366 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
3367 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
3368 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07003369 }
3370
Peter Wang44b186e2020-01-13 23:33:09 -08003371 private boolean isImsAvailableOnDevice() {
3372 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
3373 if (pm == null) {
3374 // For some reason package manger is not available.. This will fail internally anyway,
3375 // so do not throw error and allow.
3376 return true;
3377 }
3378 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
3379 }
3380
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003381 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003382 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07003383 }
3384
Wink Savilleb564aae2014-10-23 10:18:09 -07003385 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003386 if (DBG) log("dial: " + number);
3387 // No permission check needed here: This is just a wrapper around the
3388 // ACTION_DIAL intent, which is available to any app since it puts up
3389 // the UI before it does anything.
3390
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003391 final long identity = Binder.clearCallingIdentity();
3392 try {
3393 String url = createTelUrl(number);
3394 if (url == null) {
3395 return;
3396 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003398 // PENDING: should we just silently fail if phone is offhook or ringing?
3399 PhoneConstants.State state = mCM.getState(subId);
3400 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
3401 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
3402 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3403 mApp.startActivity(intent);
3404 }
3405 } finally {
3406 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003407 }
3408 }
3409
3410 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003411 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07003412 }
3413
Wink Savilleb564aae2014-10-23 10:18:09 -07003414 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003415 if (DBG) log("call: " + number);
3416
3417 // This is just a wrapper around the ACTION_CALL intent, but we still
3418 // need to do a permission check since we're calling startActivity()
3419 // from the context of the phone app.
3420 enforceCallPermission();
3421
Jordan Liu1617b712019-07-10 15:06:26 -07003422 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003423 != AppOpsManager.MODE_ALLOWED) {
3424 return;
3425 }
3426
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003427 final long identity = Binder.clearCallingIdentity();
3428 try {
3429 String url = createTelUrl(number);
3430 if (url == null) {
3431 return;
3432 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003433
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003434 boolean isValid = false;
3435 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
3436 if (slist != null) {
3437 for (SubscriptionInfo subInfoRecord : slist) {
3438 if (subInfoRecord.getSubscriptionId() == subId) {
3439 isValid = true;
3440 break;
3441 }
Wink Saville3ab207e2014-11-20 13:07:20 -08003442 }
Wink Saville08874612014-08-31 19:19:58 -07003443 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003444 if (!isValid) {
3445 return;
3446 }
Wink Saville08874612014-08-31 19:19:58 -07003447
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003448 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
3449 intent.putExtra(SUBSCRIPTION_KEY, subId);
3450 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3451 mApp.startActivity(intent);
3452 } finally {
3453 Binder.restoreCallingIdentity(identity);
3454 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003455 }
3456
Wink Savilleb564aae2014-10-23 10:18:09 -07003457 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003458 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07003459 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
3460 }
3461
Wink Savilleb564aae2014-10-23 10:18:09 -07003462 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003463 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07003464 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
3465 }
3466
Wink Savilleb564aae2014-10-23 10:18:09 -07003467 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003468 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003469
3470 final long identity = Binder.clearCallingIdentity();
3471 try {
Michele Berionne5e411512020-11-13 02:36:59 +00003472 Phone phone = getPhone(subId);
3473 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003474 checkSimPin.start();
3475 return checkSimPin.unlockSim(null, pin);
3476 } finally {
3477 Binder.restoreCallingIdentity(identity);
3478 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003479 }
3480
Wink Savilleb564aae2014-10-23 10:18:09 -07003481 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003482 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003483
3484 final long identity = Binder.clearCallingIdentity();
3485 try {
Michele Berionne5e411512020-11-13 02:36:59 +00003486 Phone phone = getPhone(subId);
3487 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003488 checkSimPuk.start();
3489 return checkSimPuk.unlockSim(puk, pin);
3490 } finally {
3491 Binder.restoreCallingIdentity(identity);
3492 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003493 }
3494
3495 /**
Wink Saville9de0f752013-10-22 19:04:03 -07003496 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003497 * a synchronous one.
3498 */
3499 private static class UnlockSim extends Thread {
3500
3501 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00003502 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003503
3504 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07003505 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
3506 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003507
3508 // For replies from SimCard interface
3509 private Handler mHandler;
3510
3511 // For async handler to identify request type
3512 private static final int SUPPLY_PIN_COMPLETE = 100;
3513
Michele Berionne5e411512020-11-13 02:36:59 +00003514 UnlockSim(int phoneId, IccCard simCard) {
3515 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003516 mSimCard = simCard;
3517 }
3518
3519 @Override
3520 public void run() {
3521 Looper.prepare();
3522 synchronized (UnlockSim.this) {
3523 mHandler = new Handler() {
3524 @Override
3525 public void handleMessage(Message msg) {
3526 AsyncResult ar = (AsyncResult) msg.obj;
3527 switch (msg.what) {
3528 case SUPPLY_PIN_COMPLETE:
3529 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
3530 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07003531 mRetryCount = msg.arg1;
3532 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08003533 CommandException.Error error = null;
3534 if (ar.exception instanceof CommandException) {
3535 error = ((CommandException) (ar.exception))
3536 .getCommandError();
3537 }
3538 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07003539 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08003540 } else if (error == CommandException.Error.ABORTED) {
3541 /* When UiccCardApp dispose, handle message and return
3542 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08003543 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07003544 } else {
3545 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
3546 }
3547 } else {
3548 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
3549 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003550 mDone = true;
3551 UnlockSim.this.notifyAll();
3552 }
3553 break;
3554 }
3555 }
3556 };
3557 UnlockSim.this.notifyAll();
3558 }
3559 Looper.loop();
3560 }
3561
3562 /*
3563 * Use PIN or PUK to unlock SIM card
3564 *
3565 * If PUK is null, unlock SIM card with PIN
3566 *
3567 * If PUK is not null, unlock SIM card with PUK and set PIN code
3568 */
Wink Saville9de0f752013-10-22 19:04:03 -07003569 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003570
3571 while (mHandler == null) {
3572 try {
3573 wait();
3574 } catch (InterruptedException e) {
3575 Thread.currentThread().interrupt();
3576 }
3577 }
3578 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
3579
3580 if (puk == null) {
3581 mSimCard.supplyPin(pin, callback);
3582 } else {
3583 mSimCard.supplyPuk(puk, pin, callback);
3584 }
3585
3586 while (!mDone) {
3587 try {
3588 Log.d(LOG_TAG, "wait for done");
3589 wait();
3590 } catch (InterruptedException e) {
3591 // Restore the interrupted status
3592 Thread.currentThread().interrupt();
3593 }
3594 }
3595 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07003596 int[] resultArray = new int[2];
3597 resultArray[0] = mResult;
3598 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00003599
3600 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00003601 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00003602 }
3603
Wink Saville9de0f752013-10-22 19:04:03 -07003604 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003605 }
3606 }
3607
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003608 /**
3609 * This method has been removed due to privacy and stability concerns.
3610 */
3611 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003612 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003613 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
3614 return;
Wink Saville36469e72014-06-11 15:17:00 -07003615 }
3616
Nathan Harold1f889d82020-06-04 17:05:26 -07003617 @Override
3618 public void updateServiceLocationWithPackageName(String callingPackage) {
3619 mApp.getSystemService(AppOpsManager.class)
3620 .checkPackage(Binder.getCallingUid(), callingPackage);
3621
Nathan Haroldf096d982020-11-18 17:18:06 -08003622 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07003623 if (targetSdk > android.os.Build.VERSION_CODES.R) {
3624 // Callers targeting S have no business invoking this method.
3625 return;
3626 }
3627
3628 LocationAccessPolicy.LocationPermissionResult locationResult =
3629 LocationAccessPolicy.checkLocationPermission(mApp,
3630 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3631 .setCallingPackage(callingPackage)
3632 .setCallingFeatureId(null)
3633 .setCallingPid(Binder.getCallingPid())
3634 .setCallingUid(Binder.getCallingUid())
3635 .setMethod("updateServiceLocation")
3636 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3637 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3638 .build());
3639 // Apps that lack location permission have no business calling this method;
3640 // however, because no permission was declared in the public API, denials must
3641 // all be "soft".
3642 switch (locationResult) {
3643 case DENIED_HARD: /* fall through */
3644 case DENIED_SOFT:
3645 return;
3646 }
3647
3648 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003649 final long identity = Binder.clearCallingIdentity();
3650 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07003651 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003652 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07003653 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003654 }
3655 } finally {
3656 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003658 }
3659
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003660 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003661 @Override
3662 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003663 return isRadioOnWithFeature(callingPackage, null);
3664 }
3665
3666
3667 @Override
3668 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
3669 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
3670 callingFeatureId);
3671 }
3672
3673 @Deprecated
3674 @Override
3675 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
3676 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07003677 }
3678
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003679 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003680 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
3681 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003682 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003683 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003684 return false;
3685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003686
3687 final long identity = Binder.clearCallingIdentity();
3688 try {
3689 return isRadioOnForSubscriber(subId);
3690 } finally {
3691 Binder.restoreCallingIdentity(identity);
3692 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003693 }
3694
3695 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003696 final long identity = Binder.clearCallingIdentity();
3697 try {
3698 final Phone phone = getPhone(subId);
3699 if (phone != null) {
3700 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
3701 } else {
3702 return false;
3703 }
3704 } finally {
3705 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003706 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003707 }
3708
3709 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003710 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003711 }
Wink Saville36469e72014-06-11 15:17:00 -07003712
Wink Savilleb564aae2014-10-23 10:18:09 -07003713 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003714 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003715
3716 final long identity = Binder.clearCallingIdentity();
3717 try {
3718 final Phone phone = getPhone(subId);
3719 if (phone != null) {
3720 phone.setRadioPower(!isRadioOnForSubscriber(subId));
3721 }
3722 } finally {
3723 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003724 }
Wink Saville36469e72014-06-11 15:17:00 -07003725 }
3726
3727 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003728 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07003729 }
3730
Wink Savilleb564aae2014-10-23 10:18:09 -07003731 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07003732 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003733
3734 final long identity = Binder.clearCallingIdentity();
3735 try {
3736 final Phone phone = getPhone(subId);
3737 if (phone == null) {
3738 return false;
3739 }
3740 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
3741 toggleRadioOnOffForSubscriber(subId);
3742 }
3743 return true;
3744 } finally {
3745 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003746 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003747 }
Wink Saville36469e72014-06-11 15:17:00 -07003748
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003749 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08003750 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003751 /*
3752 * If any of the Radios are available, it will need to be
3753 * shutdown. So return true if any Radio is available.
3754 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003755 final long identity = Binder.clearCallingIdentity();
3756 try {
3757 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3758 Phone phone = PhoneFactory.getPhone(i);
3759 if (phone != null && phone.isRadioAvailable()) return true;
3760 }
3761 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3762 return false;
3763 } finally {
3764 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003765 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003766 }
3767
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003768 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003769 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003770 enforceModifyPermission();
3771
3772 final long identity = Binder.clearCallingIdentity();
3773 try {
3774 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3775 logv("Shutting down Phone " + i);
3776 shutdownRadioUsingPhoneId(i);
3777 }
3778 } finally {
3779 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003780 }
3781 }
3782
3783 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003784 Phone phone = PhoneFactory.getPhone(phoneId);
3785 if (phone != null && phone.isRadioAvailable()) {
3786 phone.shutdownRadio();
3787 }
3788 }
3789
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003790 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003791 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003792
Ling Ma83dc5ea2023-01-12 15:06:04 -08003793 if (!turnOn) {
3794 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3795 }
3796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003797 final long identity = Binder.clearCallingIdentity();
3798 try {
3799 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3800 if (defaultPhone != null) {
3801 defaultPhone.setRadioPower(turnOn);
3802 return true;
3803 } else {
3804 loge("There's no default phone.");
3805 return false;
3806 }
3807 } finally {
3808 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003809 }
Wink Saville36469e72014-06-11 15:17:00 -07003810 }
3811
Wink Savilleb564aae2014-10-23 10:18:09 -07003812 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003813 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003814
Ling Ma83dc5ea2023-01-12 15:06:04 -08003815 if (!turnOn) {
3816 log("setRadioPowerForSubscriber off: subId=" + subId
3817 + ",callingPackage=" + getCurrentPackageName());
3818 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003819 final long identity = Binder.clearCallingIdentity();
3820 try {
3821 final Phone phone = getPhone(subId);
3822 if (phone != null) {
3823 phone.setRadioPower(turnOn);
3824 return true;
3825 } else {
3826 return false;
3827 }
3828 } finally {
3829 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003830 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003831 }
3832
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003833 /**
3834 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3835 * no reason to power it off. When any of the voters want to power it off, it will be turned
3836 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3837 * powering it off, and these radio off votes will be cleared.
3838 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3839 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3840 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3841 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3842 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3843 * check its vote.
3844 *
3845 * @param subId The subscription ID.
3846 * @param reason The reason for powering off radio.
3847 * @return true on success and false on failure.
3848 */
3849 public boolean requestRadioPowerOffForReason(int subId,
3850 @TelephonyManager.RadioPowerReason int reason) {
3851 enforceModifyPermission();
3852
Ling Ma83dc5ea2023-01-12 15:06:04 -08003853 log("requestRadioPowerOffForReason: subId=" + subId
3854 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003855 final long identity = Binder.clearCallingIdentity();
3856 try {
3857 final Phone phone = getPhone(subId);
3858 if (phone != null) {
3859 phone.setRadioPowerForReason(false, reason);
3860 return true;
3861 } else {
3862 return false;
3863 }
3864 } finally {
3865 Binder.restoreCallingIdentity(identity);
3866 }
3867 }
3868
3869 /**
3870 * Remove the vote on powering off the radio for a reason, as requested by
3871 * {@link requestRadioPowerOffForReason}.
3872 *
3873 * @param subId The subscription ID.
3874 * @param reason The reason for powering off radio.
3875 * @return true on success and false on failure.
3876 */
3877 public boolean clearRadioPowerOffForReason(int subId,
3878 @TelephonyManager.RadioPowerReason int reason) {
3879 enforceModifyPermission();
3880
3881 final long identity = Binder.clearCallingIdentity();
3882 try {
3883 final Phone phone = getPhone(subId);
3884 if (phone != null) {
3885 phone.setRadioPowerForReason(true, reason);
3886 return true;
3887 } else {
3888 return false;
3889 }
3890 } finally {
3891 Binder.restoreCallingIdentity(identity);
3892 }
3893 }
3894
3895 /**
3896 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3897 *
3898 * @param subId The subscription ID.
3899 * @param callingPackage The package making the call.
3900 * @param callingFeatureId The feature in the package.
3901 * @return List of reasons for powering off radio.
3902 */
3903 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3904 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3905
3906 final long identity = Binder.clearCallingIdentity();
3907 List result = new ArrayList();
3908 try {
3909 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3910 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3911 return result;
3912 }
3913
3914 final Phone phone = getPhone(subId);
3915 if (phone != null) {
3916 result.addAll(phone.getRadioPowerOffReasons());
3917 }
3918 } finally {
3919 Binder.restoreCallingIdentity(identity);
3920 }
3921 return result;
3922 }
3923
Wink Saville36469e72014-06-11 15:17:00 -07003924 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003925 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003926 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003927 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003928
3929 final long identity = Binder.clearCallingIdentity();
3930 try {
Jack Yu285100e2022-12-02 22:48:35 -08003931 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003932 final Phone phone = getPhone(subId);
3933 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003934 phone.getDataSettingsManager().setDataEnabled(
3935 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003936 return true;
3937 } else {
3938 return false;
3939 }
3940 } finally {
3941 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003942 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003943 }
3944
Wink Saville36469e72014-06-11 15:17:00 -07003945 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003946 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003947 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003948 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003949
3950 final long identity = Binder.clearCallingIdentity();
3951 try {
Jack Yu285100e2022-12-02 22:48:35 -08003952 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003953 final Phone phone = getPhone(subId);
3954 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003955 phone.getDataSettingsManager().setDataEnabled(
3956 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003957 return true;
3958 } else {
3959 return false;
3960 }
3961 } finally {
3962 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003963 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003964 }
3965
Sanket Padawe356d7632015-06-22 14:03:32 -07003966 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003967 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003968 final long identity = Binder.clearCallingIdentity();
3969 try {
3970 final Phone phone = getPhone(subId);
3971 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003972 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003973 } else {
3974 return false;
3975 }
3976 } finally {
3977 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003978 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003979 }
3980
3981 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003982 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003983 }
3984
pkanwarae03a6b2016-11-06 20:37:09 -08003985 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003986 enforceCallPermission();
3987
3988 final long identity = Binder.clearCallingIdentity();
3989 try {
3990 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3991 return;
3992 }
3993 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3994 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3995 } finally {
3996 Binder.restoreCallingIdentity(identity);
3997 }
pkanwar32d516d2016-10-14 19:37:38 -07003998 };
3999
Wink Savilleb564aae2014-10-23 10:18:09 -07004000 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004001 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004002
4003 final long identity = Binder.clearCallingIdentity();
4004 try {
4005 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4006 return false;
4007 }
4008 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
4009 } finally {
4010 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004011 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004012 }
4013
Brad Ebinger4f6208e2021-03-23 21:04:45 +00004014 /**
4015 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
4016 * tag on getCallState Binder call.
4017 */
4018 @Deprecated
4019 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004020 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00004021 if (CompatChanges.isChangeEnabled(
4022 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
4023 Binder.getCallingUid())) {
4024 // Do not allow this API to be called on API version 31+, it should only be
4025 // called on old apps using this Binder call directly.
4026 throw new SecurityException("This method can only be used for applications "
4027 + "targeting API version 30 or less.");
4028 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004029 final long identity = Binder.clearCallingIdentity();
4030 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00004031 Phone phone = getPhone(getDefaultSubscription());
4032 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
4033 PhoneConstantConversions.convertCallState(phone.getState());
4034 } finally {
4035 Binder.restoreCallingIdentity(identity);
4036 }
4037 }
4038
4039 @Override
4040 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
4041 if (CompatChanges.isChangeEnabled(
4042 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
4043 Binder.getCallingUid())) {
4044 // Check READ_PHONE_STATE for API version 31+
4045 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4046 featureId, "getCallStateForSubscription")) {
4047 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
4048 + "targeting API level 31+.");
4049 }
4050 }
4051 final long identity = Binder.clearCallingIdentity();
4052 try {
4053 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004054 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
4055 PhoneConstantConversions.convertCallState(phone.getState());
4056 } finally {
4057 Binder.restoreCallingIdentity(identity);
4058 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004059 }
4060
Sanket Padawe356d7632015-06-22 14:03:32 -07004061 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00004062 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08004063 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07004064 }
4065
4066 @Override
4067 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004068 final long identity = Binder.clearCallingIdentity();
4069 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07004070 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004071 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07004072 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004073 } else {
4074 return PhoneConstantConversions.convertDataState(
4075 PhoneConstants.DataState.DISCONNECTED);
4076 }
4077 } finally {
4078 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004079 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004080 }
4081
Sanket Padawe356d7632015-06-22 14:03:32 -07004082 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07004083 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08004084 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07004085 }
4086
4087 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07004088 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004089 final long identity = Binder.clearCallingIdentity();
4090 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07004091 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004092 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07004093 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004094 } else {
4095 return TelephonyManager.DATA_ACTIVITY_NONE;
4096 }
4097 } finally {
4098 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004099 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004100 }
4101
4102 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08004103 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004104 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08004105 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08004106
4107 LocationAccessPolicy.LocationPermissionResult locationResult =
4108 LocationAccessPolicy.checkLocationPermission(mApp,
4109 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4110 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004111 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004112 .setCallingPid(Binder.getCallingPid())
4113 .setCallingUid(Binder.getCallingUid())
4114 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08004115 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08004116 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4117 .build());
4118 switch (locationResult) {
4119 case DENIED_HARD:
4120 throw new SecurityException("Not allowed to access cell location");
4121 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08004122 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
4123 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004124 }
4125
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004126 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004127 final long identity = Binder.clearCallingIdentity();
4128 try {
4129 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08004130 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08004131 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004132 } finally {
4133 Binder.restoreCallingIdentity(identity);
4134 }
Svetoslav64fad262015-04-14 14:35:21 -07004135 }
4136
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004137 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08004138 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07004139 // Reporting the correct network country is ambiguous when IWLAN could conflict with
4140 // registered cell info, so return a NULL country instead.
4141 final long identity = Binder.clearCallingIdentity();
4142 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07004143 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
4144 // Get default phone in this case.
4145 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
4146 }
Jack Yu285100e2022-12-02 22:48:35 -08004147 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004148 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07004149 if (phone == null) return "";
4150 ServiceStateTracker sst = phone.getServiceStateTracker();
4151 if (sst == null) return "";
4152 LocaleTracker lt = sst.getLocaleTracker();
4153 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08004154 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07004155 } finally {
4156 Binder.restoreCallingIdentity(identity);
4157 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07004158 }
4159
Nathan Harold7c8d0f12020-05-28 20:40:31 -07004160 /**
4161 * This method was removed due to potential issues caused by performing partial
4162 * updates of service state, and lack of a credible use case.
4163 *
4164 * This has the ability to break the telephony implementation by disabling notification of
4165 * changes in device connectivity. DO NOT USE THIS!
4166 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07004167 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004168 public void enableLocationUpdates() {
4169 mApp.enforceCallingOrSelfPermission(
4170 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004171 }
4172
Nathan Harold7c8d0f12020-05-28 20:40:31 -07004173 /**
4174 * This method was removed due to potential issues caused by performing partial
4175 * updates of service state, and lack of a credible use case.
4176 *
4177 * This has the ability to break the telephony implementation by disabling notification of
4178 * changes in device connectivity. DO NOT USE THIS!
4179 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004180 @Override
4181 public void disableLocationUpdates() {
4182 mApp.enforceCallingOrSelfPermission(
4183 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004184 }
4185
4186 @Override
4187 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004188 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
4189 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07004190 try {
4191 mApp.getSystemService(AppOpsManager.class)
4192 .checkPackage(Binder.getCallingUid(), callingPackage);
4193 } catch (SecurityException e) {
4194 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
4195 throw e;
4196 }
4197
Nathan Haroldf096d982020-11-18 17:18:06 -08004198 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07004199 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
4200 throw new SecurityException(
4201 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
4202 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07004203
Jordan Liu1617b712019-07-10 15:06:26 -07004204 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004205 callingPackage) != AppOpsManager.MODE_ALLOWED) {
4206 return null;
4207 }
Svetoslav64fad262015-04-14 14:35:21 -07004208
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07004209 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004210
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004211 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07004212 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004213
Nathan Haroldf180aac2018-06-01 18:43:55 -07004214 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
4215 for (CellInfo ci : info) {
4216 if (ci instanceof CellInfoGsm) {
4217 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
4218 } else if (ci instanceof CellInfoWcdma) {
4219 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
4220 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004221 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07004222 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004223 }
4224
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004225 private List<CellInfo> getCachedCellInfo() {
4226 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
4227 for (Phone phone : PhoneFactory.getPhones()) {
4228 List<CellInfo> info = phone.getAllCellInfo();
4229 if (info != null) cellInfos.addAll(info);
4230 }
4231 return cellInfos;
4232 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004233
4234 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004235 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004236 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08004237 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08004238
4239 LocationAccessPolicy.LocationPermissionResult locationResult =
4240 LocationAccessPolicy.checkLocationPermission(mApp,
4241 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4242 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004243 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004244 .setCallingPid(Binder.getCallingPid())
4245 .setCallingUid(Binder.getCallingUid())
4246 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08004247 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08004248 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4249 .build());
4250 switch (locationResult) {
4251 case DENIED_HARD:
4252 throw new SecurityException("Not allowed to access cell info");
4253 case DENIED_SOFT:
4254 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004255 }
4256
Nathan Haroldf096d982020-11-18 17:18:06 -08004257 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004258 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
4259 return getCachedCellInfo();
4260 }
4261
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07004262 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004263 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004264 final long identity = Binder.clearCallingIdentity();
4265 try {
4266 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
4267 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07004268 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07004269 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004270 if (info != null) cellInfos.addAll(info);
4271 }
4272 return cellInfos;
4273 } finally {
4274 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004275 }
4276 }
4277
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07004278 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004279 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
4280 String callingFeatureId) {
4281 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
4282 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004283 }
4284
4285 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004286 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
4287 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004288 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004289 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004290 }
4291
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004292 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
4293 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004294 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004295 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08004296
4297 LocationAccessPolicy.LocationPermissionResult locationResult =
4298 LocationAccessPolicy.checkLocationPermission(mApp,
4299 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4300 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004301 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004302 .setCallingPid(Binder.getCallingPid())
4303 .setCallingUid(Binder.getCallingUid())
4304 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07004305 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
4306 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08004307 .build());
4308 switch (locationResult) {
4309 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08004310 if (TelephonyPermissions
4311 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07004312 // Safetynet logging for b/154934934
4313 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
4314 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004315 throw new SecurityException("Not allowed to access cell info");
4316 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08004317 if (TelephonyPermissions
4318 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07004319 // Safetynet logging for b/154934934
4320 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
4321 }
Nathan Harold5320c422019-05-09 10:26:08 -07004322 try {
4323 cb.onCellInfo(new ArrayList<CellInfo>());
4324 } catch (RemoteException re) {
4325 // Drop without consequences
4326 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004327 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004328 }
4329
Nathan Harolda939a962019-05-09 10:13:47 -07004330
4331 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004332 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
4333
4334 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
4335 }
4336
4337 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00004338 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08004339 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004340 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004341
4342 final long identity = Binder.clearCallingIdentity();
4343 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00004344 Phone phone = getPhone(subId);
4345 if (phone == null) {
4346 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
4347 } else {
4348 phone.setCellInfoListRate(rateInMillis, workSource);
4349 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004350 } finally {
4351 Binder.restoreCallingIdentity(identity);
4352 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004353 }
4354
Shishir Agrawala9f32182016-04-12 12:00:16 -07004355 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004356 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004357 Phone phone = PhoneFactory.getPhone(slotIndex);
4358 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004359 return null;
4360 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004361 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07004362 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07004363 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004364 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004365 return null;
4366 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004367
4368 final long identity = Binder.clearCallingIdentity();
4369 try {
4370 return phone.getImei();
4371 } finally {
4372 Binder.restoreCallingIdentity(identity);
4373 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07004374 }
4375
4376 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00004377 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
4378 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
4379 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
4380 callingFeatureId, "getPrimaryImei")) {
4381 throw new SecurityException("Caller does not have permission");
4382 }
4383 final long identity = Binder.clearCallingIdentity();
4384 try {
4385 for (Phone phone : PhoneFactory.getPhones()) {
4386 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
4387 return phone.getImei();
4388 }
4389 }
4390 throw new UnsupportedOperationException("Operation not supported");
4391 } finally {
4392 Binder.restoreCallingIdentity(identity);
4393 }
4394 }
4395
4396 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00004397 public String getTypeAllocationCodeForSlot(int slotIndex) {
4398 Phone phone = PhoneFactory.getPhone(slotIndex);
4399 String tac = null;
4400 if (phone != null) {
4401 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07004402 try {
4403 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
4404 } catch (IndexOutOfBoundsException e) {
4405 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
4406 return null;
4407 }
David Kelly5e06a7f2018-03-12 14:10:59 +00004408 }
4409 return tac;
4410 }
4411
4412 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004413 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004414 try {
4415 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4416 } catch (SecurityException se) {
4417 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
4418 throw new SecurityException("Package " + callingPackage + " does not belong to "
4419 + Binder.getCallingUid());
4420 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004421 Phone phone = PhoneFactory.getPhone(slotIndex);
4422 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07004423 return null;
4424 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004425
Jeff Davidson913390f2018-02-23 17:11:49 -08004426 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07004427 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004428 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004429 return null;
4430 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004431
4432 final long identity = Binder.clearCallingIdentity();
4433 try {
4434 return phone.getMeid();
4435 } finally {
4436 Binder.restoreCallingIdentity(identity);
4437 }
Jack Yu2af8d712017-03-15 17:14:14 -07004438 }
4439
4440 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00004441 public String getManufacturerCodeForSlot(int slotIndex) {
4442 Phone phone = PhoneFactory.getPhone(slotIndex);
4443 String manufacturerCode = null;
4444 if (phone != null) {
4445 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07004446 try {
4447 manufacturerCode =
4448 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
4449 } catch (IndexOutOfBoundsException e) {
4450 Log.e(LOG_TAG, "MEID length shorter than upper index.");
4451 return null;
4452 }
David Kelly5e06a7f2018-03-12 14:10:59 +00004453 }
4454 return manufacturerCode;
4455 }
4456
4457 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004458 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
4459 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004460 Phone phone = PhoneFactory.getPhone(slotIndex);
4461 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004462 return null;
4463 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004464 int subId = phone.getSubId();
4465 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004466 mApp, subId, callingPackage, callingFeatureId,
4467 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004468 return null;
4469 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004470
4471 final long identity = Binder.clearCallingIdentity();
4472 try {
4473 return phone.getDeviceSvn();
4474 } finally {
4475 Binder.restoreCallingIdentity(identity);
4476 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07004477 }
4478
fionaxu43304da2017-11-27 22:51:16 -08004479 @Override
4480 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004481 final long identity = Binder.clearCallingIdentity();
4482 try {
4483 final Phone phone = getPhone(subId);
4484 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
4485 } finally {
4486 Binder.restoreCallingIdentity(identity);
4487 }
fionaxu43304da2017-11-27 22:51:16 -08004488 }
4489
4490 @Override
4491 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004492 final long identity = Binder.clearCallingIdentity();
4493 try {
4494 final Phone phone = getPhone(subId);
4495 return phone == null ? null : phone.getCarrierName();
4496 } finally {
4497 Binder.restoreCallingIdentity(identity);
4498 }
fionaxu43304da2017-11-27 22:51:16 -08004499 }
4500
calvinpanffe225e2018-11-01 19:43:06 +08004501 @Override
chen xu0026ca62019-03-06 15:28:50 -08004502 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08004503 final long identity = Binder.clearCallingIdentity();
4504 try {
4505 final Phone phone = getPhone(subId);
4506 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08004507 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08004508 } finally {
4509 Binder.restoreCallingIdentity(identity);
4510 }
4511 }
4512
4513 @Override
chen xu0026ca62019-03-06 15:28:50 -08004514 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08004515 final long identity = Binder.clearCallingIdentity();
4516 try {
4517 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08004518 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08004519 } finally {
4520 Binder.restoreCallingIdentity(identity);
4521 }
4522 }
4523
chen xu651eec72018-11-11 19:03:44 -08004524 @Override
chen xu864e11c2018-12-06 22:10:03 -08004525 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
4526 if (!isSubscriptionMccMnc) {
4527 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
4528 }
chen xu651eec72018-11-11 19:03:44 -08004529 final Phone phone = PhoneFactory.getPhone(slotIndex);
4530 if (phone == null) {
4531 return TelephonyManager.UNKNOWN_CARRIER_ID;
4532 }
4533 final long identity = Binder.clearCallingIdentity();
4534 try {
4535 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
4536 } finally {
4537 Binder.restoreCallingIdentity(identity);
4538 }
4539 }
4540
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004541 //
4542 // Internal helper methods.
4543 //
4544
Sanket Padaweee13a9b2016-03-08 17:30:28 -08004545 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07004546 * Make sure the caller is the calling package itself
4547 *
4548 * @throws SecurityException if the caller is not the calling package
4549 */
4550 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
4551 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07004552 PackageManager pm = mApp.getBaseContext().createContextAsUser(
4553 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07004554 try {
Grace Jiadbefca02021-04-26 15:13:31 -07004555 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07004556 } catch (PackageManager.NameNotFoundException e) {
4557 // packageUid is -1
4558 }
4559 if (packageUid != callingUid) {
4560 throw new SecurityException(message + ": Package " + callingPackage
4561 + " does not belong to " + callingUid);
4562 }
4563 }
4564
4565 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004566 * Make sure the caller has the MODIFY_PHONE_STATE permission.
4567 *
4568 * @throws SecurityException if the caller does not have the required permission
4569 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004570 @VisibleForTesting
4571 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004572 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
4573 }
4574
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004575 /**
arunvoddud7401012022-12-15 16:08:12 +00004576 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004577 *
4578 * @throws SecurityException if the caller does not have the required permission
4579 */
4580 @VisibleForTesting
4581 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00004582 enforceReadPermission(null);
4583 }
4584
4585 /**
4586 * Make sure the caller has the READ_PHONE_STATE permissions.
4587 *
4588 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
4589 */
4590 @VisibleForTesting
4591 public void enforceReadPermission(String msg) {
4592 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004593 }
4594
Shuo Qian3b6ee772019-11-13 17:43:31 -08004595 private void enforceActiveEmergencySessionPermission() {
4596 mApp.enforceCallingOrSelfPermission(
4597 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
4598 }
4599
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004600 /**
4601 * Make sure the caller has the CALL_PHONE permission.
4602 *
4603 * @throws SecurityException if the caller does not have the required permission
4604 */
4605 private void enforceCallPermission() {
4606 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
4607 }
4608
paulhu5a773602019-08-23 19:17:33 +08004609 private void enforceSettingsPermission() {
4610 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004611 }
4612
Michele Berionne5e411512020-11-13 02:36:59 +00004613 private void enforceRebootPermission() {
4614 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
4615 }
4616
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00004617 /**
4618 * Make sure the caller has SATELLITE_COMMUNICATION permission.
4619 * @param message - log message to print.
4620 * @throws SecurityException if the caller does not have the required permission
4621 */
4622 private void enforceSatelliteCommunicationPermission(String message) {
4623 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
4624 }
4625
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004626 private String createTelUrl(String number) {
4627 if (TextUtils.isEmpty(number)) {
4628 return null;
4629 }
4630
Jake Hambye994d462014-02-03 13:10:13 -08004631 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004632 }
4633
Ihab Awadf9e92732013-12-05 18:02:52 -08004634 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08004635 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004636 }
4637
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07004638 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08004639 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07004640 }
4641
Ihab Awadf9e92732013-12-05 18:02:52 -08004642 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08004643 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004644 }
4645
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004646 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004647 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07004648 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07004649 }
4650
Sanket Padawe356d7632015-06-22 14:03:32 -07004651 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004652 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004653 final long identity = Binder.clearCallingIdentity();
4654 try {
4655 final Phone phone = PhoneFactory.getPhone(slotIndex);
4656 if (phone == null) {
4657 return PhoneConstants.PHONE_TYPE_NONE;
4658 } else {
4659 return phone.getPhoneType();
4660 }
4661 } finally {
4662 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004663 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004664 }
4665
4666 /**
4667 * Returns the CDMA ERI icon index to display
4668 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004669 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004670 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
4671 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4672 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004673 }
4674
Sanket Padawe356d7632015-06-22 14:03:32 -07004675 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004676 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4677 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004678 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004679 mApp, subId, callingPackage, callingFeatureId,
4680 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004681 return -1;
4682 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004683
4684 final long identity = Binder.clearCallingIdentity();
4685 try {
4686 final Phone phone = getPhone(subId);
4687 if (phone != null) {
4688 return phone.getCdmaEriIconIndex();
4689 } else {
4690 return -1;
4691 }
4692 } finally {
4693 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004694 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004695 }
4696
4697 /**
4698 * Returns the CDMA ERI icon mode,
4699 * 0 - ON
4700 * 1 - FLASHING
4701 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004702 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004703 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4704 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4705 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004706 }
4707
Sanket Padawe356d7632015-06-22 14:03:32 -07004708 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004709 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4710 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004711 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004712 mApp, subId, callingPackage, callingFeatureId,
4713 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004714 return -1;
4715 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004716
4717 final long identity = Binder.clearCallingIdentity();
4718 try {
4719 final Phone phone = getPhone(subId);
4720 if (phone != null) {
4721 return phone.getCdmaEriIconMode();
4722 } else {
4723 return -1;
4724 }
4725 } finally {
4726 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004727 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004728 }
4729
4730 /**
4731 * Returns the CDMA ERI text,
4732 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004733 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004734 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4735 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4736 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004737 }
4738
Sanket Padawe356d7632015-06-22 14:03:32 -07004739 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004740 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4741 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004742 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004743 mApp, subId, callingPackage, callingFeatureId,
4744 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004745 return null;
4746 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004747
4748 final long identity = Binder.clearCallingIdentity();
4749 try {
4750 final Phone phone = getPhone(subId);
4751 if (phone != null) {
4752 return phone.getCdmaEriText();
4753 } else {
4754 return null;
4755 }
4756 } finally {
4757 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004758 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004759 }
4760
4761 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004762 * Returns the CDMA MDN.
4763 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004764 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004765 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4767 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004768
4769 final long identity = Binder.clearCallingIdentity();
4770 try {
4771 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004772 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004773 return phone.getLine1Number();
4774 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004775 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004776 return null;
4777 }
4778 } finally {
4779 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004780 }
4781 }
4782
4783 /**
4784 * Returns the CDMA MIN.
4785 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004786 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004787 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4789 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004790
4791 final long identity = Binder.clearCallingIdentity();
4792 try {
4793 final Phone phone = getPhone(subId);
4794 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4795 return phone.getCdmaMin();
4796 } else {
4797 return null;
4798 }
4799 } finally {
4800 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004801 }
4802 }
4803
Hall Liud892bec2018-11-30 14:51:45 -08004804 @Override
4805 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4806 INumberVerificationCallback callback, String callingPackage) {
4807 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4808 != PERMISSION_GRANTED) {
4809 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4810 }
4811 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4812
4813 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4814 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004815 throw new SecurityException("Calling package must be configured in the device config: "
4816 + "calling package: " + callingPackage
4817 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004818 }
4819
4820 if (range == null) {
4821 throw new NullPointerException("Range must be non-null");
4822 }
4823
4824 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004825 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004826
4827 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4828 }
4829
Junda Liuca05d5d2014-08-14 22:36:34 -07004830 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004831 * Returns true if CDMA provisioning needs to run.
4832 */
4833 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004834 final long identity = Binder.clearCallingIdentity();
4835 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004836 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004837 } finally {
4838 Binder.restoreCallingIdentity(identity);
4839 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004840 }
4841
4842 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004843 * Sets the voice mail number of a given subId.
4844 */
4845 @Override
4846 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004847 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4848 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004849
4850 final long identity = Binder.clearCallingIdentity();
4851 try {
4852 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4853 new Pair<String, String>(alphaTag, number), new Integer(subId));
4854 return success;
4855 } finally {
4856 Binder.restoreCallingIdentity(identity);
4857 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004858 }
4859
Ta-wei Yen87c49842016-05-13 21:19:52 -07004860 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004861 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4862 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004863 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4864 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004865 if (!TextUtils.equals(callingPackage, systemDialer)) {
4866 throw new SecurityException("caller must be system dialer");
4867 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004868
4869 final long identity = Binder.clearCallingIdentity();
4870 try {
4871 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4872 if (phoneAccountHandle == null) {
4873 return null;
4874 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004875 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004876 } finally {
4877 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004878 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004879 }
4880
4881 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004882 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4883 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004884 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004885 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004886 mApp, subId, callingPackage, callingFeatureId,
4887 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004888 return null;
4889 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004890
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004891 final long identity = Binder.clearCallingIdentity();
4892 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004893 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004894 } finally {
4895 Binder.restoreCallingIdentity(identity);
4896 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004897 }
4898
4899 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004900 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4901 VisualVoicemailSmsFilterSettings settings) {
4902 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004903
4904 final long identity = Binder.clearCallingIdentity();
4905 try {
4906 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004907 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004908 } finally {
4909 Binder.restoreCallingIdentity(identity);
4910 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004911 }
4912
4913 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004914 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4915 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004916
4917 final long identity = Binder.clearCallingIdentity();
4918 try {
4919 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004920 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004921 } finally {
4922 Binder.restoreCallingIdentity(identity);
4923 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004924 }
4925
4926 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004927 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4928 String callingPackage, int subId) {
4929 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004930
4931 final long identity = Binder.clearCallingIdentity();
4932 try {
4933 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004934 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004935 } finally {
4936 Binder.restoreCallingIdentity(identity);
4937 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004938 }
4939
4940 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004941 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004942 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004943
4944 final long identity = Binder.clearCallingIdentity();
4945 try {
4946 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004947 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004948 } finally {
4949 Binder.restoreCallingIdentity(identity);
4950 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004951 }
4952
4953 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004954 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4955 String callingAttributionTag, int subId, String number, int port, String text,
4956 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004957 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004958 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004959 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004960 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004961 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4962 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004963 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004964
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004965 /**
fionaxu0152e512016-11-14 13:36:14 -08004966 * Sets the voice activation state of a given subId.
4967 */
4968 @Override
4969 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004970 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4971 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004972
4973 final long identity = Binder.clearCallingIdentity();
4974 try {
4975 final Phone phone = getPhone(subId);
4976 if (phone != null) {
4977 phone.setVoiceActivationState(activationState);
4978 } else {
4979 loge("setVoiceActivationState fails with invalid subId: " + subId);
4980 }
4981 } finally {
4982 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004983 }
4984 }
4985
4986 /**
4987 * Sets the data activation state of a given subId.
4988 */
4989 @Override
4990 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004991 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4992 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004993
4994 final long identity = Binder.clearCallingIdentity();
4995 try {
4996 final Phone phone = getPhone(subId);
4997 if (phone != null) {
4998 phone.setDataActivationState(activationState);
4999 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09005000 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005001 }
5002 } finally {
5003 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08005004 }
5005 }
5006
5007 /**
5008 * Returns the voice activation state of a given subId.
5009 */
5010 @Override
5011 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005012 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005013
fionaxu0152e512016-11-14 13:36:14 -08005014 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005015 final long identity = Binder.clearCallingIdentity();
5016 try {
5017 if (phone != null) {
5018 return phone.getVoiceActivationState();
5019 } else {
5020 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
5021 }
5022 } finally {
5023 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08005024 }
5025 }
5026
5027 /**
5028 * Returns the data activation state of a given subId.
5029 */
5030 @Override
5031 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005032 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005033
fionaxu0152e512016-11-14 13:36:14 -08005034 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005035 final long identity = Binder.clearCallingIdentity();
5036 try {
5037 if (phone != null) {
5038 return phone.getDataActivationState();
5039 } else {
5040 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
5041 }
5042 } finally {
5043 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08005044 }
5045 }
5046
5047 /**
Wink Saville36469e72014-06-11 15:17:00 -07005048 * Returns the unread count of voicemails for a subId
5049 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005050 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005051 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
5052 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08005053 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005054 mApp, subId, callingPackage, callingFeatureId,
5055 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08005056 return 0;
5057 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005058 final long identity = Binder.clearCallingIdentity();
5059 try {
5060 final Phone phone = getPhone(subId);
5061 if (phone != null) {
5062 return phone.getVoiceMessageCount();
5063 } else {
5064 return 0;
5065 }
5066 } finally {
5067 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005068 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005069 }
5070
5071 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005072 * returns true, if the device is in a state where both voice and data
5073 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08005074 */
5075 @Override
5076 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005077 final long identity = Binder.clearCallingIdentity();
5078 try {
5079 final Phone phone = getPhone(subId);
5080 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
5081 } finally {
5082 Binder.restoreCallingIdentity(identity);
5083 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08005084 }
5085
5086 /**
fionaxu235cc5e2017-03-06 22:25:57 -08005087 * Send the dialer code if called from the current default dialer or the caller has
5088 * carrier privilege.
5089 * @param inputCode The dialer code to send
5090 */
5091 @Override
5092 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005093 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08005094 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07005095 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
5096 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08005097 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005098 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005099 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08005100 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005101
5102 final long identity = Binder.clearCallingIdentity();
5103 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005104 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005105 } finally {
5106 Binder.restoreCallingIdentity(identity);
5107 }
fionaxu235cc5e2017-03-06 22:25:57 -08005108 }
5109
Pengquan Menga1bb6272018-09-06 09:59:22 -07005110 @Override
5111 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08005112 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005113 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5114 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08005115 final long identity = Binder.clearCallingIdentity();
5116 try {
5117 if (!isActiveSubscription(subId)) {
5118 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
5119 }
5120 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
5121 } finally {
5122 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07005123 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005124 }
5125
Brad Ebinger35c841c2018-10-01 10:40:55 -07005126 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07005127 public boolean isInEmergencySmsMode() {
5128 enforceReadPrivilegedPermission("isInEmergencySmsMode");
5129 final long identity = Binder.clearCallingIdentity();
5130 try {
5131 for (Phone phone : PhoneFactory.getPhones()) {
5132 if (phone.isInEmergencySmsMode()) {
5133 return true;
5134 }
5135 }
5136 } finally {
5137 Binder.restoreCallingIdentity(identity);
5138 }
5139 return false;
5140 }
5141
shilu366312e2019-12-17 09:28:10 -08005142 /**
5143 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5144 * @param subId The subscription to use to check the configuration.
5145 * @param c The callback that will be used to send the result.
5146 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07005147 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005148 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
5149 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07005150 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005151 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00005152
5153 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5154 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5155 "IMS not available on device.");
5156 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07005157 final long token = Binder.clearCallingIdentity();
5158 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005159 int slotId = getSlotIndexOrException(subId);
5160 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00005161
5162 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5163 if (controller != null) {
5164 ImsManager imsManager = controller.getImsManager(subId);
5165 if (imsManager != null) {
5166 imsManager.addRegistrationCallbackForSubscription(c, subId);
5167 } else {
5168 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5169 }
5170 } else {
5171 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5172 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005173 } catch (ImsException e) {
5174 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005175 } finally {
5176 Binder.restoreCallingIdentity(token);
5177 }
5178 }
5179
shilu366312e2019-12-17 09:28:10 -08005180 /**
5181 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5182 * @param subId The subscription to use to check the configuration.
5183 * @param c The callback that will be used to send the result.
5184 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005185 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005186 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07005187 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005188 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005189 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5190 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5191 }
Meng Wangafbc5852019-09-19 17:37:13 -07005192 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00005193
Meng Wangafbc5852019-09-19 17:37:13 -07005194 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00005195 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5196 if (controller != null) {
5197 ImsManager imsManager = controller.getImsManager(subId);
5198 if (imsManager != null) {
5199 imsManager.removeRegistrationCallbackForSubscription(c, subId);
5200 } else {
5201 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
5202 + "is inactive, ignoring unregister.");
5203 // If the ImsManager is not valid, just return, since the callback
5204 // will already have been removed internally.
5205 }
5206 }
Meng Wangafbc5852019-09-19 17:37:13 -07005207 } finally {
5208 Binder.restoreCallingIdentity(token);
5209 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07005210 }
5211
Brad Ebingera34a6c22019-10-22 17:36:18 -07005212 /**
5213 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
5214 */
5215 @Override
5216 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
5217 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
5218 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5219 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5220 "IMS not available on device.");
5221 }
5222 final long token = Binder.clearCallingIdentity();
5223 try {
5224 Phone phone = getPhone(subId);
5225 if (phone == null) {
5226 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
5227 + subId + "'");
5228 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5229 }
5230 phone.getImsRegistrationState(regState -> {
5231 try {
5232 consumer.accept((regState == null)
5233 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
5234 } catch (RemoteException e) {
5235 // Ignore if the remote process is no longer available to call back.
5236 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
5237 }
5238 });
5239 } finally {
5240 Binder.restoreCallingIdentity(token);
5241 }
5242 }
5243
5244 /**
5245 * Get the transport type for the IMS service registration state.
5246 */
5247 @Override
5248 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07005249 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005250 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07005251 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5252 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5253 "IMS not available on device.");
5254 }
5255 final long token = Binder.clearCallingIdentity();
5256 try {
5257 Phone phone = getPhone(subId);
5258 if (phone == null) {
5259 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
5260 + subId + "'");
5261 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5262 }
5263 phone.getImsRegistrationTech(regTech -> {
5264 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
5265 int regTechConverted = (regTech == null)
5266 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
5267 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
5268 regTechConverted);
5269 try {
5270 consumer.accept(regTechConverted);
5271 } catch (RemoteException e) {
5272 // Ignore if the remote process is no longer available to call back.
5273 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
5274 }
5275 });
5276 } finally {
5277 Binder.restoreCallingIdentity(token);
5278 }
5279 }
5280
shilu366312e2019-12-17 09:28:10 -08005281 /**
5282 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5283 * @param subId The subscription to use to check the configuration.
5284 * @param c The callback that will be used to send the result.
5285 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005286 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005287 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
5288 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07005289 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005290 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00005291 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5292 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5293 "IMS not available on device.");
5294 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07005295 final long token = Binder.clearCallingIdentity();
5296 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005297 int slotId = getSlotIndexOrException(subId);
5298 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005299
5300 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5301 if (controller != null) {
5302 ImsManager imsManager = controller.getImsManager(subId);
5303 if (imsManager != null) {
5304 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
5305 } else {
5306 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5307 }
5308 } else {
5309 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5310 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005311 } catch (ImsException e) {
5312 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005313 } finally {
5314 Binder.restoreCallingIdentity(token);
5315 }
5316 }
5317
shilu366312e2019-12-17 09:28:10 -08005318 /**
5319 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5320 * @param subId The subscription to use to check the configuration.
5321 * @param c The callback that will be used to send the result.
5322 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005323 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005324 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07005325 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005326 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005327 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5328 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5329 }
Meng Wangafbc5852019-09-19 17:37:13 -07005330
5331 final long token = Binder.clearCallingIdentity();
5332 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005333 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5334 if (controller != null) {
5335 ImsManager imsManager = controller.getImsManager(subId);
5336 if (imsManager != null) {
5337 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
5338 } else {
5339 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
5340 + " is inactive, ignoring unregister.");
5341 // If the ImsManager is not valid, just return, since the callback
5342 // will already have been removed internally.
5343 }
5344 }
Meng Wangafbc5852019-09-19 17:37:13 -07005345 } finally {
5346 Binder.restoreCallingIdentity(token);
5347 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07005348 }
5349
5350 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005351 public boolean isCapable(int subId, int capability, int regTech) {
5352 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005353 final long token = Binder.clearCallingIdentity();
5354 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005355 int slotId = getSlotIndexOrException(subId);
5356 verifyImsMmTelConfiguredOrThrow(slotId);
5357 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
5358 } catch (com.android.ims.ImsException e) {
5359 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
5360 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005361 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08005362 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
5363 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07005364 } finally {
5365 Binder.restoreCallingIdentity(token);
5366 }
5367 }
5368
5369 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005370 public boolean isAvailable(int subId, int capability, int regTech) {
5371 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005372 final long token = Binder.clearCallingIdentity();
5373 try {
5374 Phone phone = getPhone(subId);
5375 if (phone == null) return false;
5376 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07005377 } catch (com.android.ims.ImsException e) {
5378 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
5379 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07005380 } finally {
5381 Binder.restoreCallingIdentity(token);
5382 }
5383 }
5384
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005385 /**
5386 * Determines if the MmTel feature capability is supported by the carrier configuration for this
5387 * subscription.
5388 * @param subId The subscription to use to check the configuration.
5389 * @param callback The callback that will be used to send the result.
5390 * @param capability The MmTelFeature capability that will be used to send the result.
5391 * @param transportType The transport type of the MmTelFeature capability.
5392 */
5393 @Override
5394 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
5395 int transportType) {
5396 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00005397 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5398 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5399 "IMS not available on device.");
5400 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005401 final long token = Binder.clearCallingIdentity();
5402 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005403 int slotId = getSlotIndex(subId);
5404 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5405 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
5406 + subId + "'");
5407 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5408 }
5409 verifyImsMmTelConfiguredOrThrow(slotId);
5410 ImsManager.getInstance(mApp, slotId).isSupported(capability,
5411 transportType, aBoolean -> {
5412 try {
5413 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
5414 } catch (RemoteException e) {
5415 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
5416 + "running. Ignore");
5417 }
5418 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005419 } catch (ImsException e) {
5420 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005421 } finally {
5422 Binder.restoreCallingIdentity(token);
5423 }
5424 }
5425
shilu366312e2019-12-17 09:28:10 -08005426 /**
5427 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5428 * @param subId The subscription to use to check the configuration.
5429 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005430 @Override
5431 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005432 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005433 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08005434
Brad Ebinger35c841c2018-10-01 10:40:55 -07005435 final long token = Binder.clearCallingIdentity();
5436 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005437 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005438 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005439 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005440 } catch (ImsException e) {
5441 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005442 } finally {
5443 Binder.restoreCallingIdentity(token);
5444 }
5445 }
5446
5447 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005448 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005449 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005450 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005451 final long identity = Binder.clearCallingIdentity();
5452 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005453 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005454 // This setting doesn't require an active ImsService connection, so do not verify. The
5455 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005456 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005457 } catch (ImsException e) {
5458 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005459 } finally {
5460 Binder.restoreCallingIdentity(identity);
5461 }
5462 }
5463
shilu366312e2019-12-17 09:28:10 -08005464 /**
5465 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5466 * @param subId The subscription to use to check the configuration.
5467 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005468 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005469 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005470 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005471 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005472 final long identity = Binder.clearCallingIdentity();
5473 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005474 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005475 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005476 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
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
5484 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005485 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005486 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005487 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005488 final long identity = Binder.clearCallingIdentity();
5489 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005490 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005491 // This setting doesn't require an active ImsService connection, so do not verify. The
5492 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005493 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005494 } catch (ImsException e) {
5495 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005496 } finally {
5497 Binder.restoreCallingIdentity(identity);
5498 }
5499 }
5500
shilu366312e2019-12-17 09:28:10 -08005501 /**
5502 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5503 * @param subId The subscription to use to check the configuration.
5504 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005505 @Override
5506 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005507 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005508 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005509 final long identity = Binder.clearCallingIdentity();
5510 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005511 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005512 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005513 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005514 } catch (ImsException e) {
5515 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005516 } finally {
5517 Binder.restoreCallingIdentity(identity);
5518 }
5519 }
5520
5521 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005522 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005523 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005524 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005525 final long identity = Binder.clearCallingIdentity();
5526 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005527 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005528 // This setting doesn't require an active ImsService connection, so do not verify. The
5529 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005530 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005531 } catch (ImsException e) {
5532 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005533 } finally {
5534 Binder.restoreCallingIdentity(identity);
5535 }
5536 }
5537
shilu366312e2019-12-17 09:28:10 -08005538 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005539 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5540 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5541 * @param subId The subscription to use to check the configuration.
5542 */
5543 @Override
5544 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005545 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005546 mApp, subId, "isCrossSimCallingEnabledByUser");
5547 final long identity = Binder.clearCallingIdentity();
5548 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005549 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005550 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005551 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005552 } catch (ImsException e) {
5553 throw new ServiceSpecificException(e.getCode());
5554 } finally {
5555 Binder.restoreCallingIdentity(identity);
5556 }
5557 }
5558
5559 /**
5560 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5561 * Requires MODIFY_PHONE_STATE permission.
5562 * @param subId The subscription to use to check the configuration.
5563 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5564 * false otherwise
5565 */
5566 @Override
5567 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5568 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5569 "setCrossSimCallingEnabled");
5570 final long identity = Binder.clearCallingIdentity();
5571 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005572 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005573 // This setting doesn't require an active ImsService connection, so do not verify. The
5574 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005575 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005576 } catch (ImsException e) {
5577 throw new ServiceSpecificException(e.getCode());
5578 } finally {
5579 Binder.restoreCallingIdentity(identity);
5580 }
5581 }
5582
5583 /**
shilu366312e2019-12-17 09:28:10 -08005584 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5585 * @param subId The subscription to use to check the configuration.
5586 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005587 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005588
Brad Ebinger35c841c2018-10-01 10:40:55 -07005589 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005590 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005591 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005592 final long identity = Binder.clearCallingIdentity();
5593 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005594 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005595 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005596 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005597 } catch (ImsException e) {
5598 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005599 } finally {
5600 Binder.restoreCallingIdentity(identity);
5601 }
5602 }
5603
5604 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005605 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005606 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005607 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005608 final long identity = Binder.clearCallingIdentity();
5609 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005610 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005611 // This setting doesn't require an active ImsService connection, so do not verify. The
5612 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005613 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005614 } catch (ImsException e) {
5615 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005616 } finally {
5617 Binder.restoreCallingIdentity(identity);
5618 }
5619 }
5620
5621 @Override
5622 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5623 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5624 "setVoWiFiNonPersistent");
5625 final long identity = Binder.clearCallingIdentity();
5626 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005627 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005628 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005629 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005630 } catch (ImsException e) {
5631 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005632 } finally {
5633 Binder.restoreCallingIdentity(identity);
5634 }
5635 }
5636
shilu366312e2019-12-17 09:28:10 -08005637 /**
5638 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5639 * @param subId The subscription to use to check the configuration.
5640 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005641 @Override
5642 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005643 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005644 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005645 final long identity = Binder.clearCallingIdentity();
5646 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005647 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005648 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005649 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005650 } catch (ImsException e) {
5651 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005652 } finally {
5653 Binder.restoreCallingIdentity(identity);
5654 }
5655 }
5656
5657 @Override
5658 public void setVoWiFiModeSetting(int subId, int mode) {
5659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5660 "setVoWiFiModeSetting");
5661 final long identity = Binder.clearCallingIdentity();
5662 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005663 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005664 // This setting doesn't require an active ImsService connection, so do not verify. The
5665 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005666 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005667 } catch (ImsException e) {
5668 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005669 } finally {
5670 Binder.restoreCallingIdentity(identity);
5671 }
5672 }
5673
5674 @Override
5675 public int getVoWiFiRoamingModeSetting(int subId) {
5676 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
5677 final long identity = Binder.clearCallingIdentity();
5678 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005679 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005680 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005681 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005682 } catch (ImsException e) {
5683 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005684 } finally {
5685 Binder.restoreCallingIdentity(identity);
5686 }
5687 }
5688
5689 @Override
5690 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5691 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5692 "setVoWiFiRoamingModeSetting");
5693 final long identity = Binder.clearCallingIdentity();
5694 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005695 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005696 // This setting doesn't require an active ImsService connection, so do not verify. The
5697 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005698 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005699 } catch (ImsException e) {
5700 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005701 } finally {
5702 Binder.restoreCallingIdentity(identity);
5703 }
5704 }
5705
5706 @Override
5707 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5708 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5709 "setRttCapabilityEnabled");
5710 final long identity = Binder.clearCallingIdentity();
5711 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005712 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005713 // This setting doesn't require an active ImsService connection, so do not verify. The
5714 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005715 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005716 } catch (ImsException e) {
5717 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005718 } finally {
5719 Binder.restoreCallingIdentity(identity);
5720 }
5721 }
5722
shilu366312e2019-12-17 09:28:10 -08005723 /**
5724 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5725 * @param subId The subscription to use to check the configuration.
5726 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005727 @Override
5728 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005729 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005730 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005731 final long identity = Binder.clearCallingIdentity();
5732 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005733 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005734 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005735 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005736 } catch (ImsException e) {
5737 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005738 } finally {
5739 Binder.restoreCallingIdentity(identity);
5740 }
5741 }
5742
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005743 @Override
5744 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5745 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005746
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005747 final long identity = Binder.clearCallingIdentity();
5748 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005749 if (!isImsAvailableOnDevice()) {
5750 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5751 "IMS not available on device.");
5752 }
5753 int slotId = getSlotIndexOrException(subId);
5754 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005755
5756 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5757 if (controller != null) {
5758 ImsManager imsManager = controller.getImsManager(subId);
5759 if (imsManager != null) {
5760 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5761 } else {
5762 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5763 }
5764 } else {
5765 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5766 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005767 } catch (ImsException e) {
5768 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005769 } finally {
5770 Binder.restoreCallingIdentity(identity);
5771 }
5772 }
5773
5774 @Override
5775 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5776 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005777
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005778 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005779 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5780 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5781 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005782 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005783 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5784 if (controller != null) {
5785 ImsManager imsManager = controller.getImsManager(subId);
5786 if (imsManager != null) {
5787 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5788 } else {
5789 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5790 + " is inactive, ignoring unregister.");
5791 // If the ImsManager is not valid, just return, since the callback will already
5792 // have been removed internally.
5793 }
5794 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005795 } finally {
5796 Binder.restoreCallingIdentity(identity);
5797 }
5798 }
5799
joonhunshincffb7fc2021-11-28 07:32:01 +00005800 @Override
5801 public void registerFeatureProvisioningChangedCallback(int subId,
5802 IFeatureProvisioningCallback callback) {
5803 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5804 mApp, subId, "registerFeatureProvisioningChangedCallback");
5805
5806 final long identity = Binder.clearCallingIdentity();
5807 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5808 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5809 }
5810
joonhunshin91bc1952022-04-29 08:47:15 +00005811 try {
5812 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5813 if (controller == null) {
5814 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5815 "Device does not support IMS");
5816 }
5817 controller.addFeatureProvisioningChangedCallback(subId, callback);
5818 } finally {
5819 Binder.restoreCallingIdentity(identity);
5820 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005821 }
5822
5823 @Override
5824 public void unregisterFeatureProvisioningChangedCallback(int subId,
5825 IFeatureProvisioningCallback callback) {
5826 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5827 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5828
5829 final long identity = Binder.clearCallingIdentity();
5830 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5831 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5832 }
5833
joonhunshin91bc1952022-04-29 08:47:15 +00005834 try {
5835 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5836 if (controller == null) {
5837 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5838 return;
5839 }
5840 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5841 } finally {
5842 Binder.restoreCallingIdentity(identity);
5843 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005844 }
allenwtsu99c623b2020-01-03 18:24:23 +08005845
5846 private void checkModifyPhoneStatePermission(int subId, String message) {
5847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5848 message);
5849 }
5850
allenwtsu99c623b2020-01-03 18:24:23 +08005851 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005852 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005853 boolean isProvisioned) {
5854 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5855
5856 final long identity = Binder.clearCallingIdentity();
5857 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005858 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5859 if (controller == null) {
5860 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5861 return;
5862 }
5863 controller.setRcsProvisioningStatusForCapability(
5864 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005865 } finally {
5866 Binder.restoreCallingIdentity(identity);
5867 }
allenwtsu99c623b2020-01-03 18:24:23 +08005868 }
5869
5870
5871 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005872 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5873 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5874 mApp, subId, "getRcsProvisioningStatusForCapability");
5875
allenwtsu99c623b2020-01-03 18:24:23 +08005876 final long identity = Binder.clearCallingIdentity();
5877 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005878 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5879 if (controller == null) {
5880 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5881
5882 // device does not support IMS, this method will return true always.
5883 return true;
5884 }
5885 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005886 } finally {
5887 Binder.restoreCallingIdentity(identity);
5888 }
5889 }
5890
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005891 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005892 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5893 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005894 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005895
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005896 final long identity = Binder.clearCallingIdentity();
5897 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005898 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5899 if (controller == null) {
5900 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5901 return;
5902 }
5903 controller.setImsProvisioningStatusForCapability(
5904 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005905 } finally {
5906 Binder.restoreCallingIdentity(identity);
5907 }
5908 }
5909
5910 @Override
5911 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005912 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5913 mApp, subId, "getProvisioningStatusForCapability");
5914
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005915 final long identity = Binder.clearCallingIdentity();
5916 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005917 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5918 if (controller == null) {
5919 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005920
joonhunshin91bc1952022-04-29 08:47:15 +00005921 // device does not support IMS, this method will return true always.
5922 return true;
5923 }
5924 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005925 } finally {
5926 Binder.restoreCallingIdentity(identity);
5927 }
5928 }
5929
5930 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005931 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5932 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5933 mApp, subId, "isProvisioningRequiredForCapability");
5934
5935 final long identity = Binder.clearCallingIdentity();
5936 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005937 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5938 if (controller == null) {
5939 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5940
5941 // device does not support IMS, this method will return false
5942 return false;
5943 }
5944 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005945 } finally {
5946 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005947 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005948 }
5949
5950 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005951 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5952 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5953 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005954
joonhunshincffb7fc2021-11-28 07:32:01 +00005955 final long identity = Binder.clearCallingIdentity();
5956 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005957 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5958 if (controller == null) {
5959 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5960
5961 // device does not support IMS, this method will return false
5962 return false;
5963 }
5964 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005965 } finally {
5966 Binder.restoreCallingIdentity(identity);
5967 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005968 }
5969
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005970 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005971 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005972 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5973 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5974 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005975 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5976 mApp, subId, "getImsProvisioningInt");
5977
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005978 final long identity = Binder.clearCallingIdentity();
5979 try {
5980 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005981 int slotId = getSlotIndex(subId);
5982 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5983 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5984 + subId + "' for key:" + key);
5985 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5986 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005987
joonhunshin91bc1952022-04-29 08:47:15 +00005988 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5989 if (controller == null) {
5990 loge("getImsProvisioningInt: Device does not support IMS");
5991
5992 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5993 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5994 }
5995 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005996 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5997 return retVal;
5998 }
5999
calvinpanb5a34062021-02-08 19:59:36 +08006000 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07006001 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006002 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
6003 + subId + "' for key:" + key);
6004 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07006005 } finally {
6006 Binder.restoreCallingIdentity(identity);
6007 }
6008 }
6009
6010 @Override
6011 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006012 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
6013 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
6014 }
joonhunshincffb7fc2021-11-28 07:32:01 +00006015 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6016 mApp, subId, "getImsProvisioningString");
6017
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07006018 final long identity = Binder.clearCallingIdentity();
6019 try {
6020 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006021 int slotId = getSlotIndex(subId);
6022 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6023 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
6024 + subId + "' for key:" + key);
6025 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
6026 }
calvinpanb5a34062021-02-08 19:59:36 +08006027 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07006028 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006029 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
6030 + subId + "' for key:" + key);
6031 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07006032 } finally {
6033 Binder.restoreCallingIdentity(identity);
6034 }
6035 }
6036
6037 @Override
6038 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006039 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
6040 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
6041 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08006042 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
6043 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00006044
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07006045 final long identity = Binder.clearCallingIdentity();
6046 try {
6047 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006048 int slotId = getSlotIndex(subId);
6049 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6050 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
6051 + subId + "' for key:" + key);
6052 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
6053 }
joonhunshincffb7fc2021-11-28 07:32:01 +00006054
joonhunshin91bc1952022-04-29 08:47:15 +00006055 ImsProvisioningController controller = ImsProvisioningController.getInstance();
6056 if (controller == null) {
6057 loge("setImsProvisioningInt: Device does not support IMS");
6058
6059 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
6060 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
6061 }
6062 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00006063 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
6064 return retVal;
6065 }
6066
calvinpanb5a34062021-02-08 19:59:36 +08006067 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
6068 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006069 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08006070 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006071 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07006072 } finally {
6073 Binder.restoreCallingIdentity(identity);
6074 }
6075 }
6076
6077 @Override
6078 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006079 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
6080 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
6081 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08006082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
6083 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07006084 final long identity = Binder.clearCallingIdentity();
6085 try {
6086 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006087 int slotId = getSlotIndex(subId);
6088 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6089 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
6090 + subId + "' for key:" + key);
6091 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
6092 }
calvinpanb5a34062021-02-08 19:59:36 +08006093 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
6094 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006095 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08006096 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006097 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07006098 } finally {
6099 Binder.restoreCallingIdentity(identity);
6100 }
6101 }
6102
Brad Ebinger919631e2021-06-02 17:46:35 -07006103 /**
6104 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
6105 * for the given slot ID or no ImsResolver instance has been created.
6106 * @param slotId The slot ID that the IMS service is created for.
6107 * @throws ImsException If there is no ImsService configured for this slot.
6108 */
6109 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
6110 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
6111 ImsFeature.FEATURE_MMTEL)) {
6112 throw new ImsException("This subscription does not support MMTEL over IMS",
6113 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
6114 }
6115 }
6116
Brad Ebinger1ce9c432019-07-16 13:19:44 -07006117 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006118 int slotId = SubscriptionManager.getSlotIndex(subId);
6119 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07006120 throw new ImsException("Invalid Subscription Id, subId=" + subId,
6121 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07006122 }
6123 return slotId;
6124 }
6125
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006126 private int getSlotIndex(int subId) {
6127 int slotId = SubscriptionManager.getSlotIndex(subId);
6128 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
6129 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
6130 }
6131 return slotId;
6132 }
6133
Wink Saville36469e72014-06-11 15:17:00 -07006134 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07006135 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07006136 */
6137 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006138 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
6139 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07006140 try {
6141 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6142 } catch (SecurityException se) {
6143 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
6144 throw new SecurityException("Package " + callingPackage + " does not belong to "
6145 + Binder.getCallingUid());
6146 }
Nathan Haroldf096d982020-11-18 17:18:06 -08006147 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07006148 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006149 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07006150 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07006151 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006152 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006153 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006154 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
6155 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07006156
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006157 final long identity = Binder.clearCallingIdentity();
6158 try {
6159 final Phone phone = getPhone(subId);
6160 if (phone != null) {
6161 return phone.getServiceState().getDataNetworkType();
6162 } else {
6163 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
6164 }
6165 } finally {
6166 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006167 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006168 }
6169
6170 /**
6171 * Returns the data network type
6172 */
6173 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006174 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08006175 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08006176 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07006177 }
6178
6179 /**
6180 * Returns the data network type for a subId
6181 */
6182 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006183 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
6184 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006185 String functionName = "getDataNetworkTypeForSubscriber";
6186 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
6187 mApp, functionName)) {
6188 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6189 mApp, subId, callingPackage, callingFeatureId, functionName)) {
6190 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
6191 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006192 }
6193
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006194 final long identity = Binder.clearCallingIdentity();
6195 try {
6196 final Phone phone = getPhone(subId);
6197 if (phone != null) {
6198 return phone.getServiceState().getDataNetworkType();
6199 } else {
6200 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
6201 }
6202 } finally {
6203 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006204 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006205 }
6206
6207 /**
Wink Saville36469e72014-06-11 15:17:00 -07006208 * Returns the Voice network type for a subId
6209 */
6210 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006211 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
6212 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006213 String functionName = "getVoiceNetworkTypeForSubscriber";
6214 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
6215 mApp, functionName)) {
6216 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6217 mApp, subId, callingPackage, callingFeatureId, functionName)) {
6218 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
6219 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07006220 }
6221
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006222 final long identity = Binder.clearCallingIdentity();
6223 try {
6224 final Phone phone = getPhone(subId);
6225 if (phone != null) {
6226 return phone.getServiceState().getVoiceNetworkType();
6227 } else {
6228 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
6229 }
6230 } finally {
6231 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006232 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006233 }
6234
6235 /**
6236 * @return true if a ICC card is present
6237 */
6238 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07006239 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08006240 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006241 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07006242 }
6243
6244 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006245 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07006246 */
Sanket Padawe356d7632015-06-22 14:03:32 -07006247 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006248 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006249 final long identity = Binder.clearCallingIdentity();
6250 try {
6251 final Phone phone = PhoneFactory.getPhone(slotIndex);
6252 if (phone != null) {
6253 return phone.getIccCard().hasIccCard();
6254 } else {
6255 return false;
6256 }
6257 } finally {
6258 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08006259 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006260 }
6261
6262 /**
6263 * Return if the current radio is LTE on CDMA. This
6264 * is a tri-state return value as for a period of time
6265 * the mode may be unknown.
6266 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006267 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006268 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08006269 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006270 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006271 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006272 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
6273 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
6274 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07006275 }
6276
Sanket Padawe356d7632015-06-22 14:03:32 -07006277 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006278 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
6279 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08006280 try {
6281 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
6282 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006283 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
6284 }
6285
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006286 final long identity = Binder.clearCallingIdentity();
6287 try {
6288 final Phone phone = getPhone(subId);
6289 if (phone == null) {
6290 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
6291 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07006292 return TelephonyProperties.lte_on_cdma_device()
6293 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006294 }
6295 } finally {
6296 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006297 }
Wink Saville36469e72014-06-11 15:17:00 -07006298 }
6299
Wink Saville36469e72014-06-11 15:17:00 -07006300 /**
6301 * {@hide}
6302 * Returns Default subId, 0 in the case of single standby.
6303 */
Wink Savilleb564aae2014-10-23 10:18:09 -07006304 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08006305 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07006306 }
6307
Shishir Agrawala9f32182016-04-12 12:00:16 -07006308 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08006309 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07006310 }
6311
Wink Savilleb564aae2014-10-23 10:18:09 -07006312 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08006313 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006314 }
Ihab Awadf2177b72013-11-25 13:33:23 -08006315
Pengquan Menge92a50d2018-09-21 15:54:48 -07006316 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08006317 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08006318 return getSubscriptionManagerService().isActiveSubId(subId,
Jack Yu285100e2022-12-02 22:48:35 -08006319 mApp.getOpPackageName(), mApp.getFeatureId());
6320 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07006321 return mSubscriptionController.isActiveSubId(subId);
6322 }
6323
Ihab Awadf2177b72013-11-25 13:33:23 -08006324 /**
6325 * @see android.telephony.TelephonyManager.WifiCallingChoices
6326 */
6327 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006328 final long identity = Binder.clearCallingIdentity();
6329 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006330 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006331 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
6332 getWhenToMakeWifiCallsDefaultPreference());
6333 } finally {
6334 Binder.restoreCallingIdentity(identity);
6335 }
Ihab Awadf2177b72013-11-25 13:33:23 -08006336 }
6337
6338 /**
6339 * @see android.telephony.TelephonyManager.WifiCallingChoices
6340 */
6341 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006342 final long identity = Binder.clearCallingIdentity();
6343 try {
6344 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006345 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006346 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
6347 } finally {
6348 Binder.restoreCallingIdentity(identity);
6349 }
Ihab Awadf9e92732013-12-05 18:02:52 -08006350 }
6351
Sailesh Nepald1e68152013-12-12 19:08:02 -08006352 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07006353 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08006354 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08006355 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08006356
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006357 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
6358 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
6359 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08006360 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006361 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006362 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08006363 }
6364 return PhoneFactory.getPhone(phoneId);
6365 }
6366
Shishir Agrawal566b7612013-10-28 14:41:00 -07006367 @Override
Derek Tan740e1672017-06-27 14:56:27 -07006368 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08006369 @NonNull IccLogicalChannelRequest request) {
6370 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6371 /*message=*/ "iccOpenLogicalChannel");
6372
6373 if (DBG) log("iccOpenLogicalChannel: request=" + request);
6374 // Verify that the callingPackage in the request belongs to the calling UID
6375 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
6376
6377 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006378 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006379
Rambo Wanga1782702021-11-10 20:15:19 -08006380 private Phone getPhoneFromValidIccLogicalChannelRequest(
6381 @NonNull IccLogicalChannelRequest request, String message) {
6382 Phone phone;
6383 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
6384 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6385 mApp, request.subId, message);
6386 phone = getPhoneFromSubId(request.subId);
6387 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6388 enforceModifyPermission();
6389 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
6390 } else {
6391 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08006392 }
Rambo Wanga1782702021-11-10 20:15:19 -08006393 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08006394 }
6395
6396 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08006397 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006398 final long identity = Binder.clearCallingIdentity();
6399 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006400 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006401 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006402 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6403 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08006404 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
6405 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006406 loge("The calling package is not allowed to access ISD-R.");
6407 throw new SecurityException(
6408 "The calling package is not allowed to access ISD-R.");
6409 }
Derek Tan740e1672017-06-27 14:56:27 -07006410 }
Derek Tan740e1672017-06-27 14:56:27 -07006411
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006412 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006413 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6414 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006415 return response;
6416 } finally {
6417 Binder.restoreCallingIdentity(identity);
6418 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006419 }
6420
6421 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006422 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
6423 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6424 /*message=*/"iccCloseLogicalChannel");
6425
6426 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6427
6428 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006429 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006430
Rambo Wanga1782702021-11-10 20:15:19 -08006431 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6432 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006433 // before this feature is enabled, this API should only return false if
6434 // the operation fails instead of throwing runtime exception for
6435 // backward-compatibility.
6436 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6437 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006438 final long identity = Binder.clearCallingIdentity();
6439 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006440 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006441 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006442 }
Chen Xue9d737e2022-01-01 23:41:31 -08006443 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006444 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006445 Boolean success = false;
6446 if (result instanceof RuntimeException) {
6447 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006448 if (shouldThrowExceptionOnFailure) {
6449 throw (RuntimeException) result;
6450 } else {
6451 return false;
6452 }
Chen Xue9d737e2022-01-01 23:41:31 -08006453 } else if (result instanceof Boolean) {
6454 success = (Boolean) result;
6455 } else {
6456 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6457 }
Rambo Wanga1782702021-11-10 20:15:19 -08006458 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006459 return success;
6460 } finally {
6461 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006462 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006463 }
6464
6465 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006466 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006467 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006468 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6469 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08006470 if (DBG) {
6471 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6472 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6473 + p3 + " data=" + data);
6474 }
6475 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6476 command, p1, p2, p3, data);
6477 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006478
Jordan Liu4c733742019-02-28 12:03:40 -08006479 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006480 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006481 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006482 enforceModifyPermission();
6483 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006484 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006485 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6486 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006487 }
6488 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006489 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6490 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006491 }
6492
6493 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6494 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006495 final long identity = Binder.clearCallingIdentity();
6496 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006497 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006498 return "";
6499 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006500
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006501 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006502 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6503 null /* workSource */);
6504 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006505
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006506 // Append the returned status code to the end of the response payload.
6507 String s = Integer.toHexString(
6508 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6509 if (response.payload != null) {
6510 s = IccUtils.bytesToHexString(response.payload) + s;
6511 }
6512 return s;
6513 } finally {
6514 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006515 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006516 }
Jake Hambye994d462014-02-03 13:10:13 -08006517
Evan Charltonc66da362014-05-16 14:06:40 -07006518 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006519 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6520 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006521 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6522 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006523 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08006524 if (DBG) {
6525 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6526 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6527 }
6528 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6529 cla, command, p1, p2, p3, data);
6530 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006531
Jordan Liu4c733742019-02-28 12:03:40 -08006532 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006533 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006534 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006535 enforceModifyPermission();
6536 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6537 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006538 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006539 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6540 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006541 }
6542
6543 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006544 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6545 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006546 }
6547
6548 // open APDU basic channel assuming the caller has sufficient permissions
6549 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6550 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006551 final long identity = Binder.clearCallingIdentity();
6552 try {
6553 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6554 && TextUtils.equals(ISDR_AID, data)) {
6555 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006556 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6557 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006558 if (bestComponent == null
6559 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6560 loge("The calling package is not allowed to select ISD-R.");
6561 throw new SecurityException(
6562 "The calling package is not allowed to select ISD-R.");
6563 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006564 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006565
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006566 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006567 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6568 null /* workSource */);
6569 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006570
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006571 // Append the returned status code to the end of the response payload.
6572 String s = Integer.toHexString(
6573 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6574 if (response.payload != null) {
6575 s = IccUtils.bytesToHexString(response.payload) + s;
6576 }
6577 return s;
6578 } finally {
6579 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006580 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006581 }
6582
6583 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006584 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006585 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006586 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6587 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006588
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006589 final long identity = Binder.clearCallingIdentity();
6590 try {
6591 if (DBG) {
6592 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6593 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6594 }
6595
6596 IccIoResult response =
6597 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6598 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6599 subId);
6600
6601 if (DBG) {
6602 log("Exchange SIM_IO [R]" + response);
6603 }
6604
6605 byte[] result = null;
6606 int length = 2;
6607 if (response.payload != null) {
6608 length = 2 + response.payload.length;
6609 result = new byte[length];
6610 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6611 } else {
6612 result = new byte[length];
6613 }
6614
6615 result[length - 1] = (byte) response.sw2;
6616 result[length - 2] = (byte) response.sw1;
6617 return result;
6618 } finally {
6619 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006620 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006621 }
6622
Nathan Haroldb3014052017-01-25 15:57:32 -08006623 /**
6624 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6625 * on a particular subscription
6626 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006627 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6628 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006629 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006630 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006631 return null;
6632 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006633
6634 final long identity = Binder.clearCallingIdentity();
6635 try {
6636 if (appType != TelephonyManager.APPTYPE_USIM
6637 && appType != TelephonyManager.APPTYPE_SIM) {
6638 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6639 return null;
6640 }
6641 Object response = sendRequest(
6642 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6643 if (response instanceof String[]) {
6644 return (String[]) response;
6645 }
yincheng zhao2737e882019-09-06 17:06:54 -07006646 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006647 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006648 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006649 } finally {
6650 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006651 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006652 }
6653
yincheng zhao2737e882019-09-06 17:06:54 -07006654 /**
6655 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6656 * subscription.
6657 *
6658 * @param subId the id of the subscription.
6659 * @param appType the uicc app type, must be USIM or SIM.
6660 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6661 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006662 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006663 * @return number of fplmns that is successfully written to the SIM.
6664 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006665 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6666 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6668 mApp, subId, "setForbiddenPlmns");
6669
yincheng zhao2737e882019-09-06 17:06:54 -07006670 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6671 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6672 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6673 }
6674 if (fplmns == null) {
6675 throw new IllegalArgumentException("Fplmn List provided is null");
6676 }
6677 for (String fplmn : fplmns) {
6678 if (!CellIdentity.isValidPlmn(fplmn)) {
6679 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6680 }
6681 }
6682 final long identity = Binder.clearCallingIdentity();
6683 try {
6684 Object response = sendRequest(
6685 CMD_SET_FORBIDDEN_PLMNS,
6686 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6687 subId);
6688 return (int) response;
6689 } finally {
6690 Binder.restoreCallingIdentity(identity);
6691 }
6692 }
6693
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006694 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006695 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006696 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6697 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006698
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006699 final long identity = Binder.clearCallingIdentity();
6700 try {
6701 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6702 if (response.payload == null) {
6703 return "";
6704 }
Evan Charltonc66da362014-05-16 14:06:40 -07006705
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006706 // Append the returned status code to the end of the response payload.
6707 String s = Integer.toHexString(
6708 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6709 s = IccUtils.bytesToHexString(response.payload) + s;
6710 return s;
6711 } finally {
6712 Binder.restoreCallingIdentity(identity);
6713 }
Evan Charltonc66da362014-05-16 14:06:40 -07006714 }
6715
Jake Hambye994d462014-02-03 13:10:13 -08006716 /**
6717 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6718 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6719 *
6720 * @param itemID the ID of the item to read
6721 * @return the NV item as a String, or null on error.
6722 */
6723 @Override
6724 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006725 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006726 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6727 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006728
6729 final long identity = Binder.clearCallingIdentity();
6730 try {
6731 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006732 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006733 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6734 return value;
6735 } finally {
6736 Binder.restoreCallingIdentity(identity);
6737 }
Jake Hambye994d462014-02-03 13:10:13 -08006738 }
6739
6740 /**
6741 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6742 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6743 *
6744 * @param itemID the ID of the item to read
6745 * @param itemValue the value to write, as a String
6746 * @return true on success; false on any failure
6747 */
6748 @Override
6749 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006750 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006751 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6752 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006753
6754 final long identity = Binder.clearCallingIdentity();
6755 try {
6756 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6757 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006758 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006759 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6760 return success;
6761 } finally {
6762 Binder.restoreCallingIdentity(identity);
6763 }
Jake Hambye994d462014-02-03 13:10:13 -08006764 }
6765
6766 /**
6767 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6768 * Used for device configuration by some CDMA operators.
6769 *
6770 * @param preferredRoamingList byte array containing the new PRL
6771 * @return true on success; false on any failure
6772 */
6773 @Override
6774 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006775 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6776 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006777
6778 final long identity = Binder.clearCallingIdentity();
6779 try {
6780 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6781 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6782 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6783 return success;
6784 } finally {
6785 Binder.restoreCallingIdentity(identity);
6786 }
Jake Hambye994d462014-02-03 13:10:13 -08006787 }
6788
6789 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006790 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006791 * Used for device configuration by some CDMA operators.
6792 *
chen xu6dac5ab2018-10-26 17:39:23 -07006793 * @param slotIndex - device slot.
6794 *
Jake Hambye994d462014-02-03 13:10:13 -08006795 * @return true on success; false on any failure
6796 */
6797 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006798 public boolean resetModemConfig(int slotIndex) {
6799 Phone phone = PhoneFactory.getPhone(slotIndex);
6800 if (phone != null) {
6801 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6802 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006803
chen xu6dac5ab2018-10-26 17:39:23 -07006804 final long identity = Binder.clearCallingIdentity();
6805 try {
6806 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6807 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6808 return success;
6809 } finally {
6810 Binder.restoreCallingIdentity(identity);
6811 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006812 }
chen xu6dac5ab2018-10-26 17:39:23 -07006813 return false;
6814 }
6815
6816 /**
6817 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6818 *
6819 * @param slotIndex - device slot.
6820 *
6821 * @return true on success; false on any failure
6822 */
6823 @Override
6824 public boolean rebootModem(int slotIndex) {
6825 Phone phone = PhoneFactory.getPhone(slotIndex);
6826 if (phone != null) {
6827 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6828 mApp, phone.getSubId(), "rebootModem");
6829
6830 final long identity = Binder.clearCallingIdentity();
6831 try {
6832 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6833 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6834 return success;
6835 } finally {
6836 Binder.restoreCallingIdentity(identity);
6837 }
6838 }
6839 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006840 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006841
Brad Ebinger51f743a2017-01-23 13:50:20 -08006842 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006843 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6844 * {@link #disableIms(int)}.
6845 * @param slotIndex device slot.
6846 */
6847 public void resetIms(int slotIndex) {
6848 enforceModifyPermission();
6849
6850 final long identity = Binder.clearCallingIdentity();
6851 try {
6852 if (mImsResolver == null) {
6853 // may happen if the does not support IMS.
6854 return;
6855 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006856 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006857 } finally {
6858 Binder.restoreCallingIdentity(identity);
6859 }
6860 }
6861
6862 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006863 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6864 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006865 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006866 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006867 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006868
6869 final long identity = Binder.clearCallingIdentity();
6870 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006871 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006872 // may happen if the device does not support IMS.
6873 return;
6874 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006875 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006876 } finally {
6877 Binder.restoreCallingIdentity(identity);
6878 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006879 }
6880
6881 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006882 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6883 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006884 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006885 public void disableIms(int slotId) {
6886 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006887
6888 final long identity = Binder.clearCallingIdentity();
6889 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006890 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006891 // may happen if the device does not support IMS.
6892 return;
6893 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006894 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006895 } finally {
6896 Binder.restoreCallingIdentity(identity);
6897 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006898 }
6899
6900 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006901 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6902 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006903 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006904 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006905 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006906 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006907
6908 final long identity = Binder.clearCallingIdentity();
6909 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006910 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006911 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6912 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006913 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006914 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006915 } finally {
6916 Binder.restoreCallingIdentity(identity);
6917 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006918 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006919 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006920 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6921 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006922 @Override
6923 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006924 enforceModifyPermission();
6925
6926 final long identity = Binder.clearCallingIdentity();
6927 try {
6928 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006929 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006930 } finally {
6931 Binder.restoreCallingIdentity(identity);
6932 }
6933 }
6934
6935 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006936 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006937 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006938 */
6939 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6940 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006941
6942 final long identity = Binder.clearCallingIdentity();
6943 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006944 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006945 // may happen if the device does not support IMS.
6946 return null;
6947 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006948 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006949 } finally {
6950 Binder.restoreCallingIdentity(identity);
6951 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006952 }
6953
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006954 /**
6955 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006956 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006957 */
6958 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6959 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006960
6961 final long identity = Binder.clearCallingIdentity();
6962 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006963 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006964 // may happen if the device does not support IMS.
6965 return null;
6966 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006967 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006968 } finally {
6969 Binder.restoreCallingIdentity(identity);
6970 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006971 }
6972
Brad Ebinger884c07b2018-02-15 16:17:40 -08006973 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006974 * Sets the ImsService Package Name that Telephony will bind to.
6975 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006976 * @param slotIndex the slot ID that the ImsService should bind for.
6977 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006978 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006979 * @param featureTypes An integer array of feature types associated with a packageName.
6980 * @param packageName The name of the package that the current configuration will be replaced
6981 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006982 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006983 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006984 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6985 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006986 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006988 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006989
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006990 final long identity = Binder.clearCallingIdentity();
6991 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006992 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006993 // may happen if the device does not support IMS.
6994 return false;
6995 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006996 Map<Integer, String> featureConfig = new HashMap<>();
6997 for (int featureType : featureTypes) {
6998 featureConfig.put(featureType, packageName);
6999 }
7000 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
7001 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007002 } finally {
7003 Binder.restoreCallingIdentity(identity);
7004 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07007005 }
7006
7007 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08007008 * Clears any carrier ImsService overrides for the slot index specified that were previously
7009 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
7010 *
7011 * This should only be used for testing.
7012 *
7013 * @param slotIndex the slot ID that the ImsService should bind for.
7014 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
7015 */
7016 @Override
7017 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08007018 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7019 "clearCarrierImsServiceOverride");
7020 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08007021 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08007022
7023 final long identity = Binder.clearCallingIdentity();
7024 try {
7025 if (mImsResolver == null) {
7026 // may happen if the device does not support IMS.
7027 return false;
7028 }
7029 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
7030 } finally {
7031 Binder.restoreCallingIdentity(identity);
7032 }
7033 }
7034
7035 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08007036 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07007037 *
7038 * @param slotId The slot that the ImsService is associated with.
7039 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
7040 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08007041 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07007042 * @return the package name of the ImsService configuration.
7043 */
Brad Ebinger24c29992019-12-05 13:03:21 -08007044 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
7045 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08007046 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08007047 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
7048 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07007049
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007050 final long identity = Binder.clearCallingIdentity();
7051 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08007052 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08007053 // may happen if the device does not support IMS.
7054 return "";
7055 }
Brad Ebingera80c3312019-12-02 10:59:39 -08007056 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08007057 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
7058 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007059 } finally {
7060 Binder.restoreCallingIdentity(identity);
7061 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07007062 }
7063
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007064 /**
7065 * Get the MmTelFeature state associated with the requested subscription id.
7066 * @param subId The subscription that the MmTelFeature is associated with.
7067 * @param callback A callback with an integer containing the
7068 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
7069 */
7070 @Override
7071 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
7072 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00007073 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
7074 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
7075 "IMS not available on device.");
7076 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007077 final long token = Binder.clearCallingIdentity();
7078 try {
Brad Ebingera2628302022-02-18 03:44:55 +00007079 int slotId = getSlotIndex(subId);
7080 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7081 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
7082 + subId + "'");
7083 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
7084 }
7085 verifyImsMmTelConfiguredOrThrow(slotId);
7086 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
7087 try {
7088 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
7089 } catch (RemoteException e) {
7090 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
7091 + "Ignore");
7092 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007093 });
Brad Ebinger919631e2021-06-02 17:46:35 -07007094 } catch (ImsException e) {
7095 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007096 } finally {
7097 Binder.restoreCallingIdentity(token);
7098 }
7099 }
7100
Daniel Brightbb5840b2021-01-12 15:48:18 -08007101 /**
7102 * Sets the ims registration state on all valid {@link Phone}s.
7103 */
7104 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07007105 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007106
7107 final long identity = Binder.clearCallingIdentity();
7108 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08007109 // NOTE: Before S, this method only set the default phone.
7110 for (final Phone phone : PhoneFactory.getPhones()) {
7111 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
7112 phone.setImsRegistrationState(registered);
7113 }
7114 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007115 } finally {
7116 Binder.restoreCallingIdentity(identity);
7117 }
Wink Saville36469e72014-06-11 15:17:00 -07007118 }
7119
7120 /**
Stuart Scott54788802015-03-30 13:18:01 -07007121 * Set the network selection mode to automatic.
7122 *
7123 */
7124 @Override
7125 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7127 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007128
7129 final long identity = Binder.clearCallingIdentity();
7130 try {
shilufc958392020-01-20 11:36:01 -08007131 if (!isActiveSubscription(subId)) {
7132 return;
7133 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007134 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08007135 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
7136 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007137 } finally {
7138 Binder.restoreCallingIdentity(identity);
7139 }
Stuart Scott54788802015-03-30 13:18:01 -07007140 }
7141
Jack Yud10cdd42020-09-28 20:28:01 -07007142 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07007143 * Ask the radio to connect to the input network and change selection mode to manual.
7144 *
7145 * @param subId the id of the subscription.
7146 * @param operatorInfo the operator information, included the PLMN, long name and short name of
7147 * the operator to attach to.
7148 * @param persistSelection whether the selection will persist until reboot. If true, only allows
7149 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
7150 * normal network selection next time.
7151 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07007152 */
7153 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07007154 public boolean setNetworkSelectionModeManual(
7155 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7157 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07007158
Jack Yu285100e2022-12-02 22:48:35 -08007159 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07007160 if (!isActiveSubscription(subId)) {
7161 return false;
7162 }
7163
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007164 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07007165 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007166 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07007167 if (DBG) {
7168 log("setNetworkSelectionModeManual: subId: " + subId
7169 + " operator: " + operatorInfo);
7170 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007171 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
7172 } finally {
7173 Binder.restoreCallingIdentity(identity);
7174 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07007175 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007176 /**
shilu84f6e8b2019-12-19 13:58:01 -08007177 * Get the manual network selection
7178 *
7179 * @param subId the id of the subscription.
7180 *
7181 * @return the previously saved user selected PLMN
7182 */
7183 @Override
7184 public String getManualNetworkSelectionPlmn(int subId) {
7185 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007186 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
7187 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08007188
7189 final long identity = Binder.clearCallingIdentity();
7190 try {
7191 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07007192 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08007193 }
7194
7195 final Phone phone = getPhone(subId);
7196 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07007197 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08007198 }
7199 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
7200 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007201 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08007202 } finally {
7203 Binder.restoreCallingIdentity(identity);
7204 }
7205 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07007206
7207 /**
7208 * Scans for available networks.
7209 */
7210 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007211 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
7212 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007213 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7214 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08007215 LocationAccessPolicy.LocationPermissionResult locationResult =
7216 LocationAccessPolicy.checkLocationPermission(mApp,
7217 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7218 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007219 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007220 .setCallingPid(Binder.getCallingPid())
7221 .setCallingUid(Binder.getCallingUid())
7222 .setMethod("getCellNetworkScanResults")
7223 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007224 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7225 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007226 .build());
7227 switch (locationResult) {
7228 case DENIED_HARD:
7229 throw new SecurityException("Not allowed to access scan results -- location");
7230 case DENIED_SOFT:
7231 return null;
7232 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007233
Pengquan Menga1bb6272018-09-06 09:59:22 -07007234 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007235 try {
7236 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07007237 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007238 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007239 } finally {
7240 Binder.restoreCallingIdentity(identity);
7241 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07007242 }
7243
7244 /**
Shuo Qian4a594052020-01-23 11:59:30 -08007245 * Get the call forwarding info, given the call forwarding reason.
7246 */
7247 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007248 public void getCallForwarding(int subId, int callForwardingReason,
7249 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007250 enforceReadPrivilegedPermission("getCallForwarding");
7251 long identity = Binder.clearCallingIdentity();
7252 try {
7253 if (DBG) {
7254 log("getCallForwarding: subId " + subId
7255 + " callForwardingReason" + callForwardingReason);
7256 }
Hall Liu27d24262020-09-18 19:04:59 -07007257
7258 Phone phone = getPhone(subId);
7259 if (phone == null) {
7260 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07007261 callback.onError(
7262 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07007263 } catch (RemoteException e) {
7264 // ignore
7265 }
7266 return;
7267 }
7268
7269 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
7270 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
7271 @Override
7272 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
7273 try {
7274 callback.onCallForwardingInfoAvailable(info);
7275 } catch (RemoteException e) {
7276 // ignore
7277 }
7278 }
7279
7280 @Override
7281 public void onError(int error) {
7282 try {
7283 callback.onError(error);
7284 } catch (RemoteException e) {
7285 // ignore
7286 }
7287 }
7288 });
7289 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08007290 } finally {
7291 Binder.restoreCallingIdentity(identity);
7292 }
7293 }
7294
7295 /**
7296 * Sets the voice call forwarding info including status (enable/disable), call forwarding
7297 * reason, the number to forward, and the timeout before the forwarding is attempted.
7298 */
7299 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007300 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
7301 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007302 enforceModifyPermission();
7303 long identity = Binder.clearCallingIdentity();
7304 try {
7305 if (DBG) {
7306 log("setCallForwarding: subId " + subId
7307 + " callForwardingInfo" + callForwardingInfo);
7308 }
Hall Liu27d24262020-09-18 19:04:59 -07007309
7310 Phone phone = getPhone(subId);
7311 if (phone == null) {
7312 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07007313 callback.accept(
7314 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07007315 } catch (RemoteException e) {
7316 // ignore
7317 }
7318 return;
7319 }
7320
7321 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
7322 FunctionalUtils.ignoreRemoteException(callback::accept));
7323
7324 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08007325 } finally {
7326 Binder.restoreCallingIdentity(identity);
7327 }
7328 }
7329
7330 /**
Hall Liu27d24262020-09-18 19:04:59 -07007331 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007332 */
7333 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007334 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08007335 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08007336 long identity = Binder.clearCallingIdentity();
7337 try {
Hall Liu27d24262020-09-18 19:04:59 -07007338 Phone phone = getPhone(subId);
7339 if (phone == null) {
7340 try {
7341 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7342 } catch (RemoteException e) {
7343 // ignore
7344 }
7345 return;
7346 }
SongFerngWang0e767992021-03-31 22:08:45 +08007347 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7348 PersistableBundle c = configManager.getConfigForSubId(subId);
7349 boolean requireUssd = c.getBoolean(
7350 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007351
Shuo Qian4a594052020-01-23 11:59:30 -08007352 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007353 if (requireUssd) {
7354 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7355 getSubscriptionCarrierId(subId));
7356 String newUssdCommand = "";
7357 try {
7358 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007359 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007360 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7361 } catch (NullPointerException e) {
7362 loge("Failed to generate USSD number" + e);
7363 }
7364 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7365 mMainThreadHandler, callback, carrierXmlParser,
7366 CarrierXmlParser.SsEntry.SSAction.QUERY);
7367 final String ussdCommand = newUssdCommand;
7368 Executors.newSingleThreadExecutor().execute(() -> {
7369 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7370 });
7371 } else {
7372 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7373 callback::accept);
7374 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7375 }
Shuo Qian4a594052020-01-23 11:59:30 -08007376 } finally {
7377 Binder.restoreCallingIdentity(identity);
7378 }
7379 }
7380
7381 /**
Hall Liu27d24262020-09-18 19:04:59 -07007382 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007383 */
7384 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007385 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007386 enforceModifyPermission();
7387 long identity = Binder.clearCallingIdentity();
7388 try {
Hall Liu27d24262020-09-18 19:04:59 -07007389 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7390
7391 Phone phone = getPhone(subId);
7392 if (phone == null) {
7393 try {
7394 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7395 } catch (RemoteException e) {
7396 // ignore
7397 }
7398 return;
7399 }
7400
SongFerngWang0e767992021-03-31 22:08:45 +08007401 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7402 PersistableBundle c = configManager.getConfigForSubId(subId);
7403 boolean requireUssd = c.getBoolean(
7404 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007405
SongFerngWang0e767992021-03-31 22:08:45 +08007406 if (DBG) log("getCallWaitingStatus: subId " + subId);
7407 if (requireUssd) {
7408 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7409 getSubscriptionCarrierId(subId));
7410 CarrierXmlParser.SsEntry.SSAction ssAction =
7411 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7412 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7413 String newUssdCommand = "";
7414 try {
7415 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007416 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007417 .makeCommand(ssAction, null);
7418 } catch (NullPointerException e) {
7419 loge("Failed to generate USSD number" + e);
7420 }
7421 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7422 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7423 final String ussdCommand = newUssdCommand;
7424 Executors.newSingleThreadExecutor().execute(() -> {
7425 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7426 });
7427 } else {
7428 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7429 FunctionalUtils.ignoreRemoteException(callback::accept));
7430
7431 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7432 }
Shuo Qian4a594052020-01-23 11:59:30 -08007433 } finally {
7434 Binder.restoreCallingIdentity(identity);
7435 }
7436 }
7437
7438 /**
yinxub1bed742017-04-17 11:45:04 -07007439 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007440 *
yinxub1bed742017-04-17 11:45:04 -07007441 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007442 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7443 * location related information which will be sent if the caller already possess
7444 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007445 * @param request contains the radio access networks with bands/channels to scan
7446 * @param messenger callback messenger for scan results or errors
7447 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007448 * @return the id of the requested scan which can be used to stop the scan.
7449 */
7450 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007451 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7452 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007453 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7455 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007456 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007457 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7458 if (!renounceFineLocationAccess) {
7459 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007460 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7461 .setCallingPackage(callingPackage)
7462 .setCallingFeatureId(callingFeatureId)
7463 .setCallingPid(Binder.getCallingPid())
7464 .setCallingUid(Binder.getCallingUid())
7465 .setMethod("requestNetworkScan")
7466 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7467 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7468 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7469 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007470 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007471 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007472 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7473 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007474 if (e != null) {
7475 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7476 throw e;
7477 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007478 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007479 return TelephonyScanManager.INVALID_SCAN_ID;
7480 }
7481 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007482 }
Hall Liu912dfd32019-04-25 14:02:26 -07007483 int callingUid = Binder.getCallingUid();
7484 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007485 final long identity = Binder.clearCallingIdentity();
7486 try {
7487 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007488 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007489 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007490 } finally {
7491 Binder.restoreCallingIdentity(identity);
7492 }
yinxu504e1392017-04-12 16:03:22 -07007493 }
7494
Hall Liub2ac8ef2019-02-28 15:56:23 -08007495 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007496 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007497 boolean hasCarrierPriv;
7498 final long identity = Binder.clearCallingIdentity();
7499 try {
7500 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7501 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7502 } finally {
7503 Binder.restoreCallingIdentity(identity);
7504 }
Hall Liu558027f2019-05-15 19:14:05 -07007505 boolean hasNetworkScanPermission =
7506 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007507 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007508
7509 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7510 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7511 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007512 }
7513
7514 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7515 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007516 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7517 return new SecurityException("Specific channels must not be"
7518 + " scanned without location access.");
7519 }
7520 }
7521 }
7522
Hall Liub2ac8ef2019-02-28 15:56:23 -08007523 return null;
7524 }
7525
yinxu504e1392017-04-12 16:03:22 -07007526 /**
7527 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007528 *
7529 * @param subId id of the subscription
7530 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007531 */
7532 @Override
7533 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007534 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7535 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007536
Hall Liu912dfd32019-04-25 14:02:26 -07007537 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007538 final long identity = Binder.clearCallingIdentity();
7539 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007540 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007541 } finally {
7542 Binder.restoreCallingIdentity(identity);
7543 }
yinxu504e1392017-04-12 16:03:22 -07007544 }
7545
7546 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007547 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007548 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007549 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007550 */
7551 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007552 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007553 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007554 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007555 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007556
7557 final long identity = Binder.clearCallingIdentity();
7558 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007559 if (DBG) log("getAllowedNetworkTypesBitmask");
7560 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7561 int networkTypesBitmask = (result != null ? result[0] : -1);
7562 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7563 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564 } finally {
7565 Binder.restoreCallingIdentity(identity);
7566 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007567 }
7568
7569 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007570 * Get the allowed network types for certain reason.
7571 *
7572 * @param subId the id of the subscription.
7573 * @param reason the reason the allowed network type change is taking place
7574 * @return the allowed network types.
7575 */
7576 @Override
7577 public long getAllowedNetworkTypesForReason(int subId,
7578 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007579 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007580 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007581 final long identity = Binder.clearCallingIdentity();
7582 try {
7583 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
7584 } finally {
7585 Binder.restoreCallingIdentity(identity);
7586 }
7587 }
7588
7589 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007590 * Enable/Disable E-UTRA-NR Dual Connectivity
7591 * @param subId subscription id of the sim card
7592 * @param nrDualConnectivityState expected NR dual connectivity state
7593 * This can be passed following states
7594 * <ol>
7595 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7596 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7597 * <li>Disable NR dual connectivity and force secondary cell to be released
7598 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7599 * </ol>
7600 * @return operation result.
7601 */
7602 @Override
7603 public int setNrDualConnectivityState(int subId,
7604 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7606 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007607 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007608 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7609 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7610 }
7611
Sooraj Sasindran37444802020-08-11 10:40:43 -07007612 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7613 final long identity = Binder.clearCallingIdentity();
7614 try {
7615 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7616 nrDualConnectivityState, subId,
7617 workSource);
7618 if (DBG) log("enableNRDualConnectivity result: " + result);
7619 return result;
7620 } finally {
7621 Binder.restoreCallingIdentity(identity);
7622 }
7623 }
7624
7625 /**
7626 * Is E-UTRA-NR Dual Connectivity enabled
7627 * @return true if dual connectivity is enabled else false
7628 */
7629 @Override
7630 public boolean isNrDualConnectivityEnabled(int subId) {
7631 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007632 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007633 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007634 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007635 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7636 return false;
7637 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007638 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7639 final long identity = Binder.clearCallingIdentity();
7640 try {
7641 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7642 null, subId, workSource);
7643 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7644 return isEnabled;
7645 } finally {
7646 Binder.restoreCallingIdentity(identity);
7647 }
7648 }
7649
7650 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007651 * Set the allowed network types of the device and
7652 * provide the reason triggering the allowed network change.
7653 *
7654 * @param subId the id of the subscription.
7655 * @param reason the reason the allowed network type change is taking place
7656 * @param allowedNetworkTypes the allowed network types.
7657 * @return true on success; false on any failure.
7658 */
7659 @Override
7660 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007661 @TelephonyManager.AllowedNetworkTypesReason int reason,
7662 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7664 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007665 // If the caller only has carrier privileges, then they should not be able to override
7666 // any network types which were set for security reasons.
7667 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7668 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007669 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007670 throw new SecurityException(
7671 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007672 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007673 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08007674 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007675 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007676 return false;
7677 }
7678 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7679 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007680 return false;
7681 }
7682
Jack Yu5b494332023-01-23 18:18:04 +00007683 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7684 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007685
Jack Yue37dd262022-12-16 11:53:37 -08007686 Phone phone = getPhone(subId);
7687 if (phone == null) {
7688 return false;
7689 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007690
Jack Yue37dd262022-12-16 11:53:37 -08007691 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007692 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007693 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007694 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007695
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007696 final long identity = Binder.clearCallingIdentity();
7697 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007698 Boolean success = (Boolean) sendRequest(
7699 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7700 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7701
7702 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7703 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007704 } finally {
7705 Binder.restoreCallingIdentity(identity);
7706 }
7707 }
7708
7709 /**
Miaoa84611c2019-03-15 09:21:10 +08007710 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007711 *
Miaoa84611c2019-03-15 09:21:10 +08007712 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007713 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007714 * @hide
7715 */
7716 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007717 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007718 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007719 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007720 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007721 try {
Miaoa84611c2019-03-15 09:21:10 +08007722 if (phone != null) {
7723 return phone.hasMatchedTetherApnSetting();
7724 } else {
7725 return false;
7726 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007727 } finally {
7728 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007729 }
Junda Liu475951f2014-11-07 16:45:03 -08007730 }
7731
7732 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007733 * Get the user enabled state of Mobile Data.
7734 *
7735 * TODO: remove and use isUserDataEnabled.
7736 * This can't be removed now because some vendor codes
7737 * calls through ITelephony directly while they should
7738 * use TelephonyManager.
7739 *
7740 * @return true on enabled
7741 */
7742 @Override
7743 public boolean getDataEnabled(int subId) {
7744 return isUserDataEnabled(subId);
7745 }
7746
7747 /**
7748 * Get whether mobile data is enabled per user setting.
7749 *
7750 * There are other factors deciding whether mobile data is actually enabled, but they are
7751 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007752 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007753 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7754 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007755 *
7756 * @return {@code true} if data is enabled else {@code false}
7757 */
7758 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007759 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007760 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007761 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007762 try {
7763 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7764 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007765 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007766 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7767 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007768 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007770 mApp, subId, functionName);
7771
Robert Greenwalt646120a2014-05-23 11:54:03 -07007772 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007773
7774 final long identity = Binder.clearCallingIdentity();
7775 try {
Jack Yu285100e2022-12-02 22:48:35 -08007776 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007777 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7778 Phone phone = PhoneFactory.getPhone(phoneId);
7779 if (phone != null) {
7780 boolean retVal = phone.isUserDataEnabled();
7781 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7782 return retVal;
7783 } else {
7784 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7785 return false;
7786 }
7787 } finally {
7788 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007789 }
7790 }
7791
7792 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007793 * Checks if the device is capable of mobile data by considering whether whether the
7794 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7795 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007796 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007797 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007798 */
7799 @Override
7800 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007801 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007802 try {
7803 try {
7804 mApp.enforceCallingOrSelfPermission(
7805 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007806 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007807 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007808 try {
7809 mApp.enforceCallingOrSelfPermission(
7810 android.Manifest.permission.READ_PHONE_STATE,
7811 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007812 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007813 mApp.enforceCallingOrSelfPermission(
7814 permission.READ_BASIC_PHONE_STATE, functionName);
7815 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007816 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007817 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007818 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007819 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007820
7821 final long identity = Binder.clearCallingIdentity();
7822 try {
Jack Yu285100e2022-12-02 22:48:35 -08007823 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007824 Phone phone = PhoneFactory.getPhone(phoneId);
7825 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007826 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007827 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007828 return retVal;
7829 } else {
7830 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7831 return false;
7832 }
7833 } finally {
7834 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007835 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007836 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007837
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007838 /**
7839 * Check if data is enabled for a specific reason
7840 * @param subId Subscription index
7841 * @param reason the reason the data enable change is taking place
7842 * @return {@code true} if the overall data is enabled; {@code false} if not.
7843 */
7844 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007845 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007846 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007847 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007848 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007849 try {
7850 mApp.enforceCallingOrSelfPermission(
7851 android.Manifest.permission.ACCESS_NETWORK_STATE,
7852 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007853 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007854 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7855 functionName);
7856 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007857 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007858 try {
7859 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007860 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007861 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007862 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007863 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007864 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007865 }
7866
7867
7868 final long identity = Binder.clearCallingIdentity();
7869 try {
Jack Yu285100e2022-12-02 22:48:35 -08007870 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007871 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007872 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007873 + " reason=" + reason);
7874 }
7875 Phone phone = PhoneFactory.getPhone(phoneId);
7876 if (phone != null) {
7877 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007878 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007879 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007880 return retVal;
7881 } else {
7882 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007883 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007884 + subId + " retVal=false");
7885 }
7886 return false;
7887 }
7888 } finally {
7889 Binder.restoreCallingIdentity(identity);
7890 }
7891 }
7892
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007893 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007894 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007895 // No permission needed; this only lets the caller inspect their own status.
7896 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007897 }
Junda Liu29340342014-07-10 15:23:27 -07007898
7899 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007900 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007901 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007902 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7903 }
7904
7905 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7906 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007907 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007908 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007909 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7910 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007911 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7912 if (cpt == null) {
7913 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007914 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7915 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007916 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007917 }
7918
7919 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007920 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007921 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007922 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007923 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007924 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007925 Phone phone = getPhone(subId);
7926 if (phone == null) {
7927 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7928 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7929 }
7930 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7931 if (cpt == null) {
7932 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007933 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7934 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007935 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007936 }
7937
7938 @Override
7939 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007940 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007941 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7942 }
7943
7944 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007945 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007946 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007947 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007948 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007949 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7950 Phone phone = PhoneFactory.getPhone(phoneId);
7951 if (phone == null) {
7952 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007953 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007954 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7955 if (cpt == null) {
7956 continue;
7957 }
7958 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007959 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7960 break;
7961 }
7962 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007963 return result;
Junda Liu29340342014-07-10 15:23:27 -07007964 }
Derek Tan89e89d42014-07-08 17:00:10 -07007965
7966 @Override
Junda Liue64de782015-04-16 17:19:16 -07007967 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007968 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007969 Phone phone = PhoneFactory.getPhone(phoneId);
7970 if (phone == null) {
7971 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007972 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007973 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7974 if (cpt == null) {
7975 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007976 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007977 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007978 }
7979
Amith Yamasani6e118872016-02-19 12:53:51 -08007980 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007981 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007982 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007983 Phone phone = PhoneFactory.getPhone(phoneId);
7984 if (phone == null) {
7985 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007986 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007987 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7988 if (cpt == null) {
7989 return Collections.emptyList();
7990 }
7991 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007992 }
7993
chen xuf7e9fe82019-05-09 19:31:02 -07007994 @Override
7995 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007996 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007997 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007998 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007999 try {
8000 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
8001 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
8002 }
8003 } finally {
8004 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07008005 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008006 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07008007 }
8008
Rambo Wang6812ffb2022-03-15 16:54:17 -07008009 @Override
8010 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
8011 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
8012
8013 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
8014 if (phone == null) {
8015 return null;
8016 }
8017 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8018 if (cpt == null) {
8019 return null;
8020 }
8021 return cpt.getCarrierServicePackageName();
8022 }
8023
Wink Savilleb564aae2014-10-23 10:18:09 -07008024 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07008025 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008026 UiccPort port = phone == null ? null : phone.getUiccPort();
8027 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07008028 return null;
8029 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008030 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07008031 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07008032 return null;
8033 }
8034 return iccId;
8035 }
8036
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07008037 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08008038 public void setCallComposerStatus(int subId, int status) {
8039 enforceModifyPermission();
8040
8041 final long identity = Binder.clearCallingIdentity();
8042 try {
8043 Phone phone = getPhone(subId);
8044 if (phone != null) {
8045 Phone defaultPhone = phone.getImsPhone();
8046 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8047 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8048 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08008049 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
8050 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08008051 }
8052 }
Shuo Qian284ae752020-12-22 19:10:14 -08008053 } catch (ImsException e) {
8054 throw new ServiceSpecificException(e.getCode());
8055 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08008056 Binder.restoreCallingIdentity(identity);
8057 }
8058 }
8059
8060 @Override
8061 public int getCallComposerStatus(int subId) {
8062 enforceReadPrivilegedPermission("getCallComposerStatus");
8063
8064 final long identity = Binder.clearCallingIdentity();
8065 try {
8066 Phone phone = getPhone(subId);
8067 if (phone != null) {
8068 Phone defaultPhone = phone.getImsPhone();
8069 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8070 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8071 return imsPhone.getCallComposerStatus();
8072 }
8073 }
8074 } finally {
8075 Binder.restoreCallingIdentity(identity);
8076 }
8077 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
8078 }
8079
8080 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08008081 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
8082 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008083 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008084 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07008085
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008086 final long identity = Binder.clearCallingIdentity();
8087 try {
8088 final String iccId = getIccId(subId);
8089 final Phone phone = getPhone(subId);
8090 if (phone == null) {
8091 return false;
8092 }
8093 final String subscriberId = phone.getSubscriberId();
8094
8095 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008096 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008097 + subscriberId + " to " + number);
8098 }
8099
8100 if (TextUtils.isEmpty(iccId)) {
8101 return false;
8102 }
8103
8104 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
8105
8106 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
8107 if (alphaTag == null) {
8108 editor.remove(alphaTagPrefKey);
8109 } else {
8110 editor.putString(alphaTagPrefKey, alphaTag);
8111 }
8112
8113 // Record both the line number and IMSI for this ICCID, since we need to
8114 // track all merged IMSIs based on line number
8115 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
8116 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
8117 if (number == null) {
8118 editor.remove(numberPrefKey);
8119 editor.remove(subscriberPrefKey);
8120 } else {
8121 editor.putString(numberPrefKey, number);
8122 editor.putString(subscriberPrefKey, subscriberId);
8123 }
8124
8125 editor.commit();
8126 return true;
8127 } finally {
8128 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07008129 }
Derek Tan7226c842014-07-02 17:42:23 -07008130 }
8131
8132 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008133 public String getLine1NumberForDisplay(int subId, String callingPackage,
8134 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07008135 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08008136 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008137 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08008138 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07008139 return null;
8140 }
Derek Tan97ebb422014-09-05 16:55:38 -07008141
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008142 final long identity = Binder.clearCallingIdentity();
8143 try {
8144 String iccId = getIccId(subId);
8145 if (iccId != null) {
8146 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
8147 if (DBG_MERGE) {
8148 log("getLine1NumberForDisplay returning "
8149 + mTelephonySharedPreferences.getString(numberPrefKey, null));
8150 }
8151 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08008152 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008153 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
8154 return null;
8155 } finally {
8156 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07008157 }
Derek Tan7226c842014-07-02 17:42:23 -07008158 }
8159
8160 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008161 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
8162 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008163 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008164 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07008165 return null;
8166 }
Derek Tan97ebb422014-09-05 16:55:38 -07008167
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008168 final long identity = Binder.clearCallingIdentity();
8169 try {
8170 String iccId = getIccId(subId);
8171 if (iccId != null) {
8172 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
8173 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
8174 }
8175 return null;
8176 } finally {
8177 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07008178 }
Derek Tan7226c842014-07-02 17:42:23 -07008179 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008180
8181 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008182 public String[] getMergedSubscriberIds(int subId, String callingPackage,
8183 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008184 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
8185 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08008186 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08008187 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008188 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008189 return null;
8190 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008191
Jordan Liub49b04b2019-05-06 14:45:15 -07008192 // Clear calling identity, when calling TelephonyManager, because callerUid must be
8193 // the process, where TelephonyManager was instantiated.
8194 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008195 final long identity = Binder.clearCallingIdentity();
8196 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008197 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008198 final TelephonyManager tele = TelephonyManager.from(context);
8199 final SubscriptionManager sub = SubscriptionManager.from(context);
8200
8201 // Figure out what subscribers are currently active
8202 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008203
Jordan Liub49b04b2019-05-06 14:45:15 -07008204 // Only consider subs which match the current subId
8205 // This logic can be simplified. See b/131189269 for progress.
8206 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008207 activeSubscriberIds.add(tele.getSubscriberId(subId));
8208 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008209
8210 // First pass, find a number override for an active subscriber
8211 String mergeNumber = null;
8212 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
8213 for (String key : prefs.keySet()) {
8214 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
8215 final String subscriberId = (String) prefs.get(key);
8216 if (activeSubscriberIds.contains(subscriberId)) {
8217 final String iccId = key.substring(
8218 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
8219 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
8220 mergeNumber = (String) prefs.get(numberKey);
8221 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008222 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008223 + " for active subscriber " + subscriberId);
8224 }
8225 if (!TextUtils.isEmpty(mergeNumber)) {
8226 break;
8227 }
8228 }
8229 }
8230 }
8231
8232 // Shortcut when no active merged subscribers
8233 if (TextUtils.isEmpty(mergeNumber)) {
8234 return null;
8235 }
8236
8237 // Second pass, find all subscribers under that line override
8238 final ArraySet<String> result = new ArraySet<>();
8239 for (String key : prefs.keySet()) {
8240 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
8241 final String number = (String) prefs.get(key);
8242 if (mergeNumber.equals(number)) {
8243 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
8244 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
8245 final String subscriberId = (String) prefs.get(subscriberKey);
8246 if (!TextUtils.isEmpty(subscriberId)) {
8247 result.add(subscriberId);
8248 }
8249 }
8250 }
8251 }
8252
8253 final String[] resultArray = result.toArray(new String[result.size()]);
8254 Arrays.sort(resultArray);
8255 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008256 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008257 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
8258 }
8259 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008260 } finally {
8261 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08008262 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008263 }
8264
8265 @Override
zoey chen38003472019-12-13 17:16:31 +08008266 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
8267 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07008268
8269 final long identity = Binder.clearCallingIdentity();
8270 try {
8271 final TelephonyManager telephonyManager = mApp.getSystemService(
8272 TelephonyManager.class);
8273 String subscriberId = telephonyManager.getSubscriberId(subId);
8274 if (subscriberId == null) {
8275 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008276 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008277 + subId);
8278 }
8279 return null;
8280 }
8281
Jack Yu285100e2022-12-02 22:48:35 -08008282 ParcelUuid groupUuid;
8283 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008284 final SubscriptionInfo info = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08008285 .getSubscriptionInfo(subId);
8286 groupUuid = info.getGroupUuid();
8287 } else {
8288 final SubscriptionInfo info = mSubscriptionController
8289 .getSubscriptionInfo(subId);
8290 groupUuid = info.getGroupUuid();
8291 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07008292 // If it doesn't belong to any group, return just subscriberId of itself.
8293 if (groupUuid == null) {
8294 return new String[]{subscriberId};
8295 }
8296
8297 // Get all subscriberIds from the group.
8298 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08008299 List<SubscriptionInfo> groupInfos;
8300 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008301 groupInfos = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08008302 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8303 mApp.getAttributionTag());
8304 } else {
8305 groupInfos = mSubscriptionController
8306 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8307 mApp.getAttributionTag());
8308 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07008309 for (SubscriptionInfo subInfo : groupInfos) {
8310 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8311 if (subscriberId != null) {
8312 mergedSubscriberIds.add(subscriberId);
8313 }
8314 }
8315
8316 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8317 } finally {
8318 Binder.restoreCallingIdentity(identity);
8319
8320 }
8321 }
8322
8323 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008324 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008325 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008326 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008327
8328 final long identity = Binder.clearCallingIdentity();
8329 try {
8330 final Phone phone = getPhone(subId);
8331 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8332 } finally {
8333 Binder.restoreCallingIdentity(identity);
8334 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008335 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008336
8337 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008338 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008339 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8340 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008341 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8342 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008343
8344 final long identity = Binder.clearCallingIdentity();
8345 try {
8346 final Phone phone = getPhone(subId);
8347 if (phone == null) {
8348 return false;
8349 }
8350 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8351 cdmaNonRoamingList);
8352 } finally {
8353 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008354 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008355 }
8356
8357 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00008358 @Deprecated
8359 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
8360 enforceModifyPermission();
8361
8362 int returnValue = 0;
8363 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07008364 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00008365 if(result.exception == null) {
8366 if (result.result != null) {
8367 byte[] responseData = (byte[])(result.result);
8368 if(responseData.length > oemResp.length) {
8369 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
8370 responseData.length + "bytes. Buffer Size is " +
8371 oemResp.length + "bytes.");
8372 }
8373 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
8374 returnValue = responseData.length;
8375 }
8376 } else {
8377 CommandException ex = (CommandException) result.exception;
8378 returnValue = ex.getCommandError().ordinal();
8379 if(returnValue > 0) returnValue *= -1;
8380 }
8381 } catch (RuntimeException e) {
8382 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
8383 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
8384 if(returnValue > 0) returnValue *= -1;
8385 }
8386
8387 return returnValue;
8388 }
8389
8390 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008391 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008392 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07008393 try {
8394 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008395 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008396 mApp, phone.getSubId(), "getRadioAccessFamily");
8397 } catch (SecurityException e) {
8398 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8399 throw e;
8400 }
chen xub97461a2018-10-26 14:17:57 -07008401 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008402 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07008403 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08008404 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008405 final long identity = Binder.clearCallingIdentity();
8406 try {
chen xub97461a2018-10-26 14:17:57 -07008407 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008408 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07008409 mApp, phone.getSubId(), "getRadioAccessFamily");
8410 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008411 } finally {
8412 Binder.restoreCallingIdentity(identity);
8413 }
chen xub97461a2018-10-26 14:17:57 -07008414 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008415 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008416
8417 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008418 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008419 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008420 try {
8421 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8422 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008423 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008424 }
8425 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008426 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008427 }
8428 RoleManager rm = mApp.getSystemService(RoleManager.class);
8429 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8430 if (!dialerRoleHolders.contains(callingPackage)) {
8431 throw new SecurityException("App must be the dialer role holder to"
8432 + " upload a call composer pic");
8433 }
8434
8435 Executors.newSingleThreadExecutor().execute(() -> {
8436 ByteArrayOutputStream output = new ByteArrayOutputStream(
8437 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8438 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8439 boolean readUntilEnd = false;
8440 int totalBytesRead = 0;
8441 byte[] buffer = new byte[16 * 1024];
8442 while (true) {
8443 int numRead;
8444 try {
8445 numRead = input.read(buffer);
8446 } catch (IOException e) {
8447 try {
8448 fd.checkError();
8449 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8450 null);
8451 } catch (IOException e1) {
8452 // This means that the other side closed explicitly with an error. If this
8453 // happens, log and ignore.
8454 loge("Remote end of call composer picture pipe closed: " + e1);
8455 }
8456 break;
8457 }
8458 if (numRead == -1) {
8459 readUntilEnd = true;
8460 break;
8461 }
8462 totalBytesRead += numRead;
8463 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8464 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8465 try {
8466 input.close();
8467 } catch (IOException e) {
8468 // ignore
8469 }
8470 break;
8471 }
8472 output.write(buffer, 0, numRead);
8473 }
8474 // Generally, the remote end will close the file descriptors. The only case where we
8475 // close is above, where the picture size is too big.
8476
8477 try {
8478 fd.checkError();
8479 } catch (IOException e) {
8480 loge("Remote end for call composer closed with an error: " + e);
8481 return;
8482 }
8483
Hall Liuaa4211e2021-01-20 15:43:39 -08008484 if (!readUntilEnd) {
8485 loge("Did not finish reading entire image; aborting");
8486 return;
8487 }
Hall Liu82694d52020-12-11 18:22:04 -08008488
Hall Liuaa4211e2021-01-20 15:43:39 -08008489 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8490 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8491 new CallComposerPictureTransfer.Factory() {},
8492 imageData,
8493 (result) -> {
8494 if (result.first != null) {
8495 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8496 Bundle outputResult = new Bundle();
8497 outputResult.putParcelable(
8498 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8499 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8500 outputResult);
8501 } else {
8502 callback.send(result.second, null);
8503 }
8504 }
8505 );
Hall Liu82694d52020-12-11 18:22:04 -08008506 });
8507 }
8508
8509 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008510 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008511 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008512 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008513
8514 final long identity = Binder.clearCallingIdentity();
8515 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008516 ImsManager.getInstance(defaultPhone.getContext(),
8517 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008518 } finally {
8519 Binder.restoreCallingIdentity(identity);
8520 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008521 }
8522
8523 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008524 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008525 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008526 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8527 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008528 return false;
8529 }
Svet Ganovb320e182015-04-16 12:30:10 -07008530
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008531 final long identity = Binder.clearCallingIdentity();
8532 try {
8533 // Check the user preference and the system-level IMS setting. Even if the user has
8534 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8535 // In the long run, we may instead need to check if there exists a connection service
8536 // which can support video calling.
8537 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008538 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008539 return imsManager.isVtEnabledByPlatform()
8540 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8541 && imsManager.isVtEnabledByUser();
8542 } finally {
8543 Binder.restoreCallingIdentity(identity);
8544 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008545 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008546
Andrew Leea1239f22015-03-02 17:44:07 -08008547 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008548 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8549 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008550 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008551 mApp, subId, callingPackage, callingFeatureId,
8552 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008553 return false;
8554 }
8555
8556 final long identity = Binder.clearCallingIdentity();
8557 try {
8558 CarrierConfigManager configManager =
8559 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008560 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008561 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8562 } finally {
8563 Binder.restoreCallingIdentity(identity);
8564 }
Andrew Leea1239f22015-03-02 17:44:07 -08008565 }
8566
8567 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008568 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008569 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008570 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008571 return false;
8572 }
8573
8574 final long identity = Binder.clearCallingIdentity();
8575 try {
8576 CarrierConfigManager configManager =
8577 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008578 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008579 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8580 } finally {
8581 Binder.restoreCallingIdentity(identity);
8582 }
Andrew Leea1239f22015-03-02 17:44:07 -08008583 }
8584
Andrew Lee9431b832015-03-09 18:46:45 -07008585 @Override
8586 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008587 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008588 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008589 }
8590
8591 @Override
8592 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008593 final long identity = Binder.clearCallingIdentity();
8594 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008595 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008596 } finally {
8597 Binder.restoreCallingIdentity(identity);
8598 }
Andrew Lee9431b832015-03-09 18:46:45 -07008599 }
8600
Hall Liuf6668912018-10-31 17:05:23 -07008601 /**
8602 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8603 * support for the feature and device firmware support.
8604 *
8605 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8606 */
8607 @Override
8608 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008609 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008610 final Phone phone = getPhone(subscriptionId);
8611 if (phone == null) {
8612 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8613 return false;
8614 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008615 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008616 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008617 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
8618 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008619 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008620 return isCarrierSupported && isDeviceSupported;
8621 } finally {
8622 Binder.restoreCallingIdentity(identity);
8623 }
Hall Liu98187582018-01-22 19:15:32 -08008624 }
8625
Hall Liuf6668912018-10-31 17:05:23 -07008626 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008627 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8628 * RTT setting, will return true if the device and carrier both support RTT.
8629 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008630 */
8631 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008632 final long identity = Binder.clearCallingIdentity();
8633 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00008634 boolean isRttSupported = isRttSupported(subscriptionId);
8635 boolean isUserRttSettingOn = Settings.Secure.getInt(
8636 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8637 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8638 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8639 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008640 } finally {
8641 Binder.restoreCallingIdentity(identity);
8642 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008643 }
8644
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008645 @Deprecated
8646 @Override
8647 public String getDeviceId(String callingPackage) {
8648 return getDeviceIdWithFeature(callingPackage, null);
8649 }
8650
Sanket Padawe7310cc72015-01-14 09:53:20 -08008651 /**
8652 * Returns the unique device ID of phone, for example, the IMEI for
8653 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8654 *
8655 * <p>Requires Permission:
8656 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8657 */
8658 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008659 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008660 try {
8661 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8662 } catch (SecurityException se) {
8663 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8664 throw new SecurityException("Package " + callingPackage + " does not belong to "
8665 + Binder.getCallingUid());
8666 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008667 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008668 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008669 return null;
8670 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008671 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008672 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008673 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008674 return null;
8675 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008676
8677 final long identity = Binder.clearCallingIdentity();
8678 try {
8679 return phone.getDeviceId();
8680 } finally {
8681 Binder.restoreCallingIdentity(identity);
8682 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008683 }
8684
Ping Sunc67b7c22016-03-02 19:16:45 +08008685 /**
8686 * {@hide}
8687 * Returns the IMS Registration Status on a particular subid
8688 *
8689 * @param subId
8690 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008691 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008692 Phone phone = getPhone(subId);
8693 if (phone != null) {
8694 return phone.isImsRegistered();
8695 } else {
8696 return false;
8697 }
8698 }
8699
Santos Cordon7a1885b2015-02-03 11:15:19 -08008700 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008701 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008702 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008703 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008704 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008705 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8706 }
8707 final long identity = Binder.clearCallingIdentity();
8708 try {
8709 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8710 } finally {
8711 Binder.restoreCallingIdentity(identity);
8712 }
8713 }
8714
8715 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008716 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008717 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008718 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008719 mApp,
8720 subscriptionId,
8721 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8722 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07008723 final long identity = Binder.clearCallingIdentity();
8724 try {
8725 Phone phone = getPhone(subscriptionId);
8726 if (phone == null) {
8727 return null;
8728 }
8729 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8730 } finally {
8731 Binder.restoreCallingIdentity(identity);
8732 }
8733 }
8734
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008735 /**
8736 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008737 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008738 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008739 final long identity = Binder.clearCallingIdentity();
8740 try {
8741 Phone phone = getPhone(subId);
8742 if (phone != null) {
8743 return phone.isWifiCallingEnabled();
8744 } else {
8745 return false;
8746 }
8747 } finally {
8748 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008749 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008750 }
8751
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008752 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008753 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008754 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008755 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008756 final long identity = Binder.clearCallingIdentity();
8757 try {
8758 Phone phone = getPhone(subId);
8759 if (phone != null) {
8760 return phone.isVideoEnabled();
8761 } else {
8762 return false;
8763 }
8764 } finally {
8765 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008766 }
8767 }
8768
8769 /**
8770 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8771 * defined in {@link ImsRegistrationImplBase}.
8772 */
8773 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008774 final long identity = Binder.clearCallingIdentity();
8775 try {
8776 Phone phone = getPhone(subId);
8777 if (phone != null) {
8778 return phone.getImsRegistrationTech();
8779 } else {
8780 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8781 }
8782 } finally {
8783 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008784 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008785 }
8786
Stuart Scott8eef64f2015-04-08 15:13:54 -07008787 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008788 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008789 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07008790 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8791 return;
8792 }
Kai Shif70f46f2021-03-03 13:59:46 -08008793 Phone defaultPhone = getDefaultPhone();
8794 if (defaultPhone != null) {
8795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8796 mApp, getDefaultPhone().getSubId(), "factoryReset");
8797 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008798 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008799
Svet Ganovcc087f82015-05-12 20:35:54 -07008800 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008801 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8802 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008803 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008804 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008805 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008806 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008807 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008808 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08008809 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008810 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008811 // There has been issues when Sms raw table somehow stores orphan
8812 // fragments. They lead to garbled message when new fragments come
8813 // in and combined with those stale ones. In case this happens again,
8814 // user can reset all network settings which will clean up this table.
8815 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008816 // Clean up IMS settings as well here.
8817 int slotId = getSlotIndex(subId);
8818 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8819 ImsManager.getInstance(mApp, slotId).factoryReset();
8820 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008821
Kai Shif70f46f2021-03-03 13:59:46 -08008822 if (defaultPhone == null) {
8823 return;
8824 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008825 // Erase modem config if erase modem on network setting is enabled.
8826 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8827 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8828 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008829 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008830 }
Kai Shif70f46f2021-03-03 13:59:46 -08008831
8832 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008833 } finally {
8834 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008835 }
8836 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008837
SongFerngWangfd89b102021-05-27 22:44:54 +08008838 @VisibleForTesting
8839 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8840 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8841 return;
8842 }
8843 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8844 RILConstants.PREFERRED_NETWORK_MODE);
8845 SubscriptionManager.setSubscriptionProperty(subId,
8846 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8847 "user=" + defaultNetworkType);
8848 phone.loadAllowedNetworksFromSubscriptionDatabase();
8849 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8850 defaultNetworkType, null);
8851 }
8852
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008853 private void cleanUpSmsRawTable(Context context) {
8854 ContentResolver resolver = context.getContentResolver();
8855 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8856 resolver.delete(uri, null, null);
8857 }
8858
Narayan Kamath1c496c22015-04-16 14:40:19 +01008859 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008860 public String getSimLocaleForSubscriber(int subId) {
8861 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
8862 final Phone phone = getPhone(subId);
8863 if (phone == null) {
8864 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008865 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008866 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008867 final long identity = Binder.clearCallingIdentity();
8868 try {
Jack Yu285100e2022-12-02 22:48:35 -08008869 SubscriptionInfo info;
8870 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008871 info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
Jack Yu285100e2022-12-02 22:48:35 -08008872 phone.getContext().getOpPackageName(),
8873 phone.getContext().getAttributionTag());
8874 if (info == null) {
8875 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8876 return null;
8877 }
8878 } else {
8879 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
8880 phone.getContext().getOpPackageName(),
8881 phone.getContext().getAttributionTag());
8882 if (info == null) {
8883 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8884 return null;
8885 }
chen xu6291c472019-02-04 12:55:53 -08008886 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008887 // Try and fetch the locale from the carrier properties or from the SIM language
8888 // preferences (EF-PL and EF-LI)...
8889 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008890 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008891 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8892 if (localeFromDefaultSim != null) {
8893 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8894 if (DBG) log("Using locale from subId: " + subId + " locale: "
8895 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008896 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008897 } else {
8898 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008899 }
8900 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008901
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008902 // The SIM language preferences only store a language (e.g. fr = French), not an
8903 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8904 // the SIM and carrier preferences does not include a country we add the country
8905 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008906 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008907 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008908 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008909 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008910 }
8911
8912 if (DBG) log("No locale found - returning null");
8913 return null;
8914 } finally {
8915 Binder.restoreCallingIdentity(identity);
8916 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008917 }
8918
tom hsu0b59d292022-09-29 23:49:21 +08008919 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008920 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008921 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008922 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008923 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008924 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8925 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008926 Locale.forLanguageTag(localeTag).getCountry())) {
8927 return localeTag;
8928 }
8929 }
8930 return inputLocale.toLanguageTag();
8931 }
8932
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008933 /**
8934 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8935 */
8936 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08008937 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008938 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Jack Yu285100e2022-12-02 22:48:35 -08008939 mApp.getOpPackageName(), mApp.getAttributionTag());
8940 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008941 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08008942 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008943 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008944
Gary Jian3aa9a762022-01-24 16:41:19 +08008945 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8946 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008947
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008948 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008949 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8950 * representing the state of the modem.
8951 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008952 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8953 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008954 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008955 */
8956 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008957 public void requestModemActivityInfo(ResultReceiver result) {
8958 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008959 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008960
8961 final long identity = Binder.clearCallingIdentity();
8962 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008963 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008964 } finally {
8965 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008966 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008967 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008968
Gary Jian76280a42022-12-07 16:18:33 +08008969 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008970 // less than total activity duration.
8971 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8972 if (info == null) {
8973 return false;
8974 }
8975 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008976 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008977 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8978
Hall Liu49656c02020-10-09 19:00:11 -07008979 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8980
Siddharth Rayb8114062018-06-17 15:02:38 -07008981 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008982 && (info.getSleepTimeMillis() <= activityDurationMs)
8983 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008984 }
8985
Gary Jian3aa9a762022-01-24 16:41:19 +08008986 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8987 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8988 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8989 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8990
8991 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8992 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8993 }
8994
8995 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8996 mLastModemActivityInfo.setReceiveTimeMillis(
8997 rat,
8998 freq,
8999 info.getReceiveTimeMillis(rat, freq)
9000 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
9001 }
9002
9003 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
9004 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
9005 int[] txTimeMs = info.getTransmitTimeMillis(rat);
9006 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
9007
9008 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
9009 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
9010 }
9011 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
9012 mLastModemActivityInfo.setReceiveTimeMillis(
9013 rat,
9014 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
9015 }
9016
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009017 /**
9018 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
9019 * @param info recent ModemActivityInfo
9020 */
Gary Jian3aa9a762022-01-24 16:41:19 +08009021 private void mergeModemActivityInfo(ModemActivityInfo info) {
9022 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08009023 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08009024 boolean matched;
9025 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
9026 matched = false;
9027 int rat = info.getSpecificInfoRat(i);
9028 int freq = info.getSpecificInfoFrequencyRange(i);
9029 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
9030 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
9031 //if it already exists
9032 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
9033 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
9034 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
9035 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
9036 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
9037 updateLastModemActivityInfo(info, rat, freq);
9038 matched = true;
9039 }
9040 } else {
9041 updateLastModemActivityInfo(info, rat);
9042 matched = true;
9043 }
9044 }
9045 }
9046
9047 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08009048 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08009049 new ActivityStatsTechSpecificInfo(
9050 rat,
9051 freq,
9052 info.getTransmitTimeMillis(rat, freq),
9053 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08009054 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08009055 }
9056 }
9057 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
9058 mLastModemActivitySpecificInfo =
9059 new ActivityStatsTechSpecificInfo[merged.size()];
9060 merged.toArray(mLastModemActivitySpecificInfo);
9061
9062 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
9063 mLastModemActivityInfo.setSleepTimeMillis(
9064 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009065 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08009066 mLastModemActivityInfo.setIdleTimeMillis(
9067 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009068 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08009069
9070 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009071 new ModemActivityInfo(
9072 mLastModemActivityInfo.getTimestampMillis(),
9073 mLastModemActivityInfo.getSleepTimeMillis(),
9074 mLastModemActivityInfo.getIdleTimeMillis(),
9075 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08009076 }
9077
9078 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
9079 ActivityStatsTechSpecificInfo[] info) {
9080 int infoSize = info.length;
9081 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
9082 for (int i = 0; i < infoSize; i++) {
9083 ret[i] = new ActivityStatsTechSpecificInfo(
9084 info[i].getRat(), info[i].getFrequencyRange(),
9085 info[i].getTransmitTimeMillis(),
9086 (int) info[i].getReceiveTimeMillis());
9087 }
9088 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08009089 }
9090
Jack Yu85bd38a2015-11-09 11:34:32 -08009091 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08009092 * Returns the service state information on specified subscription.
9093 */
9094 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08009095 public ServiceState getServiceStateForSubscriber(int subId,
9096 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
9097 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009098 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009099 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08009100 return null;
9101 }
9102
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08009103 boolean hasFinePermission = false;
9104 boolean hasCoarsePermission = false;
9105 if (!renounceFineLocationAccess) {
9106 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
9107 LocationAccessPolicy.checkLocationPermission(mApp,
9108 new LocationAccessPolicy.LocationPermissionQuery.Builder()
9109 .setCallingPackage(callingPackage)
9110 .setCallingFeatureId(callingFeatureId)
9111 .setCallingPid(Binder.getCallingPid())
9112 .setCallingUid(Binder.getCallingUid())
9113 .setMethod("getServiceStateForSubscriber")
9114 .setLogAsInfo(true)
9115 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
9116 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
9117 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
9118 .build());
9119 hasFinePermission =
9120 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
9121 }
Hall Liuf19c44f2018-11-27 14:38:17 -08009122
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08009123 if (!renounceCoarseLocationAccess) {
9124 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
9125 LocationAccessPolicy.checkLocationPermission(mApp,
9126 new LocationAccessPolicy.LocationPermissionQuery.Builder()
9127 .setCallingPackage(callingPackage)
9128 .setCallingFeatureId(callingFeatureId)
9129 .setCallingPid(Binder.getCallingPid())
9130 .setCallingUid(Binder.getCallingUid())
9131 .setMethod("getServiceStateForSubscriber")
9132 .setLogAsInfo(true)
9133 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
9134 .setMinSdkVersionForFine(Integer.MAX_VALUE)
9135 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
9136 .build());
9137 hasCoarsePermission =
9138 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
9139 }
Hall Liuf19c44f2018-11-27 14:38:17 -08009140
Jack Yu479f40e2020-10-27 21:29:25 -07009141 final Phone phone = getPhone(subId);
9142 if (phone == null) {
9143 return null;
9144 }
9145
Jordan Liu0f2bc442020-11-18 16:47:37 -08009146 final long identity = Binder.clearCallingIdentity();
9147
Jack Yu479f40e2020-10-27 21:29:25 -07009148 boolean isCallingPackageDataService = phone.getDataServicePackages()
9149 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009150 try {
Jordan Liuc437b192020-08-17 10:59:12 -07009151 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08009152 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08009153 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08009154 .getSubscriptionInfoInternal(subId);
9155 if (subInfo == null || !subInfo.isActive()) {
9156 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
9157 + "subId=" + subId);
9158 return null;
9159 }
9160 } else {
9161 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
9162 callingFeatureId)) {
9163 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
9164 + "subId=" + subId);
9165 return null;
9166 }
Jordan Liuc437b192020-08-17 10:59:12 -07009167 }
9168
Hall Liuf19c44f2018-11-27 14:38:17 -08009169 ServiceState ss = phone.getServiceState();
9170
9171 // Scrub out the location info in ServiceState depending on what level of access
9172 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07009173 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08009174 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
9175 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009176 } finally {
9177 Binder.restoreCallingIdentity(identity);
9178 }
Jack Yu85bd38a2015-11-09 11:34:32 -08009179 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009180
9181 /**
9182 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
9183 *
9184 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
9185 * voicemail ringtone.
9186 * @return The URI for the ringtone to play when receiving a voicemail from a specific
9187 * PhoneAccount.
9188 */
9189 @Override
9190 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009191 final long identity = Binder.clearCallingIdentity();
9192 try {
9193 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9194 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009195 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009196 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009197
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009198 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
9199 } finally {
9200 Binder.restoreCallingIdentity(identity);
9201 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009202 }
9203
9204 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009205 * Sets the per-account voicemail ringtone.
9206 *
9207 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9208 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9209 *
9210 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9211 * voicemail ringtone.
9212 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
9213 * PhoneAccount.
9214 */
9215 @Override
9216 public void setVoicemailRingtoneUri(String callingPackage,
9217 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009218 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009219 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009220 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9221 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009222 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9223 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9224 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009225 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009226
9227 final long identity = Binder.clearCallingIdentity();
9228 try {
9229 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9230 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009231 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009232 }
9233 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
9234 } finally {
9235 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009236 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009237 }
9238
9239 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08009240 * Returns whether vibration is set for voicemail notification in Phone settings.
9241 *
9242 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
9243 * voicemail vibration setting.
9244 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
9245 */
9246 @Override
9247 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009248 final long identity = Binder.clearCallingIdentity();
9249 try {
9250 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9251 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009252 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009253 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009254
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009255 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
9256 } finally {
9257 Binder.restoreCallingIdentity(identity);
9258 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009259 }
9260
Youhan Wange64578a2016-05-02 15:32:42 -07009261 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009262 * Sets the per-account voicemail vibration.
9263 *
9264 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9265 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9266 *
9267 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9268 * voicemail vibration setting.
9269 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9270 * specific PhoneAccount.
9271 */
9272 @Override
9273 public void setVoicemailVibrationEnabled(String callingPackage,
9274 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009275 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009276 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009277 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9278 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009279 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9280 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9281 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009282 }
9283
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009284 final long identity = Binder.clearCallingIdentity();
9285 try {
9286 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9287 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009288 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009289 }
9290 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9291 } finally {
9292 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009293 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009294 }
9295
9296 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009297 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9298 *
9299 * @throws SecurityException if the caller does not have the required permission
9300 */
arunvoddud7401012022-12-15 16:08:12 +00009301 @VisibleForTesting
9302 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009303 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009304 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009305 }
9306
9307 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009308 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9309 * permission.
9310 *
9311 * @throws SecurityException if the caller does not have the required permission
9312 */
9313 private void enforceSendSmsPermission() {
9314 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9315 }
9316
9317 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009318 * Make sure either called from same process as self (phone) or IPC caller has interact across
9319 * users permission.
9320 *
9321 * @throws SecurityException if the caller does not have the required permission
9322 */
9323 private void enforceInteractAcrossUsersPermission(String message) {
9324 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9325 }
9326
9327 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009328 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009329 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009330 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009331 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009332 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009333 final long identity = Binder.clearCallingIdentity();
9334 try {
9335 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009336 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009337 if (componentName == null) {
9338 throw new SecurityException(
9339 "Caller not current active visual voicemail package[null]");
9340 }
9341 String vvmPackage = componentName.getPackageName();
9342 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009343 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009344 }
9345 } finally {
9346 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009347 }
9348 }
9349
9350 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009351 * Return the application ID for the app type.
9352 *
9353 * @param subId the subscription ID that this request applies to.
9354 * @param appType the uicc app type.
9355 * @return Application ID for specificied app type, or null if no uicc.
9356 */
9357 @Override
9358 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009359 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07009360 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009361
9362 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009363 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009364 if (phone == null) {
9365 return null;
9366 }
9367 String aid = null;
9368 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009369 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009370 .getApplicationByType(appType).getAid();
9371 } catch (Exception e) {
9372 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9373 }
9374 return aid;
9375 } finally {
9376 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009377 }
Youhan Wange64578a2016-05-02 15:32:42 -07009378 }
9379
Youhan Wang4001d252016-05-11 10:29:41 -07009380 /**
9381 * Return the Electronic Serial Number.
9382 *
9383 * @param subId the subscription ID that this request applies to.
9384 * @return ESN or null if error.
9385 */
9386 @Override
9387 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009388 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009389 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009390
9391 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009392 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009393 if (phone == null) {
9394 return null;
9395 }
9396 String esn = null;
9397 try {
9398 esn = phone.getEsn();
9399 } catch (Exception e) {
9400 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9401 }
9402 return esn;
9403 } finally {
9404 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009405 }
Youhan Wang4001d252016-05-11 10:29:41 -07009406 }
9407
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009408 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009409 * Return the Preferred Roaming List Version.
9410 *
9411 * @param subId the subscription ID that this request applies to.
9412 * @return PRLVersion or null if error.
9413 */
9414 @Override
9415 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009416 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07009417 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009418
9419 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009420 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009421 if (phone == null) {
9422 return null;
9423 }
9424 String cdmaPrlVersion = null;
9425 try {
9426 cdmaPrlVersion = phone.getCdmaPrlVersion();
9427 } catch (Exception e) {
9428 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9429 }
9430 return cdmaPrlVersion;
9431 } finally {
9432 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009433 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009434 }
9435
9436 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009437 * Get snapshot of Telephony histograms
9438 * @return List of Telephony histograms
9439 * @hide
9440 */
9441 @Override
9442 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9444 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009445
9446 final long identity = Binder.clearCallingIdentity();
9447 try {
9448 return RIL.getTelephonyRILTimingHistograms();
9449 } finally {
9450 Binder.restoreCallingIdentity(identity);
9451 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009452 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009453
9454 /**
9455 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009456 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9457 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009458 * Require system privileges. In the future we may add this to carrier APIs.
9459 *
Michele Berionne482f8202018-11-27 18:57:59 -08009460 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009461 */
9462 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009463 @TelephonyManager.SetCarrierRestrictionResult
9464 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009465 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07009466 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009467
Michele Berionne482f8202018-11-27 18:57:59 -08009468 if (carrierRestrictionRules == null) {
9469 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009470 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009472 final long identity = Binder.clearCallingIdentity();
9473 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009474 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009475 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009476 } finally {
9477 Binder.restoreCallingIdentity(identity);
9478 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009479 }
9480
9481 /**
9482 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009483 * Get the allowed carrier list and the excluded carrier list, including the priority between
9484 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009485 * Require system privileges. In the future we may add this to carrier APIs.
9486 *
Michele Berionne482f8202018-11-27 18:57:59 -08009487 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009488 */
9489 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009490 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009491 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07009492 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009493
9494 final long identity = Binder.clearCallingIdentity();
9495 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009496 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9497 if (response instanceof CarrierRestrictionRules) {
9498 return (CarrierRestrictionRules) response;
9499 }
9500 // Response is an Exception of some kind,
9501 // which is signalled to the user as a NULL retval
9502 return null;
9503 } catch (Exception e) {
9504 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9505 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009506 } finally {
9507 Binder.restoreCallingIdentity(identity);
9508 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009509 }
9510
fionaxu59545b42016-05-25 15:53:37 -07009511 /**
arunvoddud7401012022-12-15 16:08:12 +00009512 * Fetches the carrier restriction status of the device and sends the status to the caller
9513 * through the callback.
9514 *
9515 * @param callback The callback that will be used to send the result.
9516 * @throws SecurityException if the caller does not have the required permission/privileges or
9517 * the caller is not allowlisted.
9518 */
9519 @Override
9520 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9521 enforceReadPermission("getCarrierRestrictionStatus");
9522 int carrierId = validateCallerAndGetCarrierId(packageName);
9523 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
9524 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9525 throw new SecurityException("Not an authorized caller");
9526 }
9527 final long identity = Binder.clearCallingIdentity();
9528 try {
9529 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
9530 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
9531 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9532 } finally {
9533 Binder.restoreCallingIdentity(identity);
9534 }
9535 }
9536
9537 @VisibleForTesting
9538 public int validateCallerAndGetCarrierId(String packageName) {
9539 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9540 return allowListInfo.validateCallerAndGetCarrierId(packageName);
9541 }
9542
9543 /**
fionaxu59545b42016-05-25 15:53:37 -07009544 * Action set from carrier signalling broadcast receivers to enable/disable radio
9545 * @param subId the subscription ID that this action applies to.
9546 * @param enabled control enable or disable radio.
9547 * {@hide}
9548 */
9549 @Override
9550 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9551 enforceModifyPermission();
9552 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009553
9554 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009555 if (phone == null) {
9556 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9557 return;
9558 }
9559 try {
9560 phone.carrierActionSetRadioEnabled(enabled);
9561 } catch (Exception e) {
9562 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009563 } finally {
9564 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009565 }
9566 }
9567
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009568 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009569 * Enable or disable Voice over NR (VoNR)
9570 * @param subId the subscription ID that this action applies to.
9571 * @param enabled enable or disable VoNR.
9572 * @return operation result.
9573 */
9574 @Override
9575 public int setVoNrEnabled(int subId, boolean enabled) {
9576 enforceModifyPermission();
9577 final Phone phone = getPhone(subId);
9578
9579 final long identity = Binder.clearCallingIdentity();
9580 if (phone == null) {
9581 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9582 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9583 }
9584
9585 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9586 try {
9587 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9588 workSource);
9589 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009590
9591 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9592 if (DBG) {
9593 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9594 }
9595 SubscriptionManager.setSubscriptionProperty(
9596 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9597 (enabled ? "1" : "0"));
9598 }
9599
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009600 return result;
9601 } finally {
9602 Binder.restoreCallingIdentity(identity);
9603 }
9604 }
9605
9606 /**
9607 * Is voice over NR enabled
9608 * @return true if VoNR is enabled else false
9609 */
9610 @Override
9611 public boolean isVoNrEnabled(int subId) {
9612 enforceReadPrivilegedPermission("isVoNrEnabled");
9613 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9614 final long identity = Binder.clearCallingIdentity();
9615 try {
9616 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9617 null, subId, workSource);
9618 if (DBG) log("isVoNrEnabled: " + isEnabled);
9619 return isEnabled;
9620 } finally {
9621 Binder.restoreCallingIdentity(identity);
9622 }
9623 }
9624
9625 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009626 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9627 * network status based on which carrier apps could apply actions accordingly,
9628 * enable/disable default url handler for example.
9629 *
9630 * @param subId the subscription ID that this action applies to.
9631 * @param report control start/stop reporting the default network status.
9632 * {@hide}
9633 */
9634 @Override
9635 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9636 enforceModifyPermission();
9637 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009638
9639 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009640 if (phone == null) {
9641 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9642 return;
9643 }
9644 try {
9645 phone.carrierActionReportDefaultNetworkStatus(report);
9646 } catch (Exception e) {
9647 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009648 } finally {
9649 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009650 }
9651 }
9652
9653 /**
fionaxud9622282017-07-17 17:51:30 -07009654 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9655 * @param subId the subscription ID that this action applies to.
9656 * {@hide}
9657 */
9658 @Override
9659 public void carrierActionResetAll(int subId) {
9660 enforceModifyPermission();
9661 final Phone phone = getPhone(subId);
9662 if (phone == null) {
9663 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9664 return;
9665 }
9666 try {
9667 phone.carrierActionResetAll();
9668 } catch (Exception e) {
9669 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9670 }
9671 }
9672
9673 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009674 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9675 * bug report is being generated.
9676 */
9677 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009678 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009679 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9680 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009681 writer.println("Permission Denial: can't dump Phone from pid="
9682 + Binder.getCallingPid()
9683 + ", uid=" + Binder.getCallingUid()
9684 + "without permission "
9685 + android.Manifest.permission.DUMP);
9686 return;
9687 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009688 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009689 }
Jack Yueb89b242016-06-22 13:27:47 -07009690
Brad Ebingerdac2f002018-04-03 15:17:52 -07009691 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009692 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9693 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9694 @NonNull String[] args) {
9695 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9696 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009697 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009698 }
9699
Jack Yueb89b242016-06-22 13:27:47 -07009700 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009701 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009702 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009703 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009704 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009705 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009706 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009707 */
9708 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009709 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009710 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009711 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9712 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9713 try {
9714 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009715 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009716 } catch (SecurityException se) {
9717 enforceModifyPermission();
9718 }
9719 } else {
9720 enforceModifyPermission();
9721 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009722
9723 final long identity = Binder.clearCallingIdentity();
9724 try {
9725 Phone phone = getPhone(subId);
9726 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009727 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9728 phone.carrierActionSetMeteredApnsEnabled(enabled);
9729 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009730 phone.getDataSettingsManager().setDataEnabled(
9731 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009732 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009733 }
9734 } finally {
9735 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009736 }
9737 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009738
9739 /**
9740 * Get Client request stats
9741 * @return List of Client Request Stats
9742 * @hide
9743 */
9744 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009745 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9746 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009747 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009748 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009749 return null;
9750 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009751 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009752
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009753 final long identity = Binder.clearCallingIdentity();
9754 try {
9755 if (phone != null) {
9756 return phone.getClientRequestStats();
9757 }
9758
9759 return null;
9760 } finally {
9761 Binder.restoreCallingIdentity(identity);
9762 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009763 }
9764
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009765 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009766 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009767 if (uid == Process.ROOT_UID && packageName == null) {
9768 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9769 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9770 // exception. ROOT_UID seems not to have a valid package name returned by
9771 // PackageManager, so just fake it here to avoid issues when running telephony shell
9772 // commands that plumb through the RIL as root, like so:
9773 // $ adb root
9774 // $ adb shell cmd phone ...
9775 packageName = "root";
9776 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009777 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009778 }
Jack Yueb4124c2017-02-16 15:32:43 -08009779
9780 /**
Grace Chen70990072017-03-24 17:21:30 -07009781 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009782 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009783 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009784 * @param state State of SIM (power down, power up, pass through)
9785 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9786 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9787 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009788 *
9789 **/
9790 @Override
Grace Chen70990072017-03-24 17:21:30 -07009791 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009792 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009793 Phone phone = PhoneFactory.getPhone(slotIndex);
9794
vagdeviaf9a5b92018-08-15 16:01:53 -07009795 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009797 final long identity = Binder.clearCallingIdentity();
9798 try {
9799 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009800 phone.setSimPowerState(state, null, workSource);
9801 }
9802 } finally {
9803 Binder.restoreCallingIdentity(identity);
9804 }
9805 }
9806
9807 /**
9808 * Set SIM card power state.
9809 *
9810 * @param slotIndex SIM slot id.
9811 * @param state State of SIM (power down, power up, pass through)
9812 * @param callback callback to trigger after success or failure
9813 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9814 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9815 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9816 *
9817 **/
9818 @Override
9819 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9820 IIntegerConsumer callback) {
9821 enforceModifyPermission();
9822 Phone phone = PhoneFactory.getPhone(slotIndex);
9823
9824 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9825
9826 final long identity = Binder.clearCallingIdentity();
9827 try {
9828 if (phone != null) {
9829 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9830 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009831 }
9832 } finally {
9833 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009834 }
9835 }
Shuo Qiandd210312017-04-12 22:11:33 +00009836
Tyler Gunn65d45c22017-06-05 11:22:26 -07009837 private boolean isUssdApiAllowed(int subId) {
9838 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009839 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009840 if (configManager == null) {
9841 return false;
9842 }
9843 PersistableBundle pb = configManager.getConfigForSubId(subId);
9844 if (pb == null) {
9845 return false;
9846 }
9847 return pb.getBoolean(
9848 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9849 }
9850
Shuo Qiandd210312017-04-12 22:11:33 +00009851 /**
9852 * Check if phone is in emergency callback mode
9853 * @return true if phone is in emergency callback mode
9854 * @param subId sub id
9855 */
goneil9c5f4872017-12-05 14:07:56 -08009856 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009857 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009858 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00009859 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009860
9861 final long identity = Binder.clearCallingIdentity();
9862 try {
9863 if (phone != null) {
9864 return phone.isInEcm();
9865 } else {
9866 return false;
9867 }
9868 } finally {
9869 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009870 }
9871 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009872
9873 /**
9874 * Get the current signal strength information for the given subscription.
9875 * Because this information is not updated when the device is in a low power state
9876 * it should not be relied-upon to be current.
9877 * @param subId Subscription index
9878 * @return the most recent cached signal strength info from the modem
9879 */
9880 @Override
9881 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009882 final long identity = Binder.clearCallingIdentity();
9883 try {
9884 Phone p = getPhone(subId);
9885 if (p == null) {
9886 return null;
9887 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009888
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009889 return p.getSignalStrength();
9890 } finally {
9891 Binder.restoreCallingIdentity(identity);
9892 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009893 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009894
Pengquan Meng77b7f132018-08-22 14:49:57 -07009895 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009896 * Get the current modem radio state for the given slot.
9897 * @param slotIndex slot index.
9898 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009899 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009900 * @return the current radio power state from the modem
9901 */
9902 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009903 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009904 Phone phone = PhoneFactory.getPhone(slotIndex);
9905 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009906 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9907 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009908 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9909 }
9910
9911 final long identity = Binder.clearCallingIdentity();
9912 try {
9913 return phone.getRadioPowerState();
9914 } finally {
9915 Binder.restoreCallingIdentity(identity);
9916 }
9917 }
9918 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9919 }
9920
9921 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009922 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9923 *
9924 * <p>Requires one of the following permissions:
9925 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009926 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009927 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9928 * privileges.
9929 *
9930 * @param subId subscription id
9931 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9932 * {@code false}.
9933 */
9934 @Override
9935 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009936 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009937 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009938 try {
9939 mApp.enforceCallingOrSelfPermission(
9940 android.Manifest.permission.ACCESS_NETWORK_STATE,
9941 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009942 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009943 mApp.enforceCallingOrSelfPermission(
9944 permission.READ_BASIC_PHONE_STATE, functionName);
9945 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009946 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009947 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009948 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009949 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009950
Pengquan Menga1bb6272018-09-06 09:59:22 -07009951 boolean isEnabled = false;
9952 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009953 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009954 Phone phone = getPhone(subId);
9955 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009956 } finally {
9957 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009958 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009959 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009960 }
9961
9962
9963 /**
9964 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9965 *
9966 * <p> Requires permission:
9967 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9968 * privileges.
9969 *
9970 * @param subId subscription id
9971 * @param isEnabled {@code true} means enable, {@code false} means disable.
9972 */
9973 @Override
9974 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9976 mApp, subId, "setDataRoamingEnabled");
9977
Pengquan Menga1bb6272018-09-06 09:59:22 -07009978 final long identity = Binder.clearCallingIdentity();
9979 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009980 Phone phone = getPhone(subId);
9981 if (phone != null) {
9982 phone.setDataRoamingEnabled(isEnabled);
9983 }
9984 } finally {
9985 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009986 }
9987 }
9988
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009989 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009990 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009991 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009992 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009993 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009994
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009995 boolean isAllowed = true;
9996 final long identity = Binder.clearCallingIdentity();
9997 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009998 Phone phone = getPhone(subId);
9999 if (phone != null) {
10000 isAllowed = phone.isCspPlmnEnabled();
10001 }
10002 } finally {
10003 Binder.restoreCallingIdentity(identity);
10004 }
10005 return isAllowed;
10006 }
10007
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010008 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
10009 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -080010010 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010011 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010012 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -080010013 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
10014 if (phone == null) {
10015 return false;
10016 }
10017 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10018 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
10019 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010020 }
10021
Pengquan Meng6884a2c2018-10-03 12:19:13 -070010022 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -080010023 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +000010024 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -070010025 mApp.getSystemService(AppOpsManager.class)
10026 .checkPackage(Binder.getCallingUid(), callingPackage);
10027
Jordan Liu1e142fc2019-04-22 15:10:43 -070010028 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +000010029 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -080010030 try {
10031 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -070010032 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -080010033 } catch (SecurityException e) {
10034 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
10035 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -080010036 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010037 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -070010038 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -080010039 }
Jordan Liu75f43ea2019-01-17 16:56:37 -080010040 }
sandeepjsb6c87872021-09-27 15:34:44 +000010041 // checking compatibility, if calling app's target SDK is T and beyond.
10042 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
10043 Binder.getCallingUid())) {
10044 isIccIdAccessRestricted = true;
10045 }
Jordan Liu5aa07002018-12-18 15:44:48 -080010046 final long identity = Binder.clearCallingIdentity();
10047 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -080010048 UiccController uiccController = UiccController.getInstance();
10049 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -070010050 if (hasReadPermission) {
10051 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -080010052 }
Jordan Liu1e142fc2019-04-22 15:10:43 -070010053
10054 // Remove private info if the caller doesn't have access
10055 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
10056 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +000010057 //setting the value after compatibility check
10058 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -070010059 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
10060 // is available
sandeepjsb6c87872021-09-27 15:34:44 +000010061 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010062 if (card == null) {
10063 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +000010064 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -070010065 continue;
10066 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010067 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
10068 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +000010069 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010070 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -070010071 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010072 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
10073 for (UiccPortInfo portInfo : portInfos) {
10074 UiccPort port = uiccController.getUiccPortForSlot(
10075 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
10076 if (port == null) {
10077 // assume no access if port is null
10078 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
10079 continue;
10080 }
10081 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10082 uiccPortInfos.add(portInfo);
10083 } else {
10084 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
10085 }
10086 }
10087 filteredInfos.add(new UiccCardInfo(
10088 cardInfo.isEuicc(),
10089 cardInfo.getCardId(),
10090 null,
10091 cardInfo.getPhysicalSlotIndex(),
10092 cardInfo.isRemovable(),
10093 cardInfo.isMultipleEnabledProfilesSupported(),
10094 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -070010095 }
10096 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -080010097 } finally {
10098 Binder.restoreCallingIdentity(identity);
10099 }
10100 }
10101
sandeepjsb6c87872021-09-27 15:34:44 +000010102 /**
10103 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
10104 * generally private and require carrier privileges to view.
10105 *
10106 * @hide
10107 */
10108 @NonNull
10109 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
10110 List<UiccPortInfo> portinfo = new ArrayList<>();
10111 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
10112 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
10113 }
10114 return new UiccCardInfo(
10115 cardInfo.isEuicc(),
10116 cardInfo.getCardId(),
10117 null,
10118 cardInfo.getPhysicalSlotIndex(),
10119 cardInfo.isRemovable(),
10120 cardInfo.isMultipleEnabledProfilesSupported(),
10121 portinfo
10122 );
10123 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010124
sandeepjsb6c87872021-09-27 15:34:44 +000010125 /**
10126 * @hide
10127 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
10128 * These values are generally private and require carrier privileges to view.
10129 */
10130 @NonNull
10131 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
10132 return new UiccPortInfo(
10133 UiccPortInfo.ICCID_REDACTED,
10134 portInfo.getPortIndex(),
10135 portInfo.getLogicalSlotIndex(),
10136 portInfo.isActive()
10137 );
10138 }
10139 @Override
10140 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +000010141 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +000010142 mApp.getSystemService(AppOpsManager.class)
10143 .checkPackage(Binder.getCallingUid(), callingPackage);
10144
sandeepjsb6c87872021-09-27 15:34:44 +000010145 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +000010146
Aman Guptaf3c90b32022-03-17 04:54:16 +000010147 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
10148 // we are reading iccId which is PII data.
10149 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +000010150
10151 // checking compatibility, if calling app's target SDK is T and beyond.
10152 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
10153 Binder.getCallingUid())) {
10154 isLogicalSlotAccessRestricted = true;
10155 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010156 final long identity = Binder.clearCallingIdentity();
10157 try {
10158 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +000010159 if (slots == null || slots.length == 0) {
10160 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010161 return null;
10162 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010163 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
10164 for (int i = 0; i < slots.length; i++) {
10165 UiccSlot slot = slots[i];
10166 if (slot == null) {
10167 continue;
10168 }
10169
Jordan Liu7be7e652019-05-06 18:55:02 +000010170 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010171 UiccCard card = slot.getUiccCard();
10172 if (card != null) {
10173 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +000010174 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -070010175 cardId = slot.getEid();
10176 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +000010177 // If cardId is null, use iccId of default port as cardId.
10178 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -070010179 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010180 }
10181
Jordan Liu857451f2019-05-09 16:35:35 -070010182 if (cardId != null) {
10183 // if cardId is an ICCID, strip off trailing Fs before exposing to user
10184 // if cardId is an EID, it's all digits so this is fine
10185 cardId = IccUtils.stripTrailingFs(cardId);
10186 }
10187
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010188 int cardState = 0;
10189 switch (slot.getCardState()) {
10190 case CARDSTATE_ABSENT:
10191 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
10192 break;
10193 case CARDSTATE_PRESENT:
10194 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
10195 break;
10196 case CARDSTATE_ERROR:
10197 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
10198 break;
10199 case CARDSTATE_RESTRICTED:
10200 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
10201 break;
10202 default:
10203 break;
10204
10205 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010206 List<UiccPortInfo> portInfos = new ArrayList<>();
10207 int[] portIndexes = slot.getPortList();
10208 for (int portIdx : portIndexes) {
10209 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010210 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010211 portInfos.add(new UiccPortInfo(iccId, portIdx,
10212 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010213 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010214 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010215 slot.isEuicc(),
10216 cardId,
10217 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010218 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010219 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010220 //setting the value after compatibility check
10221 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010222 }
10223 return infos;
10224 } finally {
10225 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010226 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010227 }
10228
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010229 /* Returns null if doesn't have read permission or carrier privilege access. */
10230 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10231 boolean hasReadPermission) {
10232 String iccId = slot.getIccId(portIndex);
10233 if (hasReadPermission) { // if has read permission
10234 return iccId;
10235 } else {
10236 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10237 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10238 // if no read permission, checking carrier privilege access
10239 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10240 return iccId;
10241 }
10242 }
10243 }
10244 // No read permission or carrier privilege access.
10245 return UiccPortInfo.ICCID_REDACTED;
10246 }
10247
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010248 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010249 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010250 public boolean switchSlots(int[] physicalSlots) {
10251 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010252
10253 final long identity = Binder.clearCallingIdentity();
10254 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010255 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10256 for (int i = 0; i < physicalSlots.length; i++) {
10257 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10258 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10259 physicalSlots[i], i));
10260 }
10261 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010262 } finally {
10263 Binder.restoreCallingIdentity(identity);
10264 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010265 }
Jack Yu4c988042018-02-27 15:30:01 -080010266
10267 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010268 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10269 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10270 enforceModifyPermission();
10271
10272 final long identity = Binder.clearCallingIdentity();
10273 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010274 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010275 } finally {
10276 Binder.restoreCallingIdentity(identity);
10277 }
10278 }
10279
10280 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010281 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -080010282 final long identity = Binder.clearCallingIdentity();
10283 try {
10284 return UiccController.getInstance().getCardIdForDefaultEuicc();
10285 } finally {
10286 Binder.restoreCallingIdentity(identity);
10287 }
10288 }
10289
Pengquan Meng85728fb2018-03-12 16:31:21 -070010290 /**
goneil47ffb6e2018-04-06 15:40:58 -070010291 * A test API to reload the UICC profile.
10292 *
10293 * <p>Requires that the calling app has permission
10294 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10295 * @hide
10296 */
10297 @Override
10298 public void refreshUiccProfile(int subId) {
10299 enforceModifyPermission();
10300
10301 final long identity = Binder.clearCallingIdentity();
10302 try {
10303 Phone phone = getPhone(subId);
10304 if (phone == null) {
10305 return;
10306 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010307 UiccPort uiccPort = phone.getUiccPort();
10308 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010309 return;
10310 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010311 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010312 if (uiccProfile == null) {
10313 return;
10314 }
10315 uiccProfile.refresh();
10316 } finally {
10317 Binder.restoreCallingIdentity(identity);
10318 }
10319 }
10320
10321 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010322 * Returns false if the mobile data is disabled by default, otherwise return true.
10323 */
10324 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010325 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010326 }
10327
10328 /**
10329 * Returns true if the data roaming is enabled by default, i.e the system property
10330 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
10331 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
10332 */
10333 private boolean getDefaultDataRoamingEnabled(int subId) {
10334 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010335 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -070010336 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010337 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
10338 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
10339 return isDataRoamingEnabled;
10340 }
10341
10342 /**
10343 * Returns the default network type for the given {@code subId}, if the default network type is
10344 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10345 */
10346 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010347 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010348 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010349 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10350 return list.get(phoneId);
10351 }
10352 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010353 }
fionaxua13278b2018-03-21 00:08:13 -070010354
10355 @Override
10356 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010357 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010358 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010359
10360 final long identity = Binder.clearCallingIdentity();
10361 try {
10362 final Phone phone = getPhone(subId);
10363 if (phone == null) {
10364 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10365 return;
10366 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010367 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10368 if (cpt != null) {
10369 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10370 }
10371 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010372 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10373 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010374 if (carrierPrivilegeRules == null) {
10375 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10376 } else {
10377 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10378 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010379 } finally {
10380 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010381 }
fionaxua13278b2018-03-21 00:08:13 -070010382 }
10383
10384 @Override
10385 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010386 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010387
10388 final long identity = Binder.clearCallingIdentity();
10389 try {
10390 final Phone phone = getPhone(subId);
10391 if (phone == null) {
10392 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10393 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10394 }
10395 return phone.getCarrierIdListVersion();
10396 } finally {
10397 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010398 }
fionaxua13278b2018-03-21 00:08:13 -070010399 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010400
10401 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010402 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10403 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010404 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010405 mApp, subId, callingPackage, callingFeatureId,
10406 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010407 return -1;
10408 }
10409
10410 final long identity = Binder.clearCallingIdentity();
10411 try {
10412 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10413 } finally {
10414 Binder.restoreCallingIdentity(identity);
10415 }
10416 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010417
10418 @Override
10419 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010420 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010421 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010422 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010423
10424 final long identity = Binder.clearCallingIdentity();
10425 try {
10426 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10427 } finally {
10428 Binder.restoreCallingIdentity(identity);
10429 }
10430 }
10431
10432 @Override
10433 public boolean setCdmaRoamingMode(int subId, int mode) {
10434 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10435 mApp, subId, "setCdmaRoamingMode");
10436
10437 final long identity = Binder.clearCallingIdentity();
10438 try {
10439 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10440 } finally {
10441 Binder.restoreCallingIdentity(identity);
10442 }
10443 }
10444
10445 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010446 public int getCdmaSubscriptionMode(int subId) {
10447 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010448 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010449 mApp, subId, "getCdmaSubscriptionMode");
10450
10451 final long identity = Binder.clearCallingIdentity();
10452 try {
10453 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10454 } finally {
10455 Binder.restoreCallingIdentity(identity);
10456 }
10457 }
10458
10459 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010460 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10461 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10462 mApp, subId, "setCdmaSubscriptionMode");
10463
10464 final long identity = Binder.clearCallingIdentity();
10465 try {
10466 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10467 } finally {
10468 Binder.restoreCallingIdentity(identity);
10469 }
10470 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010471
sqianc5eccab2018-10-19 18:46:41 -070010472 @Override
sqian8c685422019-02-22 15:55:18 -080010473 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010474 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010475 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010476 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10477 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010478 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10479 }
10480 final long identity = Binder.clearCallingIdentity();
10481 try {
sqian854d44b2018-12-12 16:48:18 -080010482 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10483 for (Phone phone: PhoneFactory.getPhones()) {
10484 if (phone.getEmergencyNumberTracker() != null
10485 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10486 emergencyNumberListInternal.put(
10487 phone.getSubId(),
10488 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10489 }
sqian11b7a0e2018-12-05 18:48:28 -080010490 }
sqian854d44b2018-12-12 16:48:18 -080010491 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010492 } finally {
10493 Binder.restoreCallingIdentity(identity);
10494 }
sqianc5eccab2018-10-19 18:46:41 -070010495 }
10496
10497 @Override
sqian8c685422019-02-22 15:55:18 -080010498 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010499 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010500 if (!exactMatch) {
10501 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010502 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010503 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010504 }
10505 final long identity = Binder.clearCallingIdentity();
10506 try {
sqian854d44b2018-12-12 16:48:18 -080010507 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010508 //Note: we ignore passed in param exactMatch. We can remove it once
10509 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010510 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010511 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010512 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010513 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010514 }
sqian11b7a0e2018-12-05 18:48:28 -080010515 }
10516 return false;
10517 } finally {
10518 Binder.restoreCallingIdentity(identity);
10519 }
10520 }
10521
sqianf4ca7ed2019-01-15 18:32:07 -080010522 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010523 * Start emergency callback mode for GsmCdmaPhone for testing.
10524 */
10525 @Override
10526 public void startEmergencyCallbackMode() {
10527 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10528 "startEmergencyCallbackMode");
10529 enforceModifyPermission();
10530 final long identity = Binder.clearCallingIdentity();
10531 try {
10532 for (Phone phone : PhoneFactory.getPhones()) {
10533 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10534 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10535 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10536 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10537 gsmCdmaPhone.obtainMessage(
10538 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10539 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10540 }
10541 }
10542 } finally {
10543 Binder.restoreCallingIdentity(identity);
10544 }
10545 }
10546
10547 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010548 * Update emergency number list for test mode.
10549 */
10550 @Override
10551 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10552 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10553 "updateEmergencyNumberListTestMode");
10554
10555 final long identity = Binder.clearCallingIdentity();
10556 try {
10557 for (Phone phone: PhoneFactory.getPhones()) {
10558 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10559 if (tracker != null) {
10560 tracker.executeEmergencyNumberTestModeCommand(action, num);
10561 }
10562 }
10563 } finally {
10564 Binder.restoreCallingIdentity(identity);
10565 }
10566 }
10567
10568 /**
10569 * Get the full emergency number list for test mode.
10570 */
10571 @Override
10572 public List<String> getEmergencyNumberListTestMode() {
10573 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10574 "getEmergencyNumberListTestMode");
10575
10576 final long identity = Binder.clearCallingIdentity();
10577 try {
10578 Set<String> emergencyNumbers = new HashSet<>();
10579 for (Phone phone: PhoneFactory.getPhones()) {
10580 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10581 if (tracker != null) {
10582 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10583 emergencyNumbers.add(num.getNumber());
10584 }
10585 }
10586 }
10587 return new ArrayList<>(emergencyNumbers);
10588 } finally {
10589 Binder.restoreCallingIdentity(identity);
10590 }
10591 }
10592
chen xud6b45bd2018-10-30 22:27:10 -070010593 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010594 public int getEmergencyNumberDbVersion(int subId) {
10595 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10596
10597 final long identity = Binder.clearCallingIdentity();
10598 try {
10599 final Phone phone = getPhone(subId);
10600 if (phone == null) {
10601 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10602 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10603 }
10604 return phone.getEmergencyNumberDbVersion();
10605 } finally {
10606 Binder.restoreCallingIdentity(identity);
10607 }
10608 }
10609
10610 @Override
10611 public void notifyOtaEmergencyNumberDbInstalled() {
10612 enforceModifyPermission();
10613
10614 final long identity = Binder.clearCallingIdentity();
10615 try {
10616 for (Phone phone: PhoneFactory.getPhones()) {
10617 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10618 if (tracker != null) {
10619 tracker.updateOtaEmergencyNumberDatabase();
10620 }
10621 }
10622 } finally {
10623 Binder.restoreCallingIdentity(identity);
10624 }
10625 }
10626
10627 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010628 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010629 enforceActiveEmergencySessionPermission();
10630
10631 final long identity = Binder.clearCallingIdentity();
10632 try {
10633 for (Phone phone: PhoneFactory.getPhones()) {
10634 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10635 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010636 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10637 }
10638 }
10639 } finally {
10640 Binder.restoreCallingIdentity(identity);
10641 }
10642 }
10643
10644 @Override
10645 public void resetOtaEmergencyNumberDbFilePath() {
10646 enforceActiveEmergencySessionPermission();
10647
10648 final long identity = Binder.clearCallingIdentity();
10649 try {
10650 for (Phone phone: PhoneFactory.getPhones()) {
10651 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10652 if (tracker != null) {
10653 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010654 }
10655 }
10656 } finally {
10657 Binder.restoreCallingIdentity(identity);
10658 }
10659 }
10660
10661 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010662 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10663 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10664 Phone phone = getPhone(subId);
10665 if (phone == null) {
10666 return null;
10667 }
10668 final long identity = Binder.clearCallingIdentity();
10669 try {
10670 UiccProfile profile = UiccController.getInstance()
10671 .getUiccProfileForPhone(phone.getPhoneId());
10672 if (profile != null) {
10673 return profile.getCertsFromCarrierPrivilegeAccessRules();
10674 }
10675 } finally {
10676 Binder.restoreCallingIdentity(identity);
10677 }
10678 return null;
10679 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010680
10681 /**
10682 * Enable or disable a modem stack.
10683 */
10684 @Override
10685 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10686 enforceModifyPermission();
10687
10688 final long identity = Binder.clearCallingIdentity();
10689 try {
10690 Phone phone = PhoneFactory.getPhone(slotIndex);
10691 if (phone == null) {
10692 return false;
10693 } else {
10694 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10695 }
10696 } finally {
10697 Binder.restoreCallingIdentity(identity);
10698 }
10699 }
Michelecea4cf22018-12-21 15:00:11 -080010700
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010701 /**
10702 * Whether a modem stack is enabled or not.
10703 */
10704 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010705 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10706 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010707 Phone phone = PhoneFactory.getPhone(slotIndex);
10708 if (phone == null) return false;
10709
10710 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010711 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10712 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010713 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10714 }
10715
10716 final long identity = Binder.clearCallingIdentity();
10717 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010718 try {
10719 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10720 } catch (NoSuchElementException ex) {
10721 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10722 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010723 } finally {
10724 Binder.restoreCallingIdentity(identity);
10725 }
10726 }
10727
Michelecea4cf22018-12-21 15:00:11 -080010728 @Override
Michele0ea7d782019-03-19 14:58:42 -070010729 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010730 enforceModifyPermission();
10731
10732 final long identity = Binder.clearCallingIdentity();
10733 try {
10734 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010735 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010736 .commit();
10737 } finally {
10738 Binder.restoreCallingIdentity(identity);
10739 }
10740 }
10741
10742 @Override
Michele0ea7d782019-03-19 14:58:42 -070010743 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010744 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010745 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010746 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10747 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010748 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010749 }
Michelecea4cf22018-12-21 15:00:11 -080010750
10751 final long identity = Binder.clearCallingIdentity();
10752 try {
Michele0ea7d782019-03-19 14:58:42 -070010753 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010754 } finally {
10755 Binder.restoreCallingIdentity(identity);
10756 }
10757 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010758
Michele0ea7d782019-03-19 14:58:42 -070010759 @TelephonyManager.IsMultiSimSupportedResult
10760 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010761 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10762 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10763 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010764 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10765 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010766 }
10767 // Check if the hardware supports multisim functionality. If usage of multisim is not
10768 // supported by the modem, indicate that it is restricted.
10769 PhoneCapability staticCapability =
10770 mPhoneConfigurationManager.getStaticPhoneCapability();
10771 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010772 loge("isMultiSimSupportedInternal: no static configuration available");
10773 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010774 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010775 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010776 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10777 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010778 }
10779 // Check if support of multiple SIMs is restricted by carrier
10780 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010781 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010782 }
10783
Michele0ea7d782019-03-19 14:58:42 -070010784 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010785 }
10786
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010787 /**
10788 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010789 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10790 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10791 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010792 * @param numOfSims number of active sims we want to switch to
10793 */
10794 @Override
10795 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010796 if (numOfSims == 1) {
10797 enforceModifyPermission();
10798 } else {
10799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10800 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10801 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010802 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010803
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010804 try {
Michele30b57b22019-03-01 12:01:14 -080010805 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010806 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010807 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10808 return;
10809 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010810 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10811 } finally {
10812 Binder.restoreCallingIdentity(identity);
10813 }
10814 }
10815
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010816 @Override
10817 public boolean isApplicationOnUicc(int subId, int appType) {
10818 enforceReadPrivilegedPermission("isApplicationOnUicc");
10819 Phone phone = getPhone(subId);
10820 if (phone == null) {
10821 return false;
10822 }
10823 final long identity = Binder.clearCallingIdentity();
10824 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010825 UiccPort uiccPort = phone.getUiccPort();
10826 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010827 return false;
10828 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010829 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010830 if (uiccProfile == null) {
10831 return false;
10832 }
10833 if (TelephonyManager.APPTYPE_SIM <= appType
10834 && appType <= TelephonyManager.APPTYPE_ISIM) {
10835 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10836 }
10837 return false;
10838 } finally {
10839 Binder.restoreCallingIdentity(identity);
10840 }
10841 }
10842
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010843 /**
chen xub4baa772019-04-03 10:23:41 -070010844 * Get whether making changes to modem configurations will trigger reboot.
10845 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010846 */
10847 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010848 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10849 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010850 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010851 mApp, subId, callingPackage, callingFeatureId,
10852 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010853 return false;
10854 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010855 final long identity = Binder.clearCallingIdentity();
10856 try {
10857 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10858 } finally {
10859 Binder.restoreCallingIdentity(identity);
10860 }
10861 }
10862
Nathan Harold29f5f052019-02-15 13:41:57 -080010863 private void updateModemStateMetrics() {
10864 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10865 // TODO: check the state for each modem if the api is ready.
10866 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10867 }
10868
Pengquan Meng3889a572019-01-23 11:16:29 -080010869 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010870 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010871 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010872 // Verify that the callingPackage belongs to the calling UID
10873 mApp.getSystemService(AppOpsManager.class)
10874 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010875 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010876 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010877 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010878 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10879 if (slotInfos != null) {
10880 for (int i = 0; i < slotInfos.length; i++) {
10881 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10882 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10883 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10884 portInfo.getLogicalSlotIndex()));
10885 }
10886 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010887 }
10888 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010889 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010890 } finally {
10891 Binder.restoreCallingIdentity(identity);
10892 }
10893 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010894
10895 /**
10896 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010897 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010898 */
jimsunf9ec1622022-09-13 21:18:43 +080010899 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010900 @Override
10901 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010902 return getHalVersion(HAL_SERVICE_RADIO);
10903 }
10904
10905 /**
10906 * Get the HAL Version of a specific service
10907 */
10908 @Override
10909 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010910 Phone phone = getDefaultPhone();
10911 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010912 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010913 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10914 return hv.major * 100 + hv.minor;
10915 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010916
10917 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010918 * Get the current calling package name.
10919 * @return the current calling package name
10920 */
10921 @Override
10922 public String getCurrentPackageName() {
10923 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10924 }
10925
10926 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010927 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10928 * corresponding network requests on a subId.
10929 *
10930 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010931 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010932 * 2) APN is un-metered for this subscription, or
10933 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010934 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010935 *
10936 * @return whether data is allowed for a apn type.
10937 *
10938 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010939 */
10940 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010941 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010942 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10943 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010944
10945 // Now that all security checks passes, perform the operation as ourselves.
10946 final long identity = Binder.clearCallingIdentity();
10947 try {
10948 Phone phone = getPhone(subId);
10949 if (phone == null) return false;
10950
Jack Yu27422a52022-03-21 10:38:05 -070010951 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010952 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010953 isMetered = phone.getDataNetworkController().getDataConfigManager()
10954 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10955 phone.getServiceState().getDataRoaming());
10956 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010957 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010958 } finally {
10959 Binder.restoreCallingIdentity(identity);
10960 }
10961 }
10962
10963 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010964 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010965 enforceReadPrivilegedPermission("isApnMetered");
10966
10967 // Now that all security checks passes, perform the operation as ourselves.
10968 final long identity = Binder.clearCallingIdentity();
10969 try {
10970 Phone phone = getPhone(subId);
10971 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010972 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10973 DataUtils.apnTypeToNetworkCapability(apnType),
10974 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010975 } finally {
10976 Binder.restoreCallingIdentity(identity);
10977 }
10978 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010979
10980 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010981 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10982 int subscriptionId, IBooleanConsumer resultCallback) {
10983 enforceModifyPermission();
10984 long token = Binder.clearCallingIdentity();
10985 try {
10986 Phone phone = getPhone(subscriptionId);
10987 if (phone == null) {
10988 try {
10989 if (resultCallback != null) {
10990 resultCallback.accept(false);
10991 }
10992 } catch (RemoteException e) {
10993 // ignore
10994 }
10995 return;
10996 }
10997 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10998 Pair.create(specifiers, (x) -> {
10999 try {
11000 if (resultCallback != null) {
11001 resultCallback.accept(x);
11002 }
11003 } catch (RemoteException e) {
11004 // ignore
11005 }
11006 });
11007 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
11008 } finally {
11009 Binder.restoreCallingIdentity(token);
11010 }
11011 }
11012
11013 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080011014 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
11015 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070011016 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080011017 mApp, subId, "getSystemSelectionChannels");
11018 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11019 final long identity = Binder.clearCallingIdentity();
11020 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080011021 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
11022 if (result instanceof IllegalStateException) {
11023 throw (IllegalStateException) result;
11024 }
11025 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080011026 if (DBG) log("getSystemSelectionChannels: " + specifiers);
11027 return specifiers;
11028 } finally {
11029 Binder.restoreCallingIdentity(identity);
11030 }
11031 }
11032
11033 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070011034 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080011035 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070011036 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080011037 }
11038
11039 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011040 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
11041 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080011042 if (callingPackage == null) {
11043 callingPackage = getCurrentPackageName();
11044 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070011045 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
11046 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011047 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
11048 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070011049 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
11050 }
11051 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
11052 Intent intent = new Intent();
11053 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
11054 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11055 // Bring up choose default SMS subscription dialog right now
11056 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
11057 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
11058 mApp.startActivity(intent);
11059 }
chen xud5ca2d52019-05-28 15:20:57 -070011060
11061 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000011062 public void showSwitchToManagedProfileDialog() {
11063 enforceModifyPermission();
11064
11065 Intent intent = new Intent();
11066 intent.setClass(mApp, ErrorDialogActivity.class);
11067 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11068 mApp.startActivity(intent);
11069 }
11070
11071 @Override
chen xud5ca2d52019-05-28 15:20:57 -070011072 public String getMmsUAProfUrl(int subId) {
11073 //TODO investigate if this API should require proper permission check in R b/133791609
11074 final long identity = Binder.clearCallingIdentity();
11075 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011076 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
11077 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
11078 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
11079 return carrierUAProfUrl;
11080 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011081 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11082 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070011083 } finally {
11084 Binder.restoreCallingIdentity(identity);
11085 }
11086 }
11087
11088 @Override
11089 public String getMmsUserAgent(int subId) {
11090 //TODO investigate if this API should require proper permission check in R b/133791609
11091 final long identity = Binder.clearCallingIdentity();
11092 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011093 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
11094 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
11095 if (!TextUtils.isEmpty(carrierUserAgent)) {
11096 return carrierUserAgent;
11097 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011098 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11099 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011100 } finally {
11101 Binder.restoreCallingIdentity(identity);
11102 }
11103 }
Jack Yub07d4972019-05-28 16:12:25 -070011104
11105 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011106 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11107 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011108
Jack Yub07d4972019-05-28 16:12:25 -070011109 final long identity = Binder.clearCallingIdentity();
11110 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011111 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070011112 if (phone == null) return false;
11113
Ling Maf188d502022-09-16 15:22:36 -070011114 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011115 } finally {
11116 Binder.restoreCallingIdentity(identity);
11117 }
11118 }
11119
11120 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011121 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011122 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011123 enforceModifyPermission();
11124
changbettyd5c246e2019-12-24 15:40:37 +080011125 final long identity = Binder.clearCallingIdentity();
11126 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011127 Phone phone = getPhone(subscriptionId);
11128 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011129
Ling Maf188d502022-09-16 15:22:36 -070011130 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011131 } finally {
11132 Binder.restoreCallingIdentity(identity);
11133 }
11134 }
11135
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011136 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011137 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011138 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11139 * otherwise.
11140 */
11141 @Override
11142 public void setCepEnabled(boolean isCepEnabled) {
11143 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11144
11145 final long identity = Binder.clearCallingIdentity();
11146 try {
11147 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11148 for (Phone phone : PhoneFactory.getPhones()) {
11149 Phone defaultPhone = phone.getImsPhone();
11150 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11151 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11152 ImsPhoneCallTracker imsPhoneCallTracker =
11153 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11154 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11155 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11156 + imsPhone.getMsisdn());
11157 }
11158 }
11159 } finally {
11160 Binder.restoreCallingIdentity(identity);
11161 }
11162 }
allenwtsu46dcc572020-01-08 18:24:03 +080011163
11164 /**
11165 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11166 *
11167 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11168 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11169 * before being read.
11170 */
11171 @Override
11172 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11173 isCompressed) {
11174 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11175 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011176 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11177 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11178 }
11179 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011180 // ProvisioningManager can not handle ServiceSpecificException.
11181 // Throw the IllegalStateException and annotate ProvisioningManager.
11182 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000011183 }
11184
11185 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011186 try {
Hui Wang761a6682020-10-31 05:12:53 +000011187 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11188 } finally {
11189 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011190 }
11191 }
zoey chene02881a2019-12-30 16:11:23 +080011192
11193 @Override
11194 public boolean isIccLockEnabled(int subId) {
11195 enforceReadPrivilegedPermission("isIccLockEnabled");
11196
11197 // Now that all security checks passes, perform the operation as ourselves.
11198 final long identity = Binder.clearCallingIdentity();
11199 try {
11200 Phone phone = getPhone(subId);
11201 if (phone != null && phone.getIccCard() != null) {
11202 return phone.getIccCard().getIccLockEnabled();
11203 } else {
11204 return false;
11205 }
11206 } finally {
11207 Binder.restoreCallingIdentity(identity);
11208 }
11209 }
11210
11211 /**
11212 * Set the ICC pin lock enabled or disabled.
11213 *
11214 * @return an integer representing the status of IccLock enabled or disabled in the following
11215 * three cases:
11216 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11217 * successfully.
11218 * - Positive number and zero for remaining password attempts.
11219 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11220 *
11221 */
11222 @Override
11223 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11224 enforceModifyPermission();
11225
11226 Phone phone = getPhone(subId);
11227 if (phone == null) {
11228 return 0;
11229 }
11230 // Now that all security checks passes, perform the operation as ourselves.
11231 final long identity = Binder.clearCallingIdentity();
11232 try {
11233 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11234 new Pair<Boolean, String>(enabled, password), phone, null);
11235 return attemptsRemaining;
11236
11237 } catch (Exception e) {
11238 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11239 } finally {
11240 Binder.restoreCallingIdentity(identity);
11241 }
11242 return 0;
11243 }
11244
11245 /**
11246 * Change the ICC password used in ICC pin lock.
11247 *
11248 * @return an integer representing the status of IccLock changed in the following three cases:
11249 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11250 * - Positive number and zero for remaining password attempts.
11251 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11252 *
11253 */
11254 @Override
11255 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11256 enforceModifyPermission();
11257
11258 Phone phone = getPhone(subId);
11259 if (phone == null) {
11260 return 0;
11261 }
11262 // Now that all security checks passes, perform the operation as ourselves.
11263 final long identity = Binder.clearCallingIdentity();
11264 try {
11265 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11266 new Pair<String, String>(oldPassword, newPassword), phone, null);
11267 return attemptsRemaining;
11268
11269 } catch (Exception e) {
11270 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11271 } finally {
11272 Binder.restoreCallingIdentity(identity);
11273 }
11274 return 0;
11275 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011276
11277 /**
11278 * Request for receiving user activity notification
11279 */
11280 @Override
11281 public void requestUserActivityNotification() {
11282 if (!mNotifyUserActivity.get()
11283 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11284 mNotifyUserActivity.set(true);
11285 }
11286 }
11287
11288 /**
11289 * Called when userActivity is signalled in the power manager.
11290 * This is safe to call from any thread, with any window manager locks held or not.
11291 */
11292 @Override
11293 public void userActivity() {
11294 // ***************************************
11295 // * Inherited from PhoneWindowManager *
11296 // ***************************************
11297 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11298 // WITH ITS LOCKS HELD.
11299 //
11300 // This code must be VERY careful about the locks
11301 // it acquires.
11302 // In fact, the current code acquires way too many,
11303 // and probably has lurking deadlocks.
11304
11305 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11306 throw new SecurityException("Only the OS may call notifyUserActivity()");
11307 }
11308
11309 if (mNotifyUserActivity.getAndSet(false)) {
11310 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11311 USER_ACTIVITY_NOTIFICATION_DELAY);
11312 }
11313 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011314
11315 @Override
11316 public boolean canConnectTo5GInDsdsMode() {
11317 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11318 }
Jack Yud10cdd42020-09-28 20:28:01 -070011319
11320 @Override
11321 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11322 String callingFeatureId) {
11323 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11324 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11325 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11326 }
11327
11328 Phone phone = getPhone(subId);
11329 if (phone == null) {
11330 throw new RuntimeException("phone is not available");
11331 }
11332 // Now that all security checks passes, perform the operation as ourselves.
11333 final long identity = Binder.clearCallingIdentity();
11334 try {
11335 return phone.getEquivalentHomePlmns();
11336 } finally {
11337 Binder.restoreCallingIdentity(identity);
11338 }
11339 }
Daniel Bright59e67312020-11-13 11:49:37 -080011340
11341 @Override
11342 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011343 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
11344 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011345 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011346 if (radioInterfaceCapabilities == null) {
11347 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011348 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011349 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011350 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011351
Hui Wang641e81c2020-10-12 12:14:23 -070011352 @Override
11353 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11354 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011355 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11356 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11357 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11358 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11359 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070011360 if (DBG) {
11361 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11362 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11363 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11364 }
11365
11366 if (!SubscriptionManager.isValidSubscriptionId(subId)
11367 || appType < TelephonyManager.APPTYPE_UNKNOWN
11368 || appType > TelephonyManager.APPTYPE_ISIM
11369 || nafUrl == null || securityProtocol == null || callback == null) {
11370 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11371 if (callback != null) {
11372 try {
11373 callback.onAuthenticationFailure(
11374 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11375 } catch (RemoteException exception) {
11376 log("Fail to notify onAuthenticationFailure due to " + exception);
11377 }
11378 return;
11379 }
11380 }
11381
11382 final long token = Binder.clearCallingIdentity();
11383 try {
11384 getGbaManager(subId).bootstrapAuthenticationRequest(
11385 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011386 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011387 } finally {
11388 Binder.restoreCallingIdentity(token);
11389 }
11390 }
11391
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011392 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011393 * Attempts to set the radio power state for all phones for thermal reason.
11394 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011395 * requested radio power state will actually be set. See {@link
11396 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11397 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011398 * @param enable {@code true} if trying to turn radio on.
11399 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11400 * false}.
11401 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011402 private boolean setRadioPowerForThermal(boolean enable) {
11403 boolean isPhoneAvailable = false;
11404 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11405 Phone phone = PhoneFactory.getPhone(i);
11406 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011407 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011408 isPhoneAvailable = true;
11409 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011410 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011411
11412 // return true if successfully informed the phone object about the thermal radio power
11413 // request.
11414 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011415 }
11416
11417 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011418 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011419 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11420 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11421 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11422 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11423 throw new IllegalArgumentException("modem does not support data throttling");
11424 }
11425
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011426 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11427 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011428 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011429 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11430 }
11431
Sarah Chinecc78c42022-03-31 21:16:48 -070011432 setDataEnabledForReason(
11433 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011434
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011435 if (isDataThrottlingSupported) {
11436 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011437 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011438 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11439 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11440 } else if (thermalMitigationResult
11441 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011442 log("Modem likely does not support data throttling on secondary carrier. Data " +
11443 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11444 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011445 }
11446 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011447 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011448
11449 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011450 }
11451
Jack Nudelman644b91a2021-03-12 14:09:48 -080011452 private static List<String> getThermalMitigationAllowlist(Context context) {
11453 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11454 for (String pckg : context.getResources()
11455 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11456 sThermalMitigationAllowlistedPackages.add(pckg);
11457 }
11458 }
11459
11460 return sThermalMitigationAllowlistedPackages;
11461 }
11462
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011463 private boolean isAnyPhoneInEmergencyState() {
11464 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11465 if (tm.isInEmergencyCall()) {
11466 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11467 return true;
11468 }
11469 for (Phone phone : PhoneFactory.getPhones()) {
11470 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11471 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011472 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11473 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011474 return true;
11475 }
11476 }
11477
11478 return false;
11479 }
11480
Jack Nudelman644b91a2021-03-12 14:09:48 -080011481 /**
11482 * Used by shell commands to add an authorized package name for thermal mitigation.
11483 * @param packageName name of package to be allowlisted
11484 * @param context
11485 */
11486 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11487 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11488 sThermalMitigationAllowlistedPackages.add(packageName);
11489 }
11490
11491 /**
11492 * Used by shell commands to remove an authorized package name for thermal mitigation.
11493 * @param packageName name of package to remove from allowlist
11494 * @param context
11495 */
11496 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11497 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11498 sThermalMitigationAllowlistedPackages.remove(packageName);
11499 }
11500
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011501 /**
11502 * Thermal mitigation request to control functionalities at modem.
11503 *
11504 * @param subId the id of the subscription.
11505 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011506 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011507 *
11508 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11509 */
11510 @Override
11511 @ThermalMitigationResult
11512 public int sendThermalMitigationRequest(
11513 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011514 ThermalMitigationRequest thermalMitigationRequest,
11515 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011516 enforceModifyPermission();
11517
Jack Nudelman644b91a2021-03-12 14:09:48 -080011518 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11519 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11520 .contains(callingPackage)) {
11521 throw new SecurityException("Calling package must be configured in the device config. "
11522 + "calling package: " + callingPackage);
11523 }
11524
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011525 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11526 final long identity = Binder.clearCallingIdentity();
11527
11528 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11529 try {
11530 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11531 switch (thermalMitigationAction) {
11532 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11533 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011534 handleDataThrottlingRequest(subId,
11535 thermalMitigationRequest.getDataThrottlingRequest(),
11536 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011537 break;
11538 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11539 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11540 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11541 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11542 }
11543
11544 // Ensure that radio is on. If not able to power on due to phone being
11545 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011546 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011547 thermalMitigationResult =
11548 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11549 break;
11550 }
11551
11552 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011553 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011554 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11555 break;
11556 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11557 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11558 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11559 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11560 }
11561
11562 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11563 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011564 Phone phone = getPhone(subId);
11565 if (phone == null) {
11566 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011567 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011568 break;
11569 }
11570
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011571 TelephonyConnectionService service =
11572 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011573 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011574 Log.e(LOG_TAG, "An emergency call is pending");
11575 thermalMitigationResult =
11576 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11577 break;
11578 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011579 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011580 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011581 break;
11582 }
11583 } else {
11584 thermalMitigationResult =
11585 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11586 break;
11587 }
11588
11589 // Turn radio off. If not able to power off due to phone being unavailable,
11590 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011591 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011592 thermalMitigationResult =
11593 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11594 break;
11595 }
11596 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011597 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011598 break;
11599 default:
11600 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11601 + "not exist. Requested action: " + thermalMitigationAction);
11602 }
11603 } catch (IllegalArgumentException e) {
11604 throw e;
11605 } catch (Exception e) {
11606 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11607 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11608 } finally {
11609 Binder.restoreCallingIdentity(identity);
11610 }
11611
11612 if (DBG) {
11613 log("thermalMitigationRequest returning with thermalMitigationResult: "
11614 + thermalMitigationResult);
11615 }
11616
11617 return thermalMitigationResult;
11618 }
Hui Wang641e81c2020-10-12 12:14:23 -070011619
11620 /**
11621 * Set the GbaService Package Name that Telephony will bind to.
11622 *
11623 * @param subId The sim that the GbaService is associated with.
11624 * @param packageName The name of the package to be replaced with.
11625 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11626 */
11627 @Override
11628 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11629 enforceModifyPermission();
11630
11631 final long identity = Binder.clearCallingIdentity();
11632 try {
11633 return getGbaManager(subId).overrideServicePackage(packageName);
11634 } finally {
11635 Binder.restoreCallingIdentity(identity);
11636 }
11637 }
11638
11639 /**
11640 * Return the package name of the currently bound GbaService.
11641 *
11642 * @param subId The sim that the GbaService is associated with.
11643 * @return the package name of the GbaService configuration, null if GBA is not supported.
11644 */
11645 @Override
11646 public String getBoundGbaService(int subId) {
11647 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11648
11649 final long identity = Binder.clearCallingIdentity();
11650 try {
11651 return getGbaManager(subId).getServicePackage();
11652 } finally {
11653 Binder.restoreCallingIdentity(identity);
11654 }
11655 }
11656
11657 /**
11658 * Set the release time for telephony to unbind GbaService.
11659 *
11660 * @param subId The sim that the GbaService is associated with.
11661 * @param interval The release time to unbind GbaService by millisecond.
11662 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11663 */
11664 @Override
11665 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11666 enforceModifyPermission();
11667
11668 final long identity = Binder.clearCallingIdentity();
11669 try {
11670 return getGbaManager(subId).overrideReleaseTime(interval);
11671 } finally {
11672 Binder.restoreCallingIdentity(identity);
11673 }
11674 }
11675
11676 /**
11677 * Return the release time for telephony to unbind GbaService.
11678 *
11679 * @param subId The sim that the GbaService is associated with.
11680 * @return The release time to unbind GbaService by millisecond.
11681 */
11682 @Override
11683 public int getGbaReleaseTime(int subId) {
11684 enforceReadPrivilegedPermission("getGbaReleaseTime");
11685
11686 final long identity = Binder.clearCallingIdentity();
11687 try {
11688 return getGbaManager(subId).getReleaseTime();
11689 } finally {
11690 Binder.restoreCallingIdentity(identity);
11691 }
11692 }
11693
11694 private GbaManager getGbaManager(int subId) {
11695 GbaManager instance = GbaManager.getInstance(subId);
11696 if (instance == null) {
11697 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11698 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11699 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11700 }
11701 return instance;
11702 }
Hui Wang761a6682020-10-31 05:12:53 +000011703
11704 /**
11705 * indicate whether the device and the carrier can support
11706 * RCS VoLTE single registration.
11707 */
11708 @Override
11709 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011710 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11711 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11712 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11713 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011714
11715 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11716 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11717 }
11718
11719 final long identity = Binder.clearCallingIdentity();
11720 try {
11721 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11722 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011723 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11724 if (isCapable != null) {
11725 return isCapable;
11726 }
Hui Wang761a6682020-10-31 05:12:53 +000011727 }
Hui Wang67af90e2021-06-04 16:57:15 -070011728 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11729 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011730 } finally {
11731 Binder.restoreCallingIdentity(identity);
11732 }
11733 }
11734
11735 /**
11736 * Register RCS provisioning callback.
11737 */
11738 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011739 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011740 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011741 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011742 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011743 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11744 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011745
11746 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11747 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11748 }
11749 if (!isImsAvailableOnDevice()) {
11750 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11751 "IMS not available on device.");
11752 }
11753
11754 final long identity = Binder.clearCallingIdentity();
11755 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011756 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011757 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011758 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11759 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011760 }
Hui Wang761a6682020-10-31 05:12:53 +000011761 } finally {
11762 Binder.restoreCallingIdentity(identity);
11763 }
11764 }
11765
11766 /**
11767 * Unregister RCS provisioning callback.
11768 */
11769 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011770 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011771 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011772 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011773 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011774 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11775 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011776
11777 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11778 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11779 }
11780 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011781 // operation failed silently
11782 Rlog.w(LOG_TAG, "IMS not available on device.");
11783 return;
Hui Wang761a6682020-10-31 05:12:53 +000011784 }
11785
11786 final long identity = Binder.clearCallingIdentity();
11787 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011788 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011789 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011790 } finally {
11791 Binder.restoreCallingIdentity(identity);
11792 }
11793 }
11794
11795 /**
11796 * trigger RCS reconfiguration.
11797 */
11798 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011799 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11800 "triggerRcsReconfiguration",
11801 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011802
11803 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11804 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11805 }
11806 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011807 // ProvisioningManager can not handle ServiceSpecificException.
11808 // Throw the IllegalStateException and annotate ProvisioningManager.
11809 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000011810 }
11811
11812 final long identity = Binder.clearCallingIdentity();
11813 try {
11814 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11815 } finally {
11816 Binder.restoreCallingIdentity(identity);
11817 }
11818 }
11819
11820 /**
11821 * Provide the client configuration parameters of the RCS application.
11822 */
11823 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011824 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11825 "setRcsClientConfiguration",
11826 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011827
11828 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11829 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11830 }
11831 if (!isImsAvailableOnDevice()) {
11832 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11833 "IMS not available on device.");
11834 }
11835
11836 final long identity = Binder.clearCallingIdentity();
11837
11838 try {
11839 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11840 if (configBinder == null) {
11841 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011842 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11843 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011844 } else {
11845 configBinder.setRcsClientConfiguration(rcc);
11846 }
joonhunshin3e154242021-09-17 06:33:39 +000011847
11848 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11849 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011850 } catch (RemoteException e) {
11851 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011852 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11853 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011854 } finally {
11855 Binder.restoreCallingIdentity(identity);
11856 }
11857 }
11858
11859 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011860 * Enables or disables the test mode for RCS VoLTE single registration.
11861 */
11862 @Override
11863 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11864 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11865 "setRcsSingleRegistrationTestModeEnabled");
11866
11867 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11868 }
11869
11870 /**
11871 * Gets the test mode for RCS VoLTE single registration.
11872 */
11873 @Override
11874 public boolean getRcsSingleRegistrationTestModeEnabled() {
11875 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11876 "getRcsSingleRegistrationTestModeEnabled");
11877
11878 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11879 }
11880
11881 /**
Hui Wang761a6682020-10-31 05:12:53 +000011882 * Overrides the config of RCS VoLTE single registration enabled for the device.
11883 */
11884 @Override
11885 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11886 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11887 "setDeviceSingleRegistrationEnabledOverride");
11888 enforceModifyPermission();
11889
11890 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11891 : Boolean.parseBoolean(enabledStr);
11892 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011893 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011894 }
11895
11896 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011897 * Sends a device to device communication message. Only usable via shell.
11898 * @param message message to send.
11899 * @param value message value.
11900 */
11901 @Override
11902 public void sendDeviceToDeviceMessage(int message, int value) {
11903 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011904 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011905 enforceModifyPermission();
11906
11907 final long identity = Binder.clearCallingIdentity();
11908 try {
11909 TelephonyConnectionService service =
11910 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11911 if (service == null) {
11912 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11913 return;
11914 }
11915 service.sendTestDeviceToDeviceMessage(message, value);
11916 } finally {
11917 Binder.restoreCallingIdentity(identity);
11918 }
11919 }
11920
Tyler Gunnbabbda02021-02-10 11:05:02 -080011921 /**
11922 * Sets the specified device to device transport active.
11923 * @param transport The transport to set active.
11924 */
11925 @Override
11926 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11927 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11928 "setActiveDeviceToDeviceTransport");
11929 enforceModifyPermission();
11930
11931 final long identity = Binder.clearCallingIdentity();
11932 try {
11933 TelephonyConnectionService service =
11934 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11935 if (service == null) {
11936 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11937 return;
11938 }
11939 service.setActiveDeviceToDeviceTransport(transport);
11940 } finally {
11941 Binder.restoreCallingIdentity(identity);
11942 }
11943 }
Tyler Gunn92479152021-01-20 16:30:10 -080011944
Tyler Gunnd4339262021-05-03 14:46:49 -070011945 @Override
11946 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11947 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11948 "setDeviceToDeviceForceEnabled");
11949
11950 final long identity = Binder.clearCallingIdentity();
11951 try {
11952 Arrays.stream(PhoneFactory.getPhones()).forEach(
11953 p -> {
11954 Phone thePhone = p.getImsPhone();
11955 if (thePhone != null && thePhone instanceof ImsPhone) {
11956 ImsPhone imsPhone = (ImsPhone) thePhone;
11957 CallTracker tracker = imsPhone.getCallTracker();
11958 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11959 ImsPhoneCallTracker imsPhoneCallTracker =
11960 (ImsPhoneCallTracker) tracker;
11961 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11962 }
11963 }
11964 }
11965 );
11966 } finally {
11967 Binder.restoreCallingIdentity(identity);
11968 }
11969 }
11970
Tyler Gunn92479152021-01-20 16:30:10 -080011971 /**
Hui Wang761a6682020-10-31 05:12:53 +000011972 * Gets the config of RCS VoLTE single registration enabled for the device.
11973 */
11974 @Override
11975 public boolean getDeviceSingleRegistrationEnabled() {
11976 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11977 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11978 }
11979
11980 /**
11981 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11982 */
11983 @Override
11984 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11985 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11986 "setCarrierSingleRegistrationEnabledOverride");
11987 enforceModifyPermission();
11988
11989 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11990 : Boolean.parseBoolean(enabledStr);
11991 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11992 subId, enabled);
11993 }
11994
11995 /**
11996 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11997 */
11998 @Override
11999 public boolean getCarrierSingleRegistrationEnabled(int subId) {
12000 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
12001 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
12002 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080012003
12004 /**
Hui Wangb647abe2021-02-26 09:33:38 -080012005 * Overrides the ims feature validation result
12006 */
12007 @Override
12008 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
12009 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12010 "setImsFeatureValidationOverride");
12011
12012 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12013 : Boolean.parseBoolean(enabledStr);
12014 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
12015 subId, enabled);
12016 }
12017
12018 /**
12019 * Gets the ims feature validation override value
12020 */
12021 @Override
12022 public boolean getImsFeatureValidationOverride(int subId) {
12023 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12024 "getImsFeatureValidationOverride");
12025 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
12026 }
12027
12028 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012029 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12030 * their mobile plan.
12031 */
12032 @Override
12033 public String getMobileProvisioningUrl() {
12034 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12035 final long identity = Binder.clearCallingIdentity();
12036 try {
12037 return getDefaultPhone().getMobileProvisioningUrl();
12038 } finally {
12039 Binder.restoreCallingIdentity(identity);
12040 }
12041 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012042
James.cf Linbcdf8b32021-01-14 16:44:13 +080012043 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012044 * Get the EAB contact from the EAB database.
12045 */
12046 @Override
12047 public String getContactFromEab(String contact) {
12048 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12049 enforceModifyPermission();
12050 final long identity = Binder.clearCallingIdentity();
12051 try {
12052 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12053 } finally {
12054 Binder.restoreCallingIdentity(identity);
12055 }
12056 }
12057
12058 /**
Calvin Pana1434322021-07-01 19:27:01 +080012059 * Get the EAB capability from the EAB database.
12060 */
12061 @Override
12062 public String getCapabilityFromEab(String contact) {
12063 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12064 enforceModifyPermission();
12065 final long identity = Binder.clearCallingIdentity();
12066 try {
12067 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12068 } finally {
12069 Binder.restoreCallingIdentity(identity);
12070 }
12071 }
12072
12073 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012074 * Remove the EAB contacts from the EAB database.
12075 */
12076 @Override
12077 public int removeContactFromEab(int subId, String contacts) {
12078 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12079 enforceModifyPermission();
12080 final long identity = Binder.clearCallingIdentity();
12081 try {
12082 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12083 } finally {
12084 Binder.restoreCallingIdentity(identity);
12085 }
12086 }
12087
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012088 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012089 public boolean getDeviceUceEnabled() {
12090 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12091 final long identity = Binder.clearCallingIdentity();
12092 try {
12093 return mApp.getDeviceUceEnabled();
12094 } finally {
12095 Binder.restoreCallingIdentity(identity);
12096 }
12097 }
12098
12099 @Override
12100 public void setDeviceUceEnabled(boolean isEnabled) {
12101 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12102 final long identity = Binder.clearCallingIdentity();
12103 try {
12104 mApp.setDeviceUceEnabled(isEnabled);
12105 } finally {
12106 Binder.restoreCallingIdentity(identity);
12107 }
12108 }
12109
Brad Ebinger14d467f2021-02-12 06:18:28 +000012110 /**
12111 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12112 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12113 */
12114 // Used for SHELL command only right now.
12115 @Override
12116 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12117 List<String> featureTags) {
12118 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12119 "addUceRegistrationOverrideShell");
12120 final long identity = Binder.clearCallingIdentity();
12121 try {
12122 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12123 new ArraySet<>(featureTags));
12124 } catch (ImsException e) {
12125 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12126 } finally {
12127 Binder.restoreCallingIdentity(identity);
12128 }
12129 }
12130
12131 /**
12132 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12133 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12134 */
12135 // Used for SHELL command only right now.
12136 @Override
12137 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12138 List<String> featureTags) {
12139 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12140 "removeUceRegistrationOverrideShell");
12141 final long identity = Binder.clearCallingIdentity();
12142 try {
12143 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12144 new ArraySet<>(featureTags));
12145 } catch (ImsException e) {
12146 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12147 } finally {
12148 Binder.restoreCallingIdentity(identity);
12149 }
12150 }
12151
12152 /**
12153 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12154 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12155 */
12156 // Used for SHELL command only right now.
12157 @Override
12158 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12159 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12160 "clearUceRegistrationOverrideShell");
12161 final long identity = Binder.clearCallingIdentity();
12162 try {
12163 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12164 } catch (ImsException e) {
12165 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12166 } finally {
12167 Binder.restoreCallingIdentity(identity);
12168 }
12169 }
12170
12171 /**
12172 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12173 */
12174 // Used for SHELL command only right now.
12175 @Override
12176 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12177 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12178 "getLatestRcsContactUceCapabilityShell");
12179 final long identity = Binder.clearCallingIdentity();
12180 try {
12181 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12182 } catch (ImsException e) {
12183 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12184 } finally {
12185 Binder.restoreCallingIdentity(identity);
12186 }
12187 }
12188
12189 /**
12190 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12191 * device does not have an active PUBLISH.
12192 */
12193 // Used for SHELL command only right now.
12194 @Override
12195 public String getLastUcePidfXmlShell(int subId) {
12196 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12197 final long identity = Binder.clearCallingIdentity();
12198 try {
12199 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12200 } catch (ImsException e) {
12201 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12202 } finally {
12203 Binder.restoreCallingIdentity(identity);
12204 }
12205 }
12206
James.cf Line8713a42021-04-29 16:04:26 +080012207 /**
12208 * Remove UCE requests cannot be sent to the network status.
12209 */
12210 // Used for SHELL command only right now.
12211 @Override
12212 public boolean removeUceRequestDisallowedStatus(int subId) {
12213 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12214 final long identity = Binder.clearCallingIdentity();
12215 try {
12216 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12217 } catch (ImsException e) {
12218 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12219 } finally {
12220 Binder.restoreCallingIdentity(identity);
12221 }
12222 }
12223
James.cf Lin18bb9002021-05-25 01:37:38 +080012224 /**
12225 * Remove UCE requests cannot be sent to the network status.
12226 */
12227 // Used for SHELL command only.
12228 @Override
12229 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12230 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12231 final long identity = Binder.clearCallingIdentity();
12232 try {
12233 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12234 } catch (ImsException e) {
12235 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12236 } finally {
12237 Binder.restoreCallingIdentity(identity);
12238 }
12239 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012240
James.cf Lin4b784aa2021-01-31 03:25:15 +080012241 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012242 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12243 String callingPackage) {
12244 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12245 mApp, subId, "setSignalStrengthUpdateRequest");
12246
12247 final int callingUid = Binder.getCallingUid();
12248 // Verify that tha callingPackage belongs to the calling UID
12249 mApp.getSystemService(AppOpsManager.class)
12250 .checkPackage(callingUid, callingPackage);
12251
Rambo Wang3607f502021-02-01 21:51:40 -080012252 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012253
12254 final long identity = Binder.clearCallingIdentity();
12255 try {
12256 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12257 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12258
12259 if (result instanceof IllegalStateException) {
12260 throw (IllegalStateException) result;
12261 }
12262 } finally {
12263 Binder.restoreCallingIdentity(identity);
12264 }
12265 }
12266
12267 @Override
12268 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12269 String callingPackage) {
12270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12271 mApp, subId, "clearSignalStrengthUpdateRequest");
12272
12273 final int callingUid = Binder.getCallingUid();
12274 // Verify that tha callingPackage belongs to the calling UID
12275 mApp.getSystemService(AppOpsManager.class)
12276 .checkPackage(callingUid, callingPackage);
12277
12278 final long identity = Binder.clearCallingIdentity();
12279 try {
12280 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12281 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12282
12283 if (result instanceof IllegalStateException) {
12284 throw (IllegalStateException) result;
12285 }
12286 } finally {
12287 Binder.restoreCallingIdentity(identity);
12288 }
12289 }
12290
Rambo Wang3607f502021-02-01 21:51:40 -080012291 private static void validateSignalStrengthUpdateRequest(Context context,
12292 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012293 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12294 // phone/system process do not have further restriction on request
12295 return;
12296 }
12297
12298 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012299 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012300 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012301 context.enforceCallingOrSelfPermission(
12302 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12303 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012304 }
12305
12306 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012307 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012308 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012309 || info.isEnabled()) {
12310 throw new IllegalArgumentException(
12311 "Only system can set hide fields in SignalThresholdInfo");
12312 }
12313
12314 // Thresholds length for each RAN need in range. This has been validated in
12315 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12316 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12317 final int[] thresholds = info.getThresholds();
12318 Objects.requireNonNull(thresholds);
12319 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12320 || thresholds.length
12321 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12322 throw new IllegalArgumentException(
12323 "thresholds length is out of range: " + thresholds.length);
12324 }
12325 }
12326 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012327
12328 /**
12329 * Gets the current phone capability.
12330 *
12331 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12332 * @return the PhoneCapability which describes the data connection capability of modem.
12333 * It's used to evaluate possible phone config change, for example from single
12334 * SIM device to multi-SIM device.
12335 */
12336 @Override
12337 public PhoneCapability getPhoneCapability() {
12338 enforceReadPrivilegedPermission("getPhoneCapability");
12339 final long identity = Binder.clearCallingIdentity();
12340 try {
12341 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12342 } finally {
12343 Binder.restoreCallingIdentity(identity);
12344 }
12345 }
Michele Berionne5e411512020-11-13 02:36:59 +000012346
12347 /**
12348 * Prepare TelephonyManager for an unattended reboot. The reboot is
12349 * required to be done shortly after the API is invoked.
12350 */
12351 @Override
12352 @TelephonyManager.PrepareUnattendedRebootResult
12353 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012354 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012355 enforceRebootPermission();
12356
12357 final long identity = Binder.clearCallingIdentity();
12358 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012359 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012360 } finally {
12361 Binder.restoreCallingIdentity(identity);
12362 }
12363 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012364
12365 /**
12366 * Request to get the current slicing configuration including URSP rules and
12367 * NSSAIs (configured, allowed and rejected).
12368 *
12369 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12370 */
12371 @Override
12372 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012373 TelephonyPermissions
12374 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12375 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012376
12377 final long identity = Binder.clearCallingIdentity();
12378 try {
12379 Phone phone = getDefaultPhone();
12380 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12381 } finally {
12382 Binder.restoreCallingIdentity(identity);
12383 }
12384 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012385
12386 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012387 * Check whether the given premium capability is available for purchase from the carrier.
12388 *
12389 * @param capability The premium capability to check.
12390 * @param subId The subId to check the premium capability for.
12391 *
12392 * @return Whether the given premium capability is available to purchase.
12393 */
12394 @Override
12395 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12396 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12397 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12398 log("Premium capability "
12399 + TelephonyManager.convertPremiumCapabilityToString(capability)
12400 + " is not available for purchase due to missing permissions.");
12401 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12402 + "permission READ_BASIC_PHONE_STATE.");
12403 }
12404
12405 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012406 if (phone == null) {
12407 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12408 return false;
12409 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012410 final long identity = Binder.clearCallingIdentity();
12411 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070012412 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012413 .isPremiumCapabilityAvailableForPurchase(capability);
12414 } finally {
12415 Binder.restoreCallingIdentity(identity);
12416 }
12417 }
12418
12419 /**
12420 * Purchase the given premium capability from the carrier.
12421 *
12422 * @param capability The premium capability to purchase.
12423 * @param callback The result of the purchase request.
12424 * @param subId The subId to purchase the premium capability for.
12425 */
12426 @Override
12427 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12428 log("purchasePremiumCapability: capability="
12429 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12430 + getCurrentPackageName());
12431
12432 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12433 mApp, "purchasePremiumCapability")) {
12434 log("purchasePremiumCapability "
12435 + TelephonyManager.convertPremiumCapabilityToString(capability)
12436 + " failed due to missing permissions.");
12437 throw new SecurityException("purchasePremiumCapability requires permission "
12438 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012439 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12440 mApp, "purchasePremiumCapability")) {
12441 log("purchasePremiumCapability "
12442 + TelephonyManager.convertPremiumCapabilityToString(capability)
12443 + " failed due to missing permissions.");
12444 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012445 }
12446
12447 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012448 if (phone == null) {
12449 try {
12450 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12451 callback.accept(result);
12452 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12453 } catch (RemoteException e) {
12454 String logStr = "Purchase premium capability "
12455 + TelephonyManager.convertPremiumCapabilityToString(capability)
12456 + " failed due to RemoteException handling null phone: " + e;
12457 if (DBG) log(logStr);
12458 AnomalyReporter.reportAnomaly(
12459 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12460 }
12461 return;
12462 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012463
12464 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012465 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012466 callingProcess = mApp.getPackageManager().getApplicationInfo(
12467 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012468 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012469 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012470 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012471
12472 boolean isVisible = false;
12473 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12474 if (am != null) {
12475 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12476 if (processes != null) {
12477 for (ActivityManager.RunningAppProcessInfo process : processes) {
12478 log("purchasePremiumCapability: process " + process.processName
12479 + "has importance " + process.importance);
12480 if (process.processName.equals(callingProcess) && process.importance
12481 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12482 isVisible = true;
12483 break;
12484 }
12485 }
12486 }
12487 }
12488
12489 if (!isVisible) {
12490 try {
12491 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12492 callback.accept(result);
12493 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12494 } catch (RemoteException e) {
12495 String logStr = "Purchase premium capability "
12496 + TelephonyManager.convertPremiumCapabilityToString(capability)
12497 + " failed due to RemoteException handling background application: " + e;
12498 if (DBG) log(logStr);
12499 AnomalyReporter.reportAnomaly(
12500 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12501 }
12502 return;
12503 }
12504
Sarah Chin71b3a852022-09-28 15:54:19 -070012505 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012506 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012507 }
12508
12509 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012510 * Register an IMS connection state callback
12511 */
12512 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012513 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12514 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012515 if (feature == ImsFeature.FEATURE_MMTEL) {
12516 // ImsMmTelManager
12517 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12518 TelephonyPermissions
12519 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12520 mApp, subId, "registerImsStateCallback");
12521 } else if (feature == ImsFeature.FEATURE_RCS) {
12522 // ImsRcsManager or SipDelegateManager
12523 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12524 Binder.getCallingUid(), "registerImsStateCallback",
12525 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12526 Manifest.permission.READ_PRECISE_PHONE_STATE,
12527 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12528 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12529 }
12530
12531 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12532 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12533 "IMS not available on device.");
12534 }
12535
12536 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12537 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12538 }
12539
12540 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12541 if (controller == null) {
12542 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12543 "IMS not available on device.");
12544 }
12545
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012546 if (callingPackage == null) {
12547 callingPackage = getCurrentPackageName();
12548 }
12549
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012550 final long token = Binder.clearCallingIdentity();
12551 try {
12552 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012553 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012554 } catch (ImsException e) {
12555 throw new ServiceSpecificException(e.getCode());
12556 } finally {
12557 Binder.restoreCallingIdentity(token);
12558 }
12559 }
12560
12561 /**
12562 * Unregister an IMS connection state callback
12563 */
12564 @Override
12565 public void unregisterImsStateCallback(IImsStateCallback cb) {
12566 final long token = Binder.clearCallingIdentity();
12567 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12568 if (controller == null) {
12569 return;
12570 }
12571 try {
12572 controller.unregisterImsStateCallback(cb);
12573 } finally {
12574 Binder.restoreCallingIdentity(token);
12575 }
12576 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012577
12578 /**
12579 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12580 *
12581 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
12582 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
12583 * SecurityException.
12584 * If there is current registered network this value will be same as the registered cell
12585 * identity. If the device goes out of service the previous cell identity is cached and
12586 * will be returned. If the cache age of the Cell identity is more than 24 hours
12587 * it will be cleared and null will be returned.
12588 *
12589 */
12590 @Override
12591 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12592 String callingFeatureId) {
12593 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12594 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12595 LocationAccessPolicy.checkLocationPermission(mApp,
12596 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12597 .setCallingPackage(callingPackage)
12598 .setCallingFeatureId(callingFeatureId)
12599 .setCallingPid(Binder.getCallingPid())
12600 .setCallingUid(Binder.getCallingUid())
12601 .setMethod("getLastKnownCellIdentity")
12602 .setLogAsInfo(true)
12603 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12604 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12605 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12606 .build());
12607
12608 boolean hasFinePermission =
12609 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12610 if (!hasFinePermission
12611 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12612 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012613 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012614 }
12615
12616 final long identity = Binder.clearCallingIdentity();
12617 try {
12618 Phone phone = getPhone(subId);
12619 if (phone == null) return null;
12620 ServiceStateTracker sst = phone.getServiceStateTracker();
12621 if (sst == null) return null;
12622 return sst.getLastKnownCellIdentity();
12623 } finally {
12624 Binder.restoreCallingIdentity(identity);
12625 }
12626 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012627
jimsun3b9ccac2021-10-26 15:01:23 +080012628 /**
12629 * Sets the modem service class Name that Telephony will bind to.
12630 *
12631 * @param serviceName The class name of the modem service.
12632 * @return true if the operation is succeed, otherwise false.
12633 */
12634 public boolean setModemService(String serviceName) {
12635 Log.d(LOG_TAG, "setModemService - " + serviceName);
12636 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12637 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012638 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12639 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012640 return mPhoneConfigurationManager.setModemService(serviceName);
12641 }
12642
12643 /**
12644 * Return the class name of the currently bounded modem service.
12645 *
12646 * @return the class name of the modem service.
12647 */
12648 public String getModemService() {
12649 String result;
12650 Log.d(LOG_TAG, "getModemService");
12651 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12652 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012653 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012654 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12655 "getModemService");
12656 result = mPhoneConfigurationManager.getModemService();
12657 Log.d(LOG_TAG, "result = " + result);
12658 return result;
12659 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012660
12661 @Override
12662 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12663 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12664 mApp.enforceCallingOrSelfPermission(
12665 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12666 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12667
12668 final long identity = Binder.clearCallingIdentity();
12669 try {
12670 Phone phone = getPhone(subId);
12671 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012672 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12673 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012674 phone.setVoiceServiceStateOverride(hasService);
12675 } finally {
12676 Binder.restoreCallingIdentity(identity);
12677 }
12678 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012679
12680 /**
12681 * set removable eSIM as default eUICC.
12682 *
12683 * @hide
12684 */
12685 @Override
12686 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12687 enforceModifyPermission();
12688 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12689
12690 final long identity = Binder.clearCallingIdentity();
12691 try {
12692 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12693 } finally {
12694 Binder.restoreCallingIdentity(identity);
12695 }
12696 }
12697
12698 /**
12699 * Returns whether the removable eSIM is default eUICC or not.
12700 *
12701 * @hide
12702 */
12703 @Override
12704 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12705 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12706 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12707
12708 final long identity = Binder.clearCallingIdentity();
12709 try {
12710 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12711 } finally {
12712 Binder.restoreCallingIdentity(identity);
12713 }
12714 }
12715
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012716 /**
12717 * Get the component name of the default app to direct respond-via-message intent for the
12718 * user associated with this subscription, update the cache if there is no respond-via-message
12719 * application currently configured for this user.
12720 * @return component name of the app and class to direct Respond Via Message intent to, or
12721 * {@code null} if the functionality is not supported.
12722 * @hide
12723 */
12724 @Override
12725 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12726 boolean updateIfNeeded) {
12727 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012728
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012729 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12730
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012731 UserHandle userHandle = null;
12732 final long identity = Binder.clearCallingIdentity();
12733 try {
12734 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12735 } finally {
12736 Binder.restoreCallingIdentity(identity);
12737 }
12738 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12739 updateIfNeeded, userHandle);
12740 }
Jack Yuf5badd92022-12-08 00:50:53 -080012741
12742 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012743 * Set whether the device is able to connect with null ciphering or integrity
12744 * algorithms. This is a global setting and will apply to all active subscriptions
12745 * and all new subscriptions after this.
12746 *
12747 * @param enabled when true, null cipher and integrity algorithms are allowed.
12748 * @hide
12749 */
12750 @Override
12751 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12752 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12753 enforceModifyPermission();
12754 checkForNullCipherAndIntegritySupport();
12755
12756 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12757 // for listening to these preference changes and applying them immediately.
12758 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12759 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12760 editor.apply();
12761
12762 for (Phone phone: PhoneFactory.getPhones()) {
12763 phone.handleNullCipherEnabledChange();
12764 }
12765 }
12766
12767
12768 /**
12769 * Get whether the device is able to connect with null ciphering or integrity
12770 * algorithms. Note that this retrieves the phone-global preference and not
12771 * the state of the radio.
12772 *
12773 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12774 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12775 * version for this feature.
12776 * @hide
12777 */
12778 @Override
12779 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12780 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12781 enforceReadPermission();
12782 checkForNullCipherAndIntegritySupport();
12783 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12784 }
12785
12786 private void checkForNullCipherAndIntegritySupport() {
12787 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12788 throw new UnsupportedOperationException(
12789 "Null cipher and integrity operations require HAL 2.1 or above");
12790 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012791 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12792 throw new UnsupportedOperationException(
12793 "Null cipher and integrity operations unsupported by modem");
12794 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012795 }
12796
12797 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012798 * Get the SIM state for the slot index.
12799 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12800 *
12801 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12802 */
12803 @Override
12804 @SimState
12805 public int getSimStateForSlotIndex(int slotIndex) {
12806 IccCardConstants.State simState;
12807 if (slotIndex < 0) {
12808 simState = IccCardConstants.State.UNKNOWN;
12809 } else {
12810 Phone phone = null;
12811 try {
12812 phone = PhoneFactory.getPhone(slotIndex);
12813 } catch (IllegalStateException e) {
12814 // ignore
12815 }
12816 if (phone == null) {
12817 simState = IccCardConstants.State.UNKNOWN;
12818 } else {
12819 IccCard icc = phone.getIccCard();
12820 if (icc == null) {
12821 simState = IccCardConstants.State.UNKNOWN;
12822 } else {
12823 simState = icc.getState();
12824 }
12825 }
12826 }
12827 return simState.ordinal();
12828 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012829
12830 /**
12831 * Get current cell broadcast ranges.
12832 */
12833 @Override
12834 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12835 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12836 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12837 "getCellBroadcastIdRanges");
12838 final long identity = Binder.clearCallingIdentity();
12839 try {
12840 return getPhone(subId).getCellBroadcastIdRanges();
12841 } finally {
12842 Binder.restoreCallingIdentity(identity);
12843 }
12844 }
12845
12846 /**
12847 * Set reception of cell broadcast messages with the list of the given ranges
12848 *
12849 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12850 */
12851 @Override
12852 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12853 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12854 @Nullable IIntegerConsumer callback) {
12855 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12856 "setCellBroadcastIdRanges");
12857 final long identity = Binder.clearCallingIdentity();
12858 try {
12859 Phone phone = getPhoneFromSubId(subId);
12860 if (DBG) {
12861 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12862 }
12863 phone.setCellBroadcastIdRanges(ranges, result -> {
12864 if (callback != null) {
12865 try {
12866 callback.accept(result);
12867 } catch (RemoteException e) {
12868 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12869 }
12870 }
12871 });
12872 } finally {
12873 Binder.restoreCallingIdentity(identity);
12874 }
12875 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012876
12877 /**
12878 * Returns whether the device supports the domain selection service.
12879 *
12880 * @return {@code true} if the device supports the domain selection service.
12881 */
12882 @Override
12883 public boolean isDomainSelectionSupported() {
12884 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12885 "isDomainSelectionSupported");
12886
12887 final long identity = Binder.clearCallingIdentity();
12888 try {
12889 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12890 } finally {
12891 Binder.restoreCallingIdentity(identity);
12892 }
12893 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012894
12895 /**
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012896 * Request to enable or disable the satellite modem. If the satellite modem is enabled, this
12897 * will also disable the cellular modem, and if the satellite modem is disabled, this will also
12898 * re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012899 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012900 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012901 * @param enable {@code true} to enable the satellite modem and {@code false} to disable.
12902 * @param callback The callback to get the error code of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012903 *
12904 * @throws SecurityException if the caller doesn't have the required permission.
12905 */
12906 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012907 public void requestSatelliteEnabled(
12908 int subId, boolean enable, @NonNull IIntegerConsumer callback) {
12909 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012910 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012911 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012912 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12913 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012914 }
Sarah Chin503828c2023-02-01 23:54:20 -080012915
12916 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012917 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012918 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
12919 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012920 }
12921
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012922 Phone phone = getPhoneOrDefault(validSubId, "requestSatelliteEnabled");
Sarah Chin503828c2023-02-01 23:54:20 -080012923 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012924 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
12925 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012926 }
12927
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012928 Pair<Boolean, Consumer<Integer>> arg = new Pair<>(enable, result);
12929 sendRequestAsync(CMD_SET_SATELLITE_ENABLED, arg, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080012930 }
12931
12932 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012933 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012934 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012935 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012936 * @param result The result receiver that returns whether the satellite modem is enabled
12937 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012938 *
12939 * @throws SecurityException if the caller doesn't have the required permission.
12940 */
12941 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012942 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12943 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012944 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012945 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
12946 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012947 }
Sarah Chin503828c2023-02-01 23:54:20 -080012948
12949 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012950 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012951 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
12952 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012953 }
12954
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012955 Phone phone = getPhoneOrDefault(validSubId, "requestIsSatelliteEnabled");
Sarah Chin503828c2023-02-01 23:54:20 -080012956 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012957 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12958 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012959 }
12960
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012961 sendRequest(CMD_IS_SATELLITE_ENABLED, result, subId);
Sarah Chin503828c2023-02-01 23:54:20 -080012962 }
12963
12964 /**
Sarah Chin43457982023-02-15 17:50:38 -080012965 * Request to enable or disable the satellite service demo mode.
12966 *
12967 * @param subId The subId of the subscription to set the satellite demo mode enabled for.
12968 * @param enable {@code true} to enable the satellite demo mode and {@code false} to disable.
12969 * @param callback The callback to get the error code of the request.
12970 *
12971 * @throws SecurityException if the caller doesn't have the required permission.
12972 */
12973 @Override
12974 public void requestSatelliteDemoModeEnabled(
12975 int subId, boolean enable, @NonNull IIntegerConsumer callback) {
12976 enforceSatelliteCommunicationPermission("requestSatelliteDemoModeEnabled");
12977 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
12978 if (!isSatelliteSupported()) {
12979 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12980 return;
12981 }
12982
12983 final int validSubId = getValidSatelliteSubId(subId);
12984 if (!isSatelliteProvisioned(validSubId)) {
12985 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
12986 return;
12987 }
12988
12989 Phone phone = getPhoneOrDefault(validSubId, "requestSatelliteDemoModeEnabled");
12990 if (phone == null) {
12991 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
12992 return;
12993 }
12994
12995 if (mIsSatelliteServiceSupported) {
12996 result.accept(mSatelliteServiceController.requestSatelliteDemoModeEnabled(enable));
12997 } else {
12998 result.accept(SatelliteManager.SATELLITE_SERVICE_ERROR);
12999 }
13000 }
13001
13002 /**
13003 * Request to get whether the satellite service demo mode is enabled.
13004 *
13005 * @param subId The subId of the subscription to check whether the satellite demo mode
13006 * is enabled for.
13007 * @param result The result receiver that returns whether the satellite demo mode is enabled
13008 * if the request is successful or an error code if the request failed.
13009 *
13010 * @throws SecurityException if the caller doesn't have the required permission.
13011 */
13012 @Override
13013 public void requestIsSatelliteDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13014 enforceSatelliteCommunicationPermission("requestIsSatelliteDemoModeEnabled");
13015 if (!isSatelliteSupported()) {
13016 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
13017 return;
13018 }
13019
13020 final int validSubId = getValidSatelliteSubId(subId);
13021 if (!isSatelliteProvisioned(validSubId)) {
13022 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
13023 return;
13024 }
13025
13026 Phone phone = getPhoneOrDefault(validSubId, "requestIsSatelliteDemoModeEnabled");
13027 if (phone == null) {
13028 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
13029 return;
13030 }
13031
13032 if (mIsSatelliteServiceSupported) {
13033 final Bundle bundle = new Bundle();
13034 int error = mSatelliteServiceController.requestIsSatelliteDemoModeEnabled(
13035 new Consumer<Boolean>() {
13036 @Override
13037 public void accept(Boolean enabled) {
13038 bundle.putBoolean(SatelliteManager.KEY_DEMO_MODE_ENABLED, enabled);
13039 }
13040 });
13041 result.send(error, bundle);
13042 } else {
13043 result.send(SatelliteManager.SATELLITE_SERVICE_ERROR, null);
13044 }
13045 }
13046
13047 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013048 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013049 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013050 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013051 * @param result The result receiver that returns whether the satellite service is supported on
13052 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013053 */
13054 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013055 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013056 synchronized (mIsSatelliteSupportedLock) {
13057 if (mIsSatelliteSupported != null) {
13058 /* We have already successfully queried the satellite modem. */
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013059 Bundle bundle = new Bundle();
13060 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, mIsSatelliteSupported);
13061 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, bundle);
13062 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013063 }
13064 }
Sarah Chin503828c2023-02-01 23:54:20 -080013065
13066 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013067 Phone phone = getPhoneOrDefault(validSubId, "requestIsSatelliteSupported");
Sarah Chin503828c2023-02-01 23:54:20 -080013068 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013069 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
13070 return;
Sarah Chin503828c2023-02-01 23:54:20 -080013071 }
13072
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013073 sendRequestAsync(CMD_IS_SATELLITE_SUPPORTED, result, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080013074 }
13075
13076 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013077 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013078 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013079 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013080 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13081 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013082 *
13083 * @throws SecurityException if the caller doesn't have required permission.
13084 */
13085 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013086 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13087 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013088 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013089 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
13090 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013091 }
Sarah Chin503828c2023-02-01 23:54:20 -080013092
13093 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013094 Phone phone = getPhoneOrDefault(validSubId, "requestSatelliteCapabilities");
Sarah Chin503828c2023-02-01 23:54:20 -080013095 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013096 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
13097 return;
Sarah Chin503828c2023-02-01 23:54:20 -080013098 }
13099
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013100 sendRequestAsync(CMD_GET_SATELLITE_CAPABILITIES, result, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080013101 }
13102
13103 /**
Sarah Chineccfbd12023-01-20 19:00:35 -080013104 * Start receiving satellite position updates.
13105 * This can be called by the pointing UI when the user starts pointing to the satellite.
13106 * Modem should continue to report the pointing input as the device or satellite moves.
13107 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013108 * @param subId The subId of the subscription to start satellite position updates for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013109 * @param errorCallback The callback to get the error code of the request.
Sarah Chineccfbd12023-01-20 19:00:35 -080013110 * @param callback The callback to notify of changes in satellite position.
Sarah Chin503828c2023-02-01 23:54:20 -080013111 *
13112 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013113 */
13114 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013115 public void startSatellitePositionUpdates(int subId, @NonNull IIntegerConsumer errorCallback,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013116 @NonNull ISatellitePositionUpdateCallback callback) {
Sarah Chinf75afa72023-02-01 01:32:19 -080013117 enforceSatelliteCommunicationPermission("startSatellitePositionUpdates");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013118 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013119 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013120 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
13121 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013122 }
Sarah Chinf75afa72023-02-01 01:32:19 -080013123
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013124 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013125 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013126 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
13127 return;
Sarah Chinf75afa72023-02-01 01:32:19 -080013128 }
13129
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013130 Phone phone = getPhoneOrDefault(validSubId, "startSatellitePositionUpdates");
Sarah Chineccfbd12023-01-20 19:00:35 -080013131 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013132 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
13133 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080013134 }
13135
Sarah Chin43457982023-02-15 17:50:38 -080013136 SatellitePositionUpdateHandler handler = mSatellitePositionUpdateHandlers.get(validSubId);
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013137 if (handler != null) {
13138 handler.addListener(callback);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013139 return;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013140 } else {
13141 handler = new SatellitePositionUpdateHandler(Looper.getMainLooper());
13142 handler.addListener(callback);
13143 mSatellitePositionUpdateHandlers.put(validSubId, handler);
Sarah Chin43457982023-02-15 17:50:38 -080013144 if (mIsSatelliteServiceSupported) {
13145 mSatelliteServiceController.registerForSatellitePositionInfoChanged(handler,
13146 SatellitePositionUpdateHandler.EVENT_POSITION_INFO_CHANGED, null);
13147 mSatelliteServiceController.registerForDatagramTransferStateChanged(handler,
13148 SatellitePositionUpdateHandler.EVENT_DATAGRAM_TRANSFER_STATE_CHANGED, null);
13149 } else {
13150 phone.registerForSatellitePositionInfoChanged(handler,
13151 SatellitePositionUpdateHandler.EVENT_POSITION_INFO_CHANGED, null);
13152 // TODO: registerForDatagramTransferStateChanged through SatelliteController
13153 }
Sarah Chineccfbd12023-01-20 19:00:35 -080013154 }
13155
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013156 sendRequestAsync(CMD_START_SATELLITE_POSITION_UPDATES,
13157 new SatellitePositionUpdateArgument(result, callback, validSubId), phone, null);
Sarah Chineccfbd12023-01-20 19:00:35 -080013158 }
13159
13160 /**
13161 * Stop receiving satellite position updates.
13162 * This can be called by the pointing UI when the user stops pointing to the satellite.
13163 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013164 * @param subId The subId of the subscription to stop satellite position updates for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013165 * @param errorCallback The callback to get the error code of the request.
13166 * @param callback The callback that was passed to {@link
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013167 * #startSatellitePositionUpdates(int, IIntegerConsumer, ISatellitePositionUpdateCallback)}
Sarah Chin503828c2023-02-01 23:54:20 -080013168 *
13169 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013170 */
13171 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013172 public void stopSatellitePositionUpdates(int subId, @NonNull IIntegerConsumer errorCallback,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013173 @NonNull ISatellitePositionUpdateCallback callback) {
Sarah Chinf75afa72023-02-01 01:32:19 -080013174 enforceSatelliteCommunicationPermission("stopSatellitePositionUpdates");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013175 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013176 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013177 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
13178 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013179 }
Sarah Chinf75afa72023-02-01 01:32:19 -080013180
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013181 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013182 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013183 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
13184 return;
Sarah Chinf75afa72023-02-01 01:32:19 -080013185 }
13186
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013187 Phone phone = getPhoneOrDefault(validSubId, "stopSatellitePositionUpdates");
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013188 SatellitePositionUpdateHandler handler = mSatellitePositionUpdateHandlers.get(validSubId);
13189 if (handler != null) {
13190 handler.removeListener(callback);
13191
13192 if (handler.hasListeners()) {
13193 /**
13194 * TODO (b/269194948): If the calling apps crash, the handler will always have some
13195 * listener. That is, we will not request modem to stop position update and
13196 * cleaning our resources. We need to monitor the calling apps and clean up the
13197 * resources when the apps die. We need to this for other satellite callbacks
13198 * as well.
13199 */
13200 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
13201 return;
13202 }
13203
13204 mSatellitePositionUpdateHandlers.remove(validSubId);
Sarah Chin43457982023-02-15 17:50:38 -080013205 if (mIsSatelliteServiceSupported) {
13206 mSatelliteServiceController.unregisterForSatellitePositionInfoChanged(handler);
13207 mSatelliteServiceController.unregisterForDatagramTransferStateChanged(handler);
13208 } else {
13209 if (phone == null) {
13210 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
13211 return;
13212 }
13213 phone.unregisterForSatellitePositionInfoChanged(handler);
13214 // TODO: unregisterForDatagramTransferStateChanged through SatelliteController
13215 }
Sarah Chineccfbd12023-01-20 19:00:35 -080013216 }
13217
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013218 /**
13219 * Even if handler is null - which means there are not any listeners, the command to stop
13220 * satellite position updates sent to the modem might have failed. The callers might want to
13221 * retry sending the command. Thus, we always need to send this command to the modem.
13222 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013223 sendRequestAsync(CMD_STOP_SATELLITE_POSITION_UPDATES, result, phone, null);
Sarah Chineccfbd12023-01-20 19:00:35 -080013224 }
13225
13226 /**
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013227 * Request to get the maximum number of bytes per datagram that can be sent to satellite.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013228 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013229 * @param subId The subId of the subscription to get the maximum number of characters for.
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013230 * @param result The result receiver that returns the maximum number of bytes per datagram
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013231 * message on satellite if the request is successful or an error code
13232 * if the request failed.
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013233 *
13234 * @throws SecurityException if the caller doesn't have the required permission.
13235 */
13236 @Override
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013237 public void requestMaxSizePerSendingDatagram(int subId,
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013238 @NonNull ResultReceiver result) {
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013239 enforceSatelliteCommunicationPermission("requestMaxSizePerSendingDatagram");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013240 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013241 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
13242 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013243 }
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013244
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013245 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013246 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013247 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
13248 return;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013249 }
13250
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013251 Phone phone = getPhoneOrDefault(validSubId, "requestMaxSizePerSendingDatagram");
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013252 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013253 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
13254 return;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013255 }
13256
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013257 sendRequestAsync(CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG, result, phone, null);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013258 }
13259
13260 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013261 * Register the subscription with a satellite provider.
13262 * This is needed to register the subscription if the provider allows dynamic registration.
13263 *
13264 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013265 * @param token The token to be used as a unique identifier for provisioning with satellite
13266 * gateway.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013267 * @param callback The callback to get the error code of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013268 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013269 * @return The signal transport used by the caller to cancel the provision request,
13270 * or {@code null} if the request failed.
13271 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013272 * @throws SecurityException if the caller doesn't have the required permission.
13273 */
13274 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013275 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
13276 @NonNull String token, @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013277 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013278 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013279 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013280 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013281 return null;
13282 }
13283
13284 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013285 Phone phone = getPhoneOrDefault(validSubId, "provisionSatelliteService");
13286 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013287 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013288 return null;
13289 }
13290
13291 if (mSatelliteProvisionCallbacks.containsKey(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013292 result.accept(SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013293 return null;
13294 }
13295
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013296 if (isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013297 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013298 return null;
13299 }
13300
13301 sendRequestAsync(CMD_PROVISION_SATELLITE_SERVICE,
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013302 new ProvisionSatelliteServiceArgument(token, result, validSubId), phone, null);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013303
13304 ICancellationSignal cancelTransport = CancellationSignal.createTransport();
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013305 CancellationSignal.fromTransport(cancelTransport).setOnCancelListener(() -> {
13306 sendRequestAsync(CMD_DEPROVISION_SATELLITE_SERVICE,
13307 new ProvisionSatelliteServiceArgument(token, null, validSubId),
13308 phone, null);
13309 });
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013310 return cancelTransport;
13311 }
13312
13313 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013314 * Unregister the device/subscription with the satellite provider.
13315 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013316 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013317 * should report as deprovisioned.
13318 *
13319 * @param subId The subId of the subscription to be deprovisioned.
13320 * @param token The token of the device/subscription to be deprovisioned.
13321 * @param callback The callback to get the error code of the request.
13322 *
13323 * @throws SecurityException if the caller doesn't have the required permission.
13324 */
13325 @Override
13326 public void deprovisionSatelliteService(int subId,
13327 @NonNull String token, @NonNull IIntegerConsumer callback) {
13328 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
13329 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
13330 if (!isSatelliteSupported()) {
13331 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
13332 return;
13333 }
13334
13335 final int validSubId = getValidSatelliteSubId(subId);
13336 if (!isSatelliteProvisioned(validSubId)) {
13337 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
13338 return;
13339 }
13340
13341 Phone phone = getPhoneOrDefault(validSubId, "deprovisionSatelliteService");
13342 if (phone == null) {
13343 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
13344 return;
13345 }
13346
13347 sendRequestAsync(CMD_DEPROVISION_SATELLITE_SERVICE,
13348 new ProvisionSatelliteServiceArgument(token, result, validSubId), phone, null);
13349 }
13350
13351 /**
Sarah Chin43457982023-02-15 17:50:38 -080013352 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013353 *
Sarah Chin43457982023-02-15 17:50:38 -080013354 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013355 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013356 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013357 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
13358 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013359 * @throws SecurityException if the caller doesn't have the required permission.
13360 */
13361 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080013362 @SatelliteManager.SatelliteError public int registerForSatelliteProvisionStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013363 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013364 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Sarah Chindf715ec2023-02-13 13:46:24 -080013365 return registerForSatelliteProvisionStateChangedInternal(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013366 }
13367
13368 /**
Sarah Chin43457982023-02-15 17:50:38 -080013369 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013370 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013371 *
Sarah Chin43457982023-02-15 17:50:38 -080013372 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013373 * @param callback The callback that was passed to
13374 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013375 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013376 * @throws SecurityException if the caller doesn't have the required permission.
13377 */
13378 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013379 public void unregisterForSatelliteProvisionStateChanged(
13380 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013381 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
13382
13383 final int validSubId = getValidSatelliteSubId(subId);
13384 SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler =
13385 mSatelliteProvisionStateChangedHandlers.get(validSubId);
13386 if (satelliteProvisionStateChangedHandler != null) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013387 satelliteProvisionStateChangedHandler.removeListener(callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013388 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013389 }
13390
13391 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013392 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013393 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013394 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013395 * @param result The result receiver that returns whether the device is provisioned with a
13396 * satellite provider if the request is successful or an error code if the
13397 * request failed.
13398 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013399 * @throws SecurityException if the caller doesn't have the required permission.
13400 */
13401 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013402 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13403 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013404 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013405 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
13406 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013407 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013408
13409 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013410 Bundle bundle = new Bundle();
13411 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_PROVISIONED,
13412 isSatelliteProvisioned(validSubId));
13413 result.send(SatelliteManager.SATELLITE_ERROR_NONE, bundle);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013414 }
13415
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013416 /**
Sarah Chin43457982023-02-15 17:50:38 -080013417 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013418 *
Sarah Chin43457982023-02-15 17:50:38 -080013419 * @param subId The subId of the subscription to register for satellite modem state changed.
13420 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013421 *
13422 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
13423 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013424 * @throws SecurityException if the caller doesn't have the required permission.
13425 */
13426 @Override
Sarah Chin43457982023-02-15 17:50:38 -080013427 @SatelliteManager.SatelliteError public int registerForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013428 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013429 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013430
13431 final int validSubId = getValidSatelliteSubId(subId);
13432 Phone phone = getPhoneOrDefault(
Sarah Chin43457982023-02-15 17:50:38 -080013433 validSubId, "registerForSatelliteModemStateChanged");
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013434 if (phone == null) {
13435 return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
13436 }
13437
13438 SatelliteStateListenerHandler satelliteStateListenerHandler =
13439 mSatelliteStateListenerHandlers.get(validSubId);
13440 if (satelliteStateListenerHandler == null) {
13441 satelliteStateListenerHandler = new SatelliteStateListenerHandler(
13442 Looper.getMainLooper(), validSubId);
Sarah Chin43457982023-02-15 17:50:38 -080013443 if (mIsSatelliteServiceSupported) {
13444 mSatelliteServiceController.registerForSatelliteModemStateChanged(
13445 satelliteStateListenerHandler,
13446 SatelliteStateListenerHandler.EVENT_SATELLITE_MODEM_STATE_CHANGE, null);
13447 mSatelliteServiceController.registerForPendingDatagramCount(
13448 satelliteStateListenerHandler,
13449 SatelliteStateListenerHandler.EVENT_PENDING_DATAGRAM_COUNT, null);
13450 } else {
13451 phone.registerForSatelliteModemStateChanged(satelliteStateListenerHandler,
13452 SatelliteStateListenerHandler.EVENT_SATELLITE_MODEM_STATE_CHANGE, null);
13453 phone.registerForPendingDatagramCount(satelliteStateListenerHandler,
13454 SatelliteStateListenerHandler.EVENT_PENDING_DATAGRAM_COUNT, null);
13455 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013456 }
13457
13458 satelliteStateListenerHandler.addListener(callback);
13459 mSatelliteStateListenerHandlers.put(validSubId, satelliteStateListenerHandler);
13460 return SatelliteManager.SATELLITE_ERROR_NONE;
13461 }
13462
13463 /**
Sarah Chin43457982023-02-15 17:50:38 -080013464 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013465 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013466 *
Sarah Chin43457982023-02-15 17:50:38 -080013467 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013468 * @param callback The callback that was passed to
Sarah Chin43457982023-02-15 17:50:38 -080013469 * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013470 *
13471 * @throws SecurityException if the caller doesn't have the required permission.
13472 */
13473 @Override
Sarah Chin43457982023-02-15 17:50:38 -080013474 public void unregisterForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013475 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013476 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged");
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013477
13478 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin43457982023-02-15 17:50:38 -080013479 SatelliteStateListenerHandler handler = mSatelliteStateListenerHandlers.get(validSubId);
13480 if (handler != null) {
13481 handler.removeListener(callback);
13482 if (!handler.hasListeners()) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013483 mSatelliteStateListenerHandlers.remove(validSubId);
Sarah Chin43457982023-02-15 17:50:38 -080013484 if (mIsSatelliteServiceSupported) {
13485 mSatelliteServiceController.unregisterForSatelliteModemStateChanged(handler);
13486 mSatelliteServiceController.unregisterForPendingDatagramCount(handler);
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013487 } else {
Sarah Chin43457982023-02-15 17:50:38 -080013488 Phone phone = getPhoneOrDefault(
13489 validSubId, "unregisterForSatelliteModemStateChanged");
13490 if (phone == null) {
13491 loge("unregisterForSatelliteModemStateChanged: phone is null");
13492 } else {
13493 phone.unregisterForSatelliteModemStateChanged(handler);
13494 phone.unregisterForPendingDatagramCount(handler);
13495 }
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013496 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013497 }
13498 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013499 }
13500
13501 /**
13502 * Register to receive incoming datagrams over satellite.
13503 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013504 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013505 * @param datagramType datagram type indicating whether the datagram is of type
13506 * SOS_SMS or LOCATION_SHARING.
Sarah Chindf715ec2023-02-13 13:46:24 -080013507 * @param callback The callback to handle incoming datagrams over satellite.
13508 *
13509 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
13510 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013511 * @throws SecurityException if the caller doesn't have the required permission.
13512 */
13513 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080013514 @SatelliteManager.SatelliteError public int registerForSatelliteDatagram(int subId,
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013515 @SatelliteManager.DatagramType int datagramType,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013516 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013517 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013518 if (!isSatelliteSupported()) {
13519 return SatelliteManager.SATELLITE_NOT_SUPPORTED;
13520 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013521
13522 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chindf715ec2023-02-13 13:46:24 -080013523 Phone phone = getPhoneOrDefault(validSubId, "registerForSatelliteDatagram");
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013524 if (phone == null) {
13525 return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
13526 }
13527
13528 SatelliteDatagramListenerHandler satelliteDatagramListenerHandler =
13529 mSatelliteDatagramListenerHandlers.get(validSubId);
13530 if (satelliteDatagramListenerHandler == null) {
13531 satelliteDatagramListenerHandler = new SatelliteDatagramListenerHandler(
13532 Looper.getMainLooper(), validSubId);
Sarah Chin43457982023-02-15 17:50:38 -080013533 if (mIsSatelliteServiceSupported) {
13534 mSatelliteServiceController.registerForSatelliteDatagramsReceived(
13535 satelliteDatagramListenerHandler,
13536 SatelliteDatagramListenerHandler.EVENT_SATELLITE_DATAGRAMS_RECEIVED, null);
13537 } else {
13538 phone.registerForSatelliteDatagramsReceived(satelliteDatagramListenerHandler,
13539 SatelliteDatagramListenerHandler.EVENT_SATELLITE_DATAGRAMS_RECEIVED, null);
13540 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013541 }
13542
13543 satelliteDatagramListenerHandler.addListener(callback);
13544 mSatelliteDatagramListenerHandlers.put(validSubId, satelliteDatagramListenerHandler);
13545 return SatelliteManager.SATELLITE_ERROR_NONE;
13546 }
13547
13548 /**
13549 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013550 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013551 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013552 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13553 * @param callback The callback that was passed to
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013554 * {@link #registerForSatelliteDatagram(int, int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013555 *
13556 * @throws SecurityException if the caller doesn't have the required permission.
13557 */
13558 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013559 public void unregisterForSatelliteDatagram(int subId,
13560 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013561 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
13562
13563 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin43457982023-02-15 17:50:38 -080013564 SatelliteDatagramListenerHandler handler =
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013565 mSatelliteDatagramListenerHandlers.get(validSubId);
Sarah Chin43457982023-02-15 17:50:38 -080013566 if (handler != null) {
13567 handler.removeListener(callback);
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013568
Sarah Chin43457982023-02-15 17:50:38 -080013569 if (!handler.hasListeners()) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013570 mSatelliteDatagramListenerHandlers.remove(validSubId);
Sarah Chin43457982023-02-15 17:50:38 -080013571 if (mIsSatelliteServiceSupported) {
13572 mSatelliteServiceController.unregisterForSatelliteDatagramsReceived(handler);
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013573 } else {
Sarah Chin43457982023-02-15 17:50:38 -080013574 Phone phone = getPhoneOrDefault(validSubId, "unregisterForSatelliteDatagram");
13575 if (phone == null) {
13576 loge("unregisterForSatelliteDatagram: phone is null");
13577 } else {
13578 phone.unregisterForSatelliteDatagramsReceived(handler);
13579 }
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013580 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013581 }
13582 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013583 }
13584
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013585 /**
13586 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013587 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013588 * This method requests modem to check if there are any pending datagrams to be received over
13589 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013590 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int,
13591 * ISatelliteDatagramReceiverAck)}
Sarah Chindf715ec2023-02-13 13:46:24 -080013592 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013593 * @param subId The subId of the subscription used for receiving datagrams.
13594 * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013595 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013596 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013597 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013598 @Override
13599 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013600 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013601 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013602
13603 final int validSubId = getValidSatelliteSubId(subId);
13604 if (!isSatelliteProvisioned(validSubId)) {
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013605 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
13606 return;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013607 }
13608
13609 Phone phone = getPhoneOrDefault(validSubId, "pollPendingSatelliteDatagrams");
13610 if (phone == null) {
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013611 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
13612 return;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013613 }
13614
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013615 sendRequestAsync(CMD_POLL_PENDING_SATELLITE_DATAGRAMS, result, phone, null);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013616 }
13617
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013618 /**
13619 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013620 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013621 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13622 * input to this method. Datagram received here will be passed down to modem without any
13623 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013624 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013625 * @param subId The subId of the subscription to send satellite datagrams for.
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013626 * @param datagramId An id that uniquely identifies datagram requested to be sent.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013627 * @param datagramType datagram type indicating whether the datagram is of type
13628 * SOS_SMS or LOCATION_SHARING.
13629 * @param datagram encoded gateway datagram which is encrypted by the caller.
13630 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013631 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13632 * full screen mode.
13633 * @param result The result receiver that returns datagramId if datagram is sent successfully
13634 * or {@link SatelliteManager.SatelliteError} of the request if it is failed.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013635 *
13636 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013637 */
13638 @Override
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013639 public void sendSatelliteDatagram(int subId, long datagramId,
13640 @SatelliteManager.DatagramType int datagramType, SatelliteDatagram datagram,
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013641 boolean needFullScreenPointingUI, @NonNull ResultReceiver result) {
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013642 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013643
13644 final int validSubId = getValidSatelliteSubId(subId);
13645 if (!isSatelliteProvisioned(validSubId)) {
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013646 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013647 return;
13648 }
13649
13650 Phone phone = getPhoneOrDefault(validSubId, "sendSatelliteDatagram");
13651 if (phone == null) {
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013652 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013653 return;
13654 }
13655
13656 // check if we need to start PointingUI.
13657
13658 sendRequestAsync(CMD_SEND_SATELLITE_DATAGRAM,
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013659 new SendSatelliteDatagramArgument(datagramId, datagramType, datagram,
13660 needFullScreenPointingUI, result), phone, null);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013661 }
13662
Sarah Chindf715ec2023-02-13 13:46:24 -080013663 /**
13664 * Request to get whether satellite communication is allowed for the current location.
13665 *
13666 * @param subId The subId of the subscription to check whether satellite communication is
13667 * allowed for the current location for.
13668 * @param result The result receiver that returns whether satellite communication is allowed
13669 * for the current location if the request is successful or an error code
13670 * if the request failed.
13671 *
13672 * @throws SecurityException if the caller doesn't have the required permission.
13673 */
13674 @Override
13675 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
13676 @NonNull ResultReceiver result) {
13677 enforceSatelliteCommunicationPermission(
13678 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
13679 if (!isSatelliteSupported()) {
13680 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
13681 return;
13682 }
13683
13684 final int validSubId = getValidSatelliteSubId(subId);
13685 if (!isSatelliteProvisioned(validSubId)) {
13686 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
13687 return;
13688 }
13689
13690 Phone phone = getPhoneOrDefault(validSubId,
13691 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
13692 if (phone == null) {
13693 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
13694 return;
13695 }
13696
13697 sendRequest(CMD_IS_SATELLITE_COMMUNICATION_ALLOWED, result, subId);
13698 }
13699
13700 /**
Sarah Chin5f57c582023-02-14 04:16:10 -080013701 * Request to get the time after which the satellite will be visible
Sarah Chindf715ec2023-02-13 13:46:24 -080013702 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013703 * @param subId The subId to get the time after which the satellite will be visible for.
13704 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013705 * be visible if the request is successful or an error code if the request failed.
13706 *
13707 * @throws SecurityException if the caller doesn't have the required permission.
13708 */
13709 @Override
13710 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13711 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
13712 if (!isSatelliteSupported()) {
13713 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
13714 return;
13715 }
13716
13717 final int validSubId = getValidSatelliteSubId(subId);
13718 if (!isSatelliteProvisioned(validSubId)) {
13719 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
13720 return;
13721 }
13722
13723 Phone phone = getPhoneOrDefault(validSubId, "requestTimeForNextSatelliteVisibility");
13724 if (phone == null) {
13725 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
13726 return;
13727 }
13728
13729 sendRequestAsync(CMD_GET_TIME_SATELLITE_NEXT_VISIBLE, result, phone, null);
13730 }
13731
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013732 private void handleEventProvisionSatelliteServiceDone(
13733 @NonNull ProvisionSatelliteServiceArgument arg,
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013734 @SatelliteManager.SatelliteError int result) {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013735 log("handleEventProvisionSatelliteServiceDone: result="
13736 + result + ", subId=" + arg.subId);
13737
13738 Consumer<Integer> callback = mSatelliteProvisionCallbacks.remove(arg.subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013739 if (callback == null) {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013740 loge("handleEventProvisionSatelliteServiceDone: callback is null for subId="
13741 + arg.subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013742 return;
13743 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013744 callback.accept(result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013745
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013746 if (result == SatelliteManager.SATELLITE_ERROR_NONE) {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013747 setSatelliteProvisioned(arg.subId, true);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013748 }
13749
13750 /**
13751 * We need to update satellite provision status in SubscriptionController
13752 * or SatelliteController.
13753 * TODO (b/267826133) we need to do this for all subscriptions on the device.
13754 */
Sarah Chindf715ec2023-02-13 13:46:24 -080013755 registerForSatelliteProvisionStateChangedInternal(arg.subId, null);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013756 }
13757
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013758 private void handleEventDeprovisionSatelliteServiceDone(
13759 @NonNull ProvisionSatelliteServiceArgument arg,
13760 @SatelliteManager.SatelliteError int result) {
13761 if (arg == null) {
13762 loge("handleEventDeprovisionSatelliteServiceDone: arg is null");
13763 return;
13764 }
13765 log("handleEventDeprovisionSatelliteServiceDone: result="
13766 + result + ", subId=" + arg.subId);
13767
13768 if (arg.callback != null) {
13769 arg.callback.accept(result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013770 }
13771
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013772 if (result == SatelliteManager.SATELLITE_ERROR_NONE) {
13773 setSatelliteProvisioned(arg.subId, false);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013774 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013775 }
13776
13777 private Phone getPhoneOrDefault(int subId, String caller) {
13778 Phone phone = getPhone(subId);
13779 if (phone == null) {
13780 loge(caller + " called with invalid subId: " + subId
13781 + ". Retrying with default phone.");
13782 phone = getDefaultPhone();
13783 if (phone == null) {
13784 loge(caller + " failed with no phone object.");
13785 }
13786 }
13787 return phone;
13788 }
13789
13790 /**
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013791 * Check if satellite is provisioned for a subscription or the device.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013792 *
13793 * Note: this is the version without permission check for telephony internal use only. The
13794 * caller need to take care of the permission check.
13795 */
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013796 private boolean isSatelliteProvisioned(int subId) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013797 if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
13798 if (mSubscriptionController == null) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013799 loge("isSatelliteProvisioned mSubscriptionController is null");
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013800 return false;
13801 }
13802
13803 String strResult = mSubscriptionController.getSubscriptionProperty(
13804 subId, SubscriptionManager.SATELLITE_ENABLED);
13805 if (strResult != null) {
13806 int intResult = Integer.parseInt(strResult);
13807 return (intResult == 1) ? true : false;
13808 }
13809 } else {
13810 //TODO (b/267826133): check via SatelliteController
13811 }
13812 return false;
13813 }
13814
13815 /**
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013816 * Set satellite provisioned for a subscription or the device.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013817 *
13818 * The permission {@link android.Manifest.permission#MODIFY_PHONE_STATE} will be enforced by
13819 * {@link SubscriptionController} when setting satellite enabled for an active subscription.
13820 * Otherwise, {@link android.Manifest.permission#SATELLITE_COMMUNICATION} will be enforced.
13821 */
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013822 private synchronized void setSatelliteProvisioned(int subId, boolean isEnabled) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013823 if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
13824 if (mSubscriptionController == null) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013825 loge("setSatelliteProvisioned mSubscriptionController is null");
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013826 return;
13827 }
13828 mSubscriptionController.setSubscriptionProperty(
13829 subId, SubscriptionManager.SATELLITE_ENABLED, isEnabled ? "1" : "0");
13830 } else {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013831 //TODO (b/267826133): set via SatelliteController
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013832 }
13833 }
13834
13835 private int getValidSatelliteSubId(int subId) {
13836 if (mSubscriptionController == null) {
13837 loge("getValidSatelliteSubId mSubscriptionController is null. "
13838 + "Use DEFAULT_SUBSCRIPTION_ID for subId=" + subId);
13839 return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
13840 }
13841 final long identity = Binder.clearCallingIdentity();
13842 try {
13843 Context context = getDefaultPhone().getContext();
13844 if (mSubscriptionController.isActiveSubId(
13845 subId, context.getOpPackageName(), context.getAttributionTag())) {
13846 return subId;
13847 }
13848 } finally {
13849 Binder.restoreCallingIdentity(identity);
13850 }
13851 if (DBG) log("getValidSatelliteSubId: use DEFAULT_SUBSCRIPTION_ID for subId=" + subId);
13852 return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
13853 }
13854
13855 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013856 * If we have not successfully queried the satellite modem for its satellite service support,
13857 * we will retry the query one more time. Otherwise, we will return the queried result.
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013858 */
13859 private boolean isSatelliteSupported() {
13860 synchronized (mIsSatelliteSupportedLock) {
13861 if (mIsSatelliteSupported != null) {
13862 /* We have already successfully queried the satellite modem. */
13863 return mIsSatelliteSupported;
13864 }
13865 }
13866 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013867 * We have not successfully checked whether the modem supports satellite service.
13868 * Thus, we need to retry it now.
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013869 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013870 requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
13871 mSatelliteSupportedReceiver);
13872 return false;
13873 }
13874
13875 /**
13876 * Get the {@link SatelliteManager.SatelliteError} from the provided result.
Sarah Chindf715ec2023-02-13 13:46:24 -080013877 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013878 * @param ar AsyncResult used to determine the error code.
13879 * @param caller The satellite request.
13880 * @param checkResult Whether to check if the result exists.
Sarah Chindf715ec2023-02-13 13:46:24 -080013881 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013882 * @return The {@link SatelliteManager.SatelliteError} error code from the request.
13883 */
13884 @SatelliteManager.SatelliteError private int getSatelliteError(@NonNull AsyncResult ar,
13885 @NonNull String caller, boolean checkResult) {
13886 int errorCode;
13887 if (ar.exception == null) {
13888 errorCode = SatelliteManager.SATELLITE_ERROR_NONE;
13889 if (checkResult && ar.result == null) {
13890 loge(caller + ": result is null");
13891 errorCode = SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
13892 }
13893 } else {
13894 errorCode = SatelliteManager.SATELLITE_ERROR;
13895 if (ar.exception instanceof CommandException) {
Sarah Chin4beb2b72023-02-14 14:47:54 -080013896 CommandException.Error error = ((CommandException) ar.exception).getCommandError();
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013897 errorCode = RILUtils.convertToSatelliteError(error);
13898 loge(caller + " CommandException: " + ar.exception);
Sarah Chin4beb2b72023-02-14 14:47:54 -080013899 } else if (ar.exception instanceof SatelliteManager.SatelliteException) {
13900 errorCode = ((SatelliteManager.SatelliteException) ar.exception).getErrorCode();
13901 loge(caller + " SatelliteException: " + ar.exception);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013902 } else {
13903 loge(caller + " unknown exception: " + ar.exception);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013904 }
13905 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013906 log(caller + " error: " + errorCode);
13907 return errorCode;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013908 }
13909
13910 /**
Sarah Chin43457982023-02-15 17:50:38 -080013911 * Registers for the satellite provision state changed.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013912 *
13913 * @param subId The subId of the subscription associated with the satellite service.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013914 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013915 *
13916 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013917 */
Sarah Chindf715ec2023-02-13 13:46:24 -080013918 @SatelliteManager.SatelliteError private int registerForSatelliteProvisionStateChangedInternal(
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013919 int subId, @Nullable ISatelliteProvisionStateCallback callback) {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013920 if (!isSatelliteSupported()) {
Sarah Chindf715ec2023-02-13 13:46:24 -080013921 return SatelliteManager.SATELLITE_NOT_SUPPORTED;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013922 }
13923
13924 final int validSubId = getValidSatelliteSubId(subId);
13925 Phone phone = getPhoneOrDefault(validSubId, "registerForSatelliteProvisionStateChanged");
13926 if (phone == null) {
Sarah Chindf715ec2023-02-13 13:46:24 -080013927 return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013928 }
13929
13930 SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler =
13931 mSatelliteProvisionStateChangedHandlers.get(validSubId);
13932 if (satelliteProvisionStateChangedHandler == null) {
13933 satelliteProvisionStateChangedHandler = new SatelliteProvisionStateChangedHandler(
13934 Looper.getMainLooper(), validSubId);
Sarah Chin43457982023-02-15 17:50:38 -080013935 if (mIsSatelliteServiceSupported) {
13936 mSatelliteServiceController.registerForSatelliteProvisionStateChanged(
13937 satelliteProvisionStateChangedHandler,
13938 SatelliteProvisionStateChangedHandler.EVENT_PROVISION_STATE_CHANGED, null);
13939 } else {
13940 phone.registerForSatelliteProvisionStateChanged(
13941 satelliteProvisionStateChangedHandler,
13942 SatelliteProvisionStateChangedHandler.EVENT_PROVISION_STATE_CHANGED, null);
13943 }
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013944 }
13945
13946 if (callback != null) {
13947 satelliteProvisionStateChangedHandler.addListener(callback);
13948 }
13949 mSatelliteProvisionStateChangedHandlers.put(
13950 validSubId, satelliteProvisionStateChangedHandler);
Sarah Chindf715ec2023-02-13 13:46:24 -080013951 return SatelliteManager.SATELLITE_ERROR_NONE;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013952 }
13953
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013954 private void handleStartSatellitePositionUpdatesDone(@NonNull AsyncResult ar) {
13955 MainThreadRequest request = (MainThreadRequest) ar.userObj;
13956 SatellitePositionUpdateArgument arg = (SatellitePositionUpdateArgument) request.argument;
13957 int errorCode = getSatelliteError(
13958 ar, "handleStartSatellitePositionUpdatesDone", false);
13959 arg.errorCallback.accept(errorCode);
13960
13961 if (errorCode != SatelliteManager.SATELLITE_ERROR_NONE) {
13962 /**
13963 * We need to remove the callback from our listener list since the caller might not call
13964 * {@link #stopSatellitePositionUpdates(int, IIntegerConsumer, ISatellitePositionUpdateCallback)}
13965 * to unregister the callback in case of failure.
13966 */
13967 SatellitePositionUpdateHandler handler =
13968 mSatellitePositionUpdateHandlers.get(arg.subId);
13969 if (handler != null) {
13970 handler.removeListener(arg.callback);
13971
13972 if (!handler.hasListeners()) {
13973 mSatellitePositionUpdateHandlers.remove(arg.subId);
13974
Sarah Chin43457982023-02-15 17:50:38 -080013975 if (mIsSatelliteServiceSupported) {
13976 mSatelliteServiceController.unregisterForSatellitePositionInfoChanged(
13977 handler);
13978 mSatelliteServiceController.unregisterForDatagramTransferStateChanged(
13979 handler);
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013980 } else {
Sarah Chin43457982023-02-15 17:50:38 -080013981 Phone phone = getPhoneFromRequest(request);
13982 if (phone == null) {
13983 loge("handleStartSatellitePositionUpdatesDone: phone is null");
13984 } else {
13985 phone.unregisterForSatellitePositionInfoChanged(handler);
13986 // TODO: unregisterForDatagramTransferStateChanged through
13987 // SatelliteController
13988 }
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013989 }
13990 }
13991 }
13992 }
13993 }
13994
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013995 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000013996 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
13997 *
13998 * <p>This method behaves in one of the following ways:
13999 * <ul>
14000 * <li>return true : if the calling package has the appop permission {@link
14001 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14002 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14003 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14004 * Owner device identifier access check, or the calling package has carrier privileges</>
14005 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14006 * </ul>
14007 */
14008 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14009 String callingPackage, @Nullable String callingFeatureId, String message) {
14010 for (Phone phone : PhoneFactory.getPhones()) {
14011 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14012 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14013 return true;
14014 }
14015 }
14016 return false;
14017 }
arunvoddud7401012022-12-15 16:08:12 +000014018
14019 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014020 * @return The subscription manager service instance.
14021 */
14022 public SubscriptionManagerService getSubscriptionManagerService() {
14023 return SubscriptionManagerService.getInstance();
14024 }
14025
14026 /**
arunvoddud7401012022-12-15 16:08:12 +000014027 * Class binds the consumer[callback] and carrierId.
14028 */
14029 private static class CallerCallbackInfo {
14030 private final Consumer<Integer> mConsumer;
14031 private final int mCarrierId;
14032
14033 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
14034 mConsumer = consumer;
14035 mCarrierId = carrierId;
14036 }
14037
14038 public Consumer<Integer> getConsumer() {
14039 return mConsumer;
14040 }
14041
14042 public int getCarrierId() {
14043 return mCarrierId;
14044 }
14045 }
Jack Yufa8ed012023-02-11 15:42:28 -080014046}